Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
fix(rule-tester): provide Linter a cwd in its constructor#9678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
25230bda3b6a920060a74bd4607d60075d209c739cFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -722,30 +722,6 @@ function a() {} | ||
| }, | ||
| { | ||
| code: ` | ||
| a(); | ||
| try { | ||
| throw new Error(); | ||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -167,7 +167,7 @@ function getUnsubstitutedMessagePlaceholders( | ||||
| export class RuleTester extends TestFramework { | ||||
| readonly #testerConfig: TesterConfigWithDefaults; | ||||
| readonly #rules: Record<string, AnyRuleCreateFunction | AnyRuleModule> = {}; | ||||
| readonly #linter: Linter; | ||||
| /** | ||||
| * Creates a new instance of RuleTester. | ||||
| @@ -183,6 +183,11 @@ export class RuleTester extends TestFramework { | ||||
| rules: { [`${RULE_TESTER_PLUGIN_PREFIX}validate-ast`]: 'error' }, | ||||
| }); | ||||
| this.#linter = new Linter({ | ||||
| configType: 'flat', | ||||
| cwd: this.#testerConfig.languageOptions.parserOptions?.tsconfigRootDir, | ||||
| }); | ||||
| // make sure that the parser doesn't hold onto file handles between tests | ||||
| // on linux (i.e. our CI env), there can be very a limited number of watch handles available | ||||
| const constructor = this.constructor as typeof RuleTester; | ||||
| @@ -282,14 +287,19 @@ export class RuleTester extends TestFramework { | ||||
| Hugely helps with the string-based valid test cases as it means they don't | ||||
| need to be made objects! | ||||
| */ | ||||
| const getFilename = ( | ||||
| originalFilename: string | undefined, | ||||
| testOptions: ParserOptions | undefined, | ||||
| ): string => { | ||||
| const resolvedOptions = deepMerge( | ||||
| this.#testerConfig.languageOptions.parserOptions, | ||||
| testOptions, | ||||
| ) as ParserOptions; | ||||
| const filename = | ||||
| originalFilename ?? | ||||
| (resolvedOptions.ecmaFeatures?.jsx | ||||
| ? this.#testerConfig.defaultFilenames.tsx | ||||
| : this.#testerConfig.defaultFilenames.ts); | ||||
| if (resolvedOptions.project) { | ||||
| return path.join( | ||||
| resolvedOptions.tsconfigRootDir ?? process.cwd(), | ||||
| @@ -309,22 +319,19 @@ export class RuleTester extends TestFramework { | ||||
| if (languageOptions.parser === parser) { | ||||
| throw new Error(DUPLICATE_PARSER_ERROR_MESSAGE); | ||||
| } | ||||
| return { | ||||
| ...test, | ||||
| filename: getFilename(test.filename, languageOptions.parserOptions), | ||||
| languageOptions: { | ||||
| ...languageOptions, | ||||
| parserOptions: { | ||||
| // Re-running simulates --fix mode, which implies an isolated program | ||||
| // (i.e. parseAndGenerateServicesCalls[test.filename] > 1). | ||||
| disallowAutomaticSingleRunInference: true, | ||||
| ...languageOptions.parserOptions, | ||||
| }, | ||||
| }, | ||||
| }; | ||||
| }; | ||||
| const normalizedTests = { | ||||
| @@ -707,16 +714,7 @@ export class RuleTester extends TestFramework { | ||||
| }, | ||||
| }, | ||||
| }); | ||||
| messages = this.#linter.verify(code, actualConfig, filename); | ||||
| } finally { | ||||
| SourceCode.prototype.applyInlineConfig = applyInlineConfig; | ||||
| SourceCode.prototype.applyLanguageOptions = applyLanguageOptions; | ||||
| @@ -917,6 +915,7 @@ export class RuleTester extends TestFramework { | ||||
| const hasMessageOfThisRule = messages.some(m => m.ruleId === ruleName); | ||||
| // console.log({ messages }); | ||||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Suggested change
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. oop will do this on the branch | ||||
| for (let i = 0, l = item.errors.length; i < l; i++) { | ||||
| const error = item.errors[i]; | ||||
| const message = messages[i]; | ||||