MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / scanFile

Function scanFile

scripts/lint-test-dynamic-imports.cjs:46–76  ·  view source on GitHub ↗
(filePath)

Source from the content-addressed store, hash-verified

44}
45
46function scanFile(filePath) {
47 const source = fs.readFileSync(filePath, 'utf8');
48 const violations = [];
49 const lines = source.split('\n');
50
51 // File-level opt-out: a header comment that disables the lint for the whole
52 // file. Useful when an entire file legitimately needs the patterns (e.g.
53 // testing env-var-loaded module init).
54 if (/lint-allow-test-imports-file/.test(source)) return [];
55
56 lines.forEach((line, idx) => {
57 if (PROJECT_IMPORT.test(line) && !ALLOW_DYNAMIC.test(line)) {
58 violations.push({
59 file: filePath,
60 line: idx + 1,
61 rule: 'no-dynamic-project-import',
62 snippet: line.trim(),
63 });
64 }
65 if (RESET_MODULES.test(line) && !ALLOW_RESET.test(line)) {
66 violations.push({
67 file: filePath,
68 line: idx + 1,
69 rule: 'no-reset-modules',
70 snippet: line.trim(),
71 });
72 }
73 });
74
75 return violations;
76}
77
78function lint() {
79 if (!fs.existsSync(TESTS_DIR)) return [];

Callers 2

lintFunction · 0.85

Calls 1

trimMethod · 0.65

Tested by

no test coverage detected