Skip to content

Commit

Permalink
refactor(no-redundant-files): consolidate :exit validations
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfaith committed Jan 16, 2025
1 parent 018d6b1 commit 0a73e47
Showing 1 changed file with 37 additions and 49 deletions.
86 changes: 37 additions & 49 deletions src/rules/no-redundant-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,56 +187,44 @@ export const rule = createRule({
return;
}

// First check if the "main" entry is included in "files".
if (entryCache.main) {
for (const [index, fileEntry] of files.entries()) {
const regex = getCachedLocalFileRegex(fileEntry.value);
if (regex.test(entryCache.main)) {
context.report({
data: { file: fileEntry.value },
messageId: "unnecessaryMain",
node: fileEntry as unknown as ESTree.Node,
suggest: [
{
*fix(fixer) {
yield* removeEntryAndAppropriateCommas(
files,
index,
fixer,
context,
);
},
messageId: "remove",
},
],
});
}
}
}

// Next check if any "bin" entries are included in "files".
for (const binEntry of entryCache.bin) {
for (const [index, fileEntry] of files.entries()) {
const regex = getCachedLocalFileRegex(fileEntry.value);
if (regex.test(binEntry)) {
context.report({
data: { file: fileEntry.value },
messageId: "unnecessaryBin",
node: fileEntry as unknown as ESTree.Node,
suggest: [
{
*fix(fixer) {
yield* removeEntryAndAppropriateCommas(
files,
index,
fixer,
context,
);
const validations = [
// First check if the "main" entry is included in "files".
{
files: entryCache.main ? [entryCache.main] : [],
messageId: "unnecessaryMain",
},
// Next check if any "bin" entries are included in "files".
{
files: entryCache.bin,
messageId: "unnecessaryBin",
},
];
for (const validation of validations) {
for (const fileToCheck of validation.files) {
for (const [index, fileEntry] of files.entries()) {
const regex = getCachedLocalFileRegex(
fileEntry.value,
);
if (regex.test(fileToCheck)) {
context.report({
data: { file: fileEntry.value },
messageId: validation.messageId,
node: fileEntry as unknown as ESTree.Node,
suggest: [
{
*fix(fixer) {
yield* removeEntryAndAppropriateCommas(
files,
index,
fixer,
context,
);
},
messageId: "remove",
},
messageId: "remove",
},
],
});
],
});
}
}
}
}
Expand Down

0 comments on commit 0a73e47

Please sign in to comment.