Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jul 28, 2024
1 parent e0b6ec2 commit 6d9940a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@
},
"devDependencies": {
"@types/eslint": "^8.56.10",
"@typescript-eslint/eslint-plugin": "8.0.0-alpha.16",
"@typescript-eslint/parser": "8.0.0-alpha.16",
"@typescript-eslint-v7/eslint-plugin": "npm:@typescript-eslint/eslint-plugin@^7",
"@typescript-eslint-v7/parser": "npm:@typescript-eslint/parser@^7",
"@typescript-eslint-v6/eslint-plugin": "npm:@typescript-eslint/eslint-plugin@^6",
"@typescript-eslint-v6/parser": "npm:@typescript-eslint/parser@^6",
"@typescript-eslint-v5/eslint-plugin": "npm:@typescript-eslint/eslint-plugin@^5",
"@typescript-eslint-v5/parser": "npm:@typescript-eslint/parser@^5",
"@typescript-eslint-v6/eslint-plugin": "npm:@typescript-eslint/eslint-plugin@^6",
"@typescript-eslint-v6/parser": "npm:@typescript-eslint/parser@^6",
"@typescript-eslint-v7/eslint-plugin": "npm:@typescript-eslint/eslint-plugin@^7",
"@typescript-eslint-v7/parser": "npm:@typescript-eslint/parser@^7",
"@typescript-eslint/eslint-plugin": "8.0.0-alpha.16",
"@typescript-eslint/parser": "8.0.0-alpha.16",
"@typescript-eslint/utils": "^7.17.0",
"eslint": "^9.3.0",
"prettier": "^3.2.5",
"tsup": "^8.2.3",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions src/rules/predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { SourceCode, AST, Rule } from "eslint";
export type Predicate = (
problem: Rule.ReportDescriptor,
context: Rule.RuleContext,
) => Rule.ReportDescriptor;
) => Rule.ReportDescriptor | false;

const commaFilter = { filter: (token: AST.Token) => token.value === "," };
const includeCommentsFilter = { includeComments: true };

function makePredicate(
isImport: boolean,
addFixer?: (parent: any, sourceCode: SourceCode) => any,
addFixer?: (parent: any, sourceCode: SourceCode) => Partial<Rule.ReportDescriptor> | boolean,
): Predicate {
return (problem, context) => {
const sourceCode = context.sourceCode || context.getSourceCode();
Expand All @@ -20,8 +20,9 @@ function makePredicate(
// typescript-eslint >= 7.8 sets a range instead of a node
sourceCode.getNodeByRangeIndex(sourceCode.getIndexFromLoc((problem as any).loc.start));
return parent
? /^Import(|Default|Namespace)Specifier$/.test(parent.type) == isImport &&
Object.assign(problem, addFixer?.(parent, sourceCode))
? /^Import(|Default|Namespace)Specifier$/.test(parent.type) == isImport
? Object.assign(problem, addFixer?.(parent, sourceCode))
: false
: problem;
};
}
Expand Down Expand Up @@ -56,11 +57,11 @@ export const unusedImportsPredicate = makePredicate(true, (parent, sourceCode) =

// Not last specifier
if (parent !== grandParent.specifiers[grandParent.specifiers.length - 1]) {
const comma = sourceCode.getTokenAfter(parent, commaFilter);
const comma = sourceCode.getTokenAfter(parent, commaFilter)!;
const prevNode = sourceCode.getTokenBefore(parent)!;

return [
fixer.removeRange([prevNode.range[1], parent.range[0]]),
fixer.removeRange([prevNode.range[1], parent.range![0]]),
fixer.remove(parent),
fixer.remove(comma),
];
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "Bundler",
// "strict": true
"skipLibCheck": true,
"noEmit": true,
}
}

0 comments on commit 6d9940a

Please sign in to comment.