diff --git a/src/rules/no-redundant-files.ts b/src/rules/no-redundant-files.ts index 2e093cc3..52088685 100644 --- a/src/rules/no-redundant-files.ts +++ b/src/rules/no-redundant-files.ts @@ -7,14 +7,10 @@ import { isJSONStringLiteral, isNotNullish } from "../utils/predicates.js"; const defaultFiles = [ /* cspell:disable-next-line */ - "LICENCE", - /* cspell:disable-next-line */ - "LICENCE.md", - "LICENSE", - "LICENSE.md", - "package.json", - "README.md", -] as const; + /^(\.\/)?LICEN(C|S)E(\.|$)/i, + /^(\.\/)?README(\.|$)/i, + /^(\.\/)?package\.json$/i, +]; const cachedRegex = new Map(); const getCachedLocalFileRegex = (filename: string) => { @@ -143,11 +139,8 @@ export const rule = createRule({ // We can also go ahead and check if this matches one // of the static default files - const regex = getCachedLocalFileRegex( - element.value, - ); for (const defaultFile of defaultFiles) { - if (regex.test(defaultFile)) { + if (defaultFile.test(element.value)) { report( elements, index, diff --git a/src/tests/rules/no-redundant-files.test.ts b/src/tests/rules/no-redundant-files.test.ts index e9eeeea9..c9372c00 100644 --- a/src/tests/rules/no-redundant-files.test.ts +++ b/src/tests/rules/no-redundant-files.test.ts @@ -51,6 +51,51 @@ ruleTester.run("no-redundant-files", rule, { { code: `{ \t"files": [ +\t\t"README.a-b-c.md", +\t\t"./package.json" + ] +} +`, + errors: [ + { + data: { file: "README.a-b-c.md" }, + line: 3, + messageId: "unnecessaryDefault", + suggestions: [ + { + messageId: "remove", + output: `{ +\t"files": [ +\t\t +\t\t"./package.json" + ] +} +`, + }, + ], + }, + { + data: { file: "./package.json" }, + line: 4, + messageId: "unnecessaryDefault", + suggestions: [ + { + messageId: "remove", + output: `{ +\t"files": [ +\t\t"README.a-b-c.md" +\t\t + ] +} +`, + }, + ], + }, + ], + }, + { + code: `{ +\t"files": [ \t\t"CHANGELOG.md", \t\t"dist", \t\t"CHANGELOG.md"