Skip to content

Commit

Permalink
fix(no-redundant-files): detect variations of README.md as redundant
Browse files Browse the repository at this point in the history
This change detects additional variations of README and LICENSE files.  Apparently npm will include any README followed by any extension (e.g. README.fi.md)
  • Loading branch information
michaelfaith committed Jan 23, 2025
1 parent 6bc31c3 commit 90aa922
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/rules/no-redundant-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, RegExp>();
const getCachedLocalFileRegex = (filename: string) => {
Expand Down Expand Up @@ -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,
Expand Down
45 changes: 45 additions & 0 deletions src/tests/rules/no-redundant-files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 90aa922

Please sign in to comment.