-
-
Notifications
You must be signed in to change notification settings - Fork 117
fix: resolve imports from ESLint plugin #5790
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c912a77
fix: resolve imports from ESLint plugin
Jason3S 472e5bc
Update docValidator.ts
Jason3S f99c186
Update cspell-eslint-plugin.cts
Jason3S 01e0783
Add resolveImportsRelativeTo
Jason3S 5619e6d
Do not fetch remote dictionary for tests
Jason3S 9d50105
Adjust the resolve URL
Jason3S e118307
Add ability to configure import root
Jason3S d861670
Try to document cspellOptionsRoot
Jason3S 43ac94c
fix test
Jason3S File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -5,8 +5,4 @@ ignoreWords: | |
| - todos | ||
| - bluelist | ||
| words: | ||
| - estree | ||
| - pnpm | ||
| - synckit | ||
| - treeshake | ||
| - tsbuildinfo | ||
2 changes: 2 additions & 0 deletions
2
packages/cspell-eslint-plugin/fixtures/import-support/cspell.config.yaml
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| words: | ||
| - isentinel |
18 changes: 18 additions & 0 deletions
18
packages/cspell-eslint-plugin/fixtures/import-support/sample.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /** | ||
| * This is a sample file to test the import support. | ||
| * Related to issue: [#5789](https://github.com/streetsidesoftware/cspell/issues/5789) | ||
| */ | ||
|
|
||
| export function sample() { | ||
| return 'sample'; | ||
| } | ||
|
|
||
| export const words = [ | ||
| ` | ||
| readstring | ||
| resetmemorycategory | ||
| retargeting | ||
| rrotate | ||
| rshift | ||
| `, | ||
| ]; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| import * as fs from 'node:fs'; | ||
| import * as path from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| import typeScriptParser from '@typescript-eslint/parser'; | ||
| import { RuleTester } from 'eslint'; | ||
|
|
||
| import type { Options as RuleOptions } from '../plugin/index.cjs'; | ||
| import Rule from '../plugin/index.cjs'; | ||
|
|
||
| const __dirname = fileURLToPath(new URL('.', import.meta.url)); | ||
| const root = path.resolve(__dirname, '../..'); | ||
| const fixturesDir = path.join(root, 'fixtures'); | ||
|
|
||
| const parsers: Record<string, string | undefined | unknown> = { | ||
| // Note: it is possible for @typescript-eslint/parser to break the path | ||
| '.ts': typeScriptParser, | ||
| }; | ||
|
|
||
| type ValidTestCase = RuleTester.ValidTestCase; | ||
| type Options = Partial<RuleOptions>; | ||
|
|
||
| const ruleTester = new RuleTester({}); | ||
|
|
||
| ruleTester.run('cspell', Rule.rules.spellchecker, { | ||
| valid: [ | ||
| readFix('import-support/sample.ts', { | ||
| cspell: { | ||
| import: ['@internal/fixture-test-dictionary'], | ||
| }, | ||
| }), | ||
| readFix('import-support/sample.ts', { | ||
| configFile: '@internal/fixture-test-dictionary', | ||
| cspell: { | ||
| language: 'en-US', | ||
| }, | ||
| }), | ||
| ], | ||
| invalid: [ | ||
| // cspell:ignore readstring resetmemorycategory retargeting rrotate rshift | ||
| readInvalid('import-support/sample.ts', [ | ||
| unknownWord('readstring', 8), | ||
| unknownWord('resetmemorycategory'), | ||
| unknownWord('retargeting', 8), | ||
| unknownWord('rrotate', 8), | ||
| unknownWord('rshift', 8), | ||
| ]), | ||
| readInvalid( | ||
| 'import-support/sample.ts', | ||
| [ | ||
| ce( | ||
| 'Configuration Error: \n' + | ||
| ' Failed to resolve configuration file: "bad-import" referenced from ' + | ||
| `"./eslint-configuration-file"`, | ||
| ), | ||
| ], | ||
| { | ||
| cspellOptionsRoot: '', | ||
| cspell: { | ||
| import: ['@internal/fixture-test-dictionary', 'bad-import'], | ||
| }, | ||
| }, | ||
| ), | ||
| readInvalid( | ||
| 'import-support/sample.ts', | ||
| [ | ||
| ce( | ||
| 'Configuration Error: \n' + | ||
| ' Failed to resolve configuration file: "missing-import" referenced from ' + | ||
| `"./eslint-test-configuration-file"`, | ||
| ), | ||
| ], | ||
| { | ||
| cspellOptionsRoot: 'eslint-test-configuration-file', | ||
| cspell: { | ||
| import: ['@internal/fixture-test-dictionary', 'missing-import'], | ||
| }, | ||
| }, | ||
| ), | ||
| ], | ||
| }); | ||
|
|
||
| function resolveFix(filename: string): string { | ||
| return path.resolve(fixturesDir, filename); | ||
| } | ||
|
|
||
| interface ValidTestCaseEsLint9 extends ValidTestCase { | ||
| languageOptions?: { | ||
| parser?: unknown; | ||
| }; | ||
| } | ||
|
|
||
| function readFix(filename: string, options?: Options): ValidTestCase { | ||
| const __filename = resolveFix(filename); | ||
| const code = fs.readFileSync(__filename, 'utf8'); | ||
|
|
||
| const sample: ValidTestCaseEsLint9 = { | ||
| code, | ||
| filename: __filename, | ||
| }; | ||
| if (options) { | ||
| sample.options = [options]; | ||
| } | ||
|
|
||
| const parser = parsers[path.extname(__filename)]; | ||
| if (parser) { | ||
| sample.languageOptions ??= {}; | ||
| sample.languageOptions.parser = parser; | ||
| } | ||
|
|
||
| return sample; | ||
| } | ||
|
|
||
| interface TestCaseError { | ||
| message?: string | RegExp | undefined; | ||
| messageId?: string | undefined; | ||
| type?: string | undefined; | ||
| data?: unknown | undefined; | ||
| line?: number | undefined; | ||
| column?: number | undefined; | ||
| endLine?: number | undefined; | ||
| endColumn?: number | undefined; | ||
| suggestions?: RuleTester.SuggestionOutput[] | undefined | number; | ||
| } | ||
|
|
||
| type InvalidTestCaseError = RuleTester.TestCaseError | TestCaseError; | ||
|
|
||
| function readInvalid(filename: string, errors: TestCaseError[], options?: Options) { | ||
| const sample = readFix(filename, options); | ||
| return { | ||
| ...sample, | ||
| errors: errors.map((err) => csError(err)), | ||
| }; | ||
| } | ||
|
|
||
| function unknownWord(word: string, suggestions?: number): InvalidTestCaseError { | ||
| return ce(`Unknown word: "${word}"`, suggestions); | ||
| } | ||
|
|
||
| function ce(message: string, suggestions?: number): RuleTester.TestCaseError { | ||
| return { message, suggestions } as RuleTester.TestCaseError; | ||
| } | ||
|
|
||
| function csError(error: InvalidTestCaseError, suggestions?: number): RuleTester.TestCaseError { | ||
| if (error && typeof error === 'object') return error as RuleTester.TestCaseError; | ||
| return ce(error, suggestions); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.