Files
msd-core/scripts/lint-pr-check-project-dir.cjs
Jakub Zych bb581803ad
Some checks failed
Tests / lint-tests (push) Has been cancelled
Tests / plugin-validate (push) Has been cancelled
Tests / test (ubuntu-latest, 24, shard 1/3) (push) Has been cancelled
Tests / test (ubuntu-latest, 24, shard 2/3) (push) Has been cancelled
Tests / test (ubuntu-latest, 24, shard 3/3) (push) Has been cancelled
Tests / test (ubuntu-latest, 24) (push) Has been cancelled
Tests / test (inert CI) (push) Has been cancelled
Tests / conformance test (macos-latest, 24) (push) Has been cancelled
Tests / conformance test (windows-latest, 24, shard 1/3) (push) Has been cancelled
Tests / conformance test (windows-latest, 24, shard 2/3) (push) Has been cancelled
Tests / conformance test (windows-latest, 24, shard 3/3) (push) Has been cancelled
Tests / Coverage gate (merged shards) (push) Has been cancelled
Tests / QA loop walk (smell ratchet) (push) Has been cancelled
Tests / Required tests (push) Has been cancelled
Tests / Publish emitted-baseline artifact (push) Has been cancelled
Tests / PR mergeability (push) Has been cancelled
Tests / Base branch health (push) Has been cancelled
Tests / Detect test scope (push) Has been cancelled
chore: drop upstream gsd issue and pr governance
MSD does not use an issue tracker, and the inherited GSD community gates
auto-closed PR #1 for lacking an issue-numbered title. Remove them:

- workflows: require-issue-link, pr-title-validator,
  auto-close-unsolicited-prs, pr-template-format, close-draft-prs(-sweep),
  auto-label-issues, auto-branch, duplicate-check, duplicate-sweep,
  remove-duplicate-label
- GSD PR and issue templates, plus the scripts only they used
  (require-issue-link-policy, pr-template-policy, pr-changed-files) and
  their tests
- workflow lists in ci-test-scope, ci-pr-mergeability,
  workflow-maintainer-skip, lint-pr-check-project-dir, the docs-guard
  baseline and the conformance tiers
- CONTRIBUTING: PR-against-next flow with no issue or template; PR titles
  are conventional without an issue ref; ADR/PRD files use the PR number
- CONTEXT.md: drop the PR-template predicates (k328, templates-mandatory)
2026-10-09 10:53:54 +02:00

98 lines
2.3 KiB
JavaScript

#!/usr/bin/env node
'use strict';
const fs = require('fs');
const path = require('path');
const { runMain } = require('./lib/cli-exit.cjs');
const ROOT = path.join(__dirname, '..');
const DEFAULT_RELATIVE_FILES = [
'.github/workflows/test.yml',
'.github/workflows/changeset-required.yml',
'scripts/lint-command-contract.cjs',
'scripts/lint-skill-deps.cjs',
'scripts/lint-descriptions.cjs',
'scripts/lint-shell-command-projection-drift.cjs',
'scripts/changeset/lint.cjs',
];
function defaultFiles(rootDir = ROOT) {
return DEFAULT_RELATIVE_FILES
.map((file) => path.join(rootDir, file))
.filter((file) => fs.existsSync(file));
}
function findForbiddenCwd(content, file = '<inline>') {
const findings = [];
const lines = content.split(/\r?\n/);
lines.forEach((line, index) => {
const pattern = /\bcwd\b/g;
let match;
while ((match = pattern.exec(line)) !== null) {
findings.push({
file,
line: index + 1,
column: match.index + 1,
source: line.trim(),
});
}
});
return findings;
}
function checkFiles(files, { rootDir = ROOT } = {}) {
const findings = [];
for (const file of files) {
const content = fs.readFileSync(file, 'utf8');
const rel = path.relative(rootDir, file);
findings.push(...findForbiddenCwd(content, rel));
}
return findings;
}
function formatFindings(findings) {
const lines = [
`ERROR lint-pr-check-project-dir: ${findings.length} forbidden cwd reference(s) found`,
'',
'PR checkers must use projectDir for project roots; cwd is forbidden in this layer.',
'',
];
for (const finding of findings) {
lines.push(` ${finding.file}:${finding.line}:${finding.column}`);
lines.push(` ${finding.source}`);
}
return `${lines.join('\n')}\n`;
}
function main(argv = process.argv.slice(2)) {
const files = argv.length > 0 ? argv.map((file) => path.resolve(file)) : defaultFiles();
const findings = checkFiles(files);
if (findings.length === 0) {
console.log(`ok lint-pr-check-project-dir: ${files.length} PR check files checked`);
return 0;
}
process.stderr.write(formatFindings(findings));
return 1;
}
if (require.main === module) {
runMain(main);
}
module.exports = {
DEFAULT_RELATIVE_FILES,
checkFiles,
defaultFiles,
findForbiddenCwd,
formatFindings,
main,
};