8000 feat: prune suppressions for non-existent files (#19825) · eslint/eslint@19cdd22 · GitHub
[go: up one dir, main page]

Skip to content

Commit 19cdd22

Browse files
authored
feat: prune suppressions for non-existent files (#19825)
1 parent b3d720f commit 19cdd22

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lib/services/suppressions-service.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ class SuppressionsService {
112112
}
113113
}
114114

115+
for (const file of Object.keys(suppressions)) {
116+
const absolutePath = path.resolve(this.cwd, file);
117+
118+
if (!fs.existsSync(absolutePath)) {
119+
delete suppressions[file];
120+
}
121+
}
122+
115123
return this.save(suppressions);
116124
}
117125

tests/bin/eslint.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,33 @@ describe("bin/eslint.js", () => {
11781178
);
11791179
});
11801180
});
1181+
1182+
it("prunes suppressions for files that don't exist", () => {
1183+
const suppressions = structuredClone(
1184+
SUPPRESSIONS_FILE_ALL_ERRORS,
1185+
);
1186+
const nonExistentFile =
1187+
"tests/fixtures/suppressions/non-existent-file.js";
1188+
1189+
suppressions[nonExistentFile] = {
1190+
"no-undef": { count: 1 },
1191+
};
1192+
1193+
fs.writeFileSync(
1194+
SUPPRESSIONS_PATH,
1195+
JSON.stringify(suppressions, null, 2),
1196+
);
1197+
1198+
const child = runESLint(ARGS_WITH_PRUNE_SUPPRESSIONS);
1199+
1200+
return assertExitCode(child, 0).then(() => {
1201+
assert.deepStrictEqual(
1202+
JSON.parse(fs.readFileSync(SUPPRESSIONS_PATH, "utf8")),
1203+
SUPPRESSIONS_FILE_ALL_ERRORS,
1204+
"Suppressions for existing files should remain unchanged",
1205+
);
1206+
});
1207+
});
11811208
});
11821209
});
11831210

0 commit comments

Comments
 (0)
0