The #452 ESLint migration replaced the homegrown source-grep regex linters with the local/no-source-grep AST rule (eslint-rules/no-source-grep.cjs, wired in eslint.config.mjs) but left the old scripts on disk, wired to nothing. Removed: - scripts/lint-no-source-grep.cjs — CLI linter; no module.exports, never required, not referenced by package.json / CI / eslint. Superseded by the rule. - scripts/lint-no-source-grep-extras.cjs — var-binding + wrapped-assert-ok regex detectors; the ESLint rule covers both forms via AST (VariableDeclarator/AssignmentExpression tracking + member-call checks). - tests/bug-2982-lint-var-binding.test.cjs — exercised only the deleted extras module; the #2982 var-binding scenario is already covered against the live rule by tests/eslint-rules.test.cjs. Also dropped the now-dangling 'scripts/lint-no-source-grep.cjs' entry from DEFAULT_RELATIVE_FILES in scripts/lint-pr-check-project-dir.cjs (the list is existsSync-filtered, so this is tidy-up, not a behavior change). No functional change: source-grep enforcement remains intact via the ESLint rule, and the full unit suite stays green. Three surviving comment-only mentions of "lint-no-source-grep" refer to the rule concept (which lives on in ESLint), not the deleted files. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Tom Boucher <trekkie@nomorestars.com>
98 lines
2.3 KiB
JavaScript
98 lines
2.3 KiB
JavaScript
#!/usr/bin/env node
|
|
'use strict';
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
|
|
const DEFAULT_RELATIVE_FILES = [
|
|
'.github/workflows/test.yml',
|
|
'.github/workflows/pr-template-format.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/pr-template-policy.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) {
|
|
process.exit(main());
|
|
}
|
|
|
|
module.exports = {
|
|
DEFAULT_RELATIVE_FILES,
|
|
checkFiles,
|
|
defaultFiles,
|
|
findForbiddenCwd,
|
|
formatFindings,
|
|
main,
|
|
};
|