From 16e5ec12a2be7d457fe87fa5b683b7b15b369851 Mon Sep 17 00:00:00 2001 From: Tom White Date: Sun, 8 Dec 2024 20:09:29 +0000 Subject: [PATCH] refactor: no need to process executeRuleWithContext when excluded --- packages/eslint-plugin/src/lib/rules/create-rule.ts | 10 +++++----- .../src/lib/rules/tests/create-rule.spec.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/eslint-plugin/src/lib/rules/create-rule.ts b/packages/eslint-plugin/src/lib/rules/create-rule.ts index 019b35c..6e9d4d5 100644 --- a/packages/eslint-plugin/src/lib/rules/create-rule.ts +++ b/packages/eslint-plugin/src/lib/rules/create-rule.ts @@ -21,17 +21,17 @@ export const createRule: ( executor: Executor, ) => Rule.RuleModule = (ruleName, fileFilter, executor) => ({ create: (context) => { + const filename = context.filename ?? context.getFilename(); + if (isExcluded(fileFilter, filename)) { + return {}; + } + let isFirstRun = true; let hasInternalError = false; const executeRuleWithContext = (node: ExecutorNode) => { - const filename = context.filename ?? context.getFilename(); const sourceCode = context.sourceCode?.text ?? context.getSourceCode().text; - if (isExcluded(fileFilter, filename)) { - return; - } - if (!hasInternalError) { try { // don't process special export `export const value = {n: 1};` diff --git a/packages/eslint-plugin/src/lib/rules/tests/create-rule.spec.ts b/packages/eslint-plugin/src/lib/rules/tests/create-rule.spec.ts index fe74646..377ec4a 100644 --- a/packages/eslint-plugin/src/lib/rules/tests/create-rule.spec.ts +++ b/packages/eslint-plugin/src/lib/rules/tests/create-rule.spec.ts @@ -35,7 +35,7 @@ describe('create rule', () => { expect(spy).toHaveBeenCalledTimes(2); }); - it.only('should NOT call the rule executor for any import or export types when filename is "sheriff.config.ts"', () => { + it('should NOT call the rule executor for any import or export types when filename is "sheriff.config.ts"', () => { tester.run('test-rule', testRule, { valid: [ {