-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new setting for reported filename pattern (#244)
* feat: new setting for customizing file name pattern to report * test: add custom rule tester for testing library * refactor: use common rule tester config
- Loading branch information
Showing
13 changed files
with
99 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,49 @@ | ||
import { resolve } from 'path'; | ||
import { TSESLint } from '@typescript-eslint/experimental-utils'; | ||
|
||
const DEFAULT_TEST_CASE_CONFIG = { | ||
filename: 'MyComponent.test.js', | ||
}; | ||
|
||
class TestingLibraryRuleTester extends TSESLint.RuleTester { | ||
run<TMessageIds extends string, TOptions extends Readonly<unknown[]>>( | ||
ruleName: string, | ||
rule: TSESLint.RuleModule<TMessageIds, TOptions>, | ||
tests: TSESLint.RunTests<TMessageIds, TOptions> | ||
): void { | ||
const { valid, invalid } = tests; | ||
|
||
const finalValid = valid.map((testCase) => { | ||
if (typeof testCase === 'string') { | ||
return { | ||
...DEFAULT_TEST_CASE_CONFIG, | ||
code: testCase, | ||
}; | ||
} | ||
|
||
return { ...DEFAULT_TEST_CASE_CONFIG, ...testCase }; | ||
}); | ||
const finalInvalid = invalid.map((testCase) => ({ | ||
...DEFAULT_TEST_CASE_CONFIG, | ||
...testCase, | ||
})); | ||
|
||
super.run(ruleName, rule, { valid: finalValid, invalid: finalInvalid }); | ||
} | ||
} | ||
|
||
export const createRuleTester = ( | ||
parserOptions: Partial<TSESLint.ParserOptions> = {} | ||
): TSESLint.RuleTester => | ||
new TSESLint.RuleTester({ | ||
): TSESLint.RuleTester => { | ||
return new TestingLibraryRuleTester({ | ||
parser: resolve('./node_modules/@typescript-eslint/parser'), | ||
parserOptions: { | ||
ecmaVersion: 2018, | ||
sourceType: 'module', | ||
ecmaFeatures: { | ||
jsx: true, | ||
}, | ||
...parserOptions, | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters