-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(typescript-eslint): make exported configs/plugin compatible with defineConfig()
#11190
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
Draft
kirkwaiblinger
wants to merge
17
commits into
typescript-eslint:main
Choose a base branch
from
kirkwaiblinger:fix-type-incompatibility
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+114
−35
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8e15765
poc
kirkwaiblinger a0775f0
more
kirkwaiblinger 1bcab8a
lintfix
kirkwaiblinger 54341e0
revert unrelated change
kirkwaiblinger 29e647d
dep
kirkwaiblinger ff95b9a
some feedback
kirkwaiblinger 526480d
add type tests for `defineConfig`
aryaemami59 31ba0c9
Merge pull request #2 from aryaemami59/pr/kirkwaiblinger/11190
kirkwaiblinger 46e2e7e
tweaks
kirkwaiblinger c946e20
Merge branch 'main' into fix-type-incompatibility
kirkwaiblinger 9bb9f95
undeclared dep
kirkwaiblinger 6730308
lintfix
kirkwaiblinger 917613d
remove dependency on eslint types
kirkwaiblinger 82aee06
simplify
kirkwaiblinger 493bdde
fix the plugin type
kirkwaiblinger 08d57ba
whoops
kirkwaiblinger 893c959
plugin
kirkwaiblinger 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 |
---|---|---|
@@ -1,25 +1,54 @@ | ||
import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'; | ||
import type * as parserBase from '@typescript-eslint/parser'; | ||
import type { Linter } from '@typescript-eslint/utils/ts-eslint'; | ||
|
||
import type plugin from './index'; | ||
export interface TSESLintParser { | ||
meta: typeof parserBase.meta; | ||
parseForESLint: typeof parserBase.parseForESLint; | ||
} | ||
|
||
export interface TSESLintConfig { | ||
name?: string; | ||
rules?: Record<string, ['error' | 'off', ...unknown[]]>; | ||
files?: string[]; | ||
languageOptions?: { | ||
sourceType?: 'module'; | ||
parser?: TSESLintParser; | ||
parserOptions?: Record<string, unknown>; | ||
}; | ||
|
||
// causes type errors :shrug: | ||
// plugins?: { | ||
// '@typescript-eslint': TSESLintPlugin; | ||
// }; | ||
} | ||
|
||
export interface TSESLintPlugin { | ||
configs: Record<string, TSESLintConfig | TSESLintConfig[]>; | ||
meta: { | ||
name: string; | ||
version: string; | ||
}; | ||
rules: Linter.PluginRules; | ||
} | ||
|
||
declare const cjsExport: { | ||
flatConfigs: { | ||
'flat/all': FlatConfig.ConfigArray; | ||
'flat/base': FlatConfig.Config; | ||
'flat/disable-type-checked': FlatConfig.Config; | ||
'flat/eslint-recommended': FlatConfig.Config; | ||
'flat/recommended': FlatConfig.ConfigArray; | ||
'flat/recommended-type-checked': FlatConfig.ConfigArray; | ||
'flat/recommended-type-checked-only': FlatConfig.ConfigArray; | ||
'flat/strict': FlatConfig.ConfigArray; | ||
'flat/strict-type-checked': FlatConfig.ConfigArray; | ||
'flat/strict-type-checked-only': FlatConfig.ConfigArray; | ||
'flat/stylistic': FlatConfig.ConfigArray; | ||
'flat/stylistic-type-checked': FlatConfig.ConfigArray; | ||
'flat/stylistic-type-checked-only': FlatConfig.ConfigArray; | ||
'flat/all': TSESLintConfig[]; | ||
'flat/base': TSESLintConfig; | ||
'flat/disable-type-checked': TSESLintConfig; | ||
'flat/eslint-recommended': TSESLintConfig; | ||
'flat/recommended': TSESLintConfig[]; | ||
'flat/recommended-type-checked': TSESLintConfig[]; | ||
'flat/recommended-type-checked-only': TSESLintConfig[]; | ||
'flat/strict': TSESLintConfig[]; | ||
'flat/strict-type-checked': TSESLintConfig[]; | ||
'flat/strict-type-checked-only': TSESLintConfig[]; | ||
'flat/stylistic': TSESLintConfig[]; | ||
'flat/stylistic-type-checked': TSESLintConfig[]; | ||
'flat/stylistic-type-checked-only': TSESLintConfig[]; | ||
}; | ||
parser: FlatConfig.Parser; | ||
plugin: typeof plugin; | ||
parser: TSESLintParser; | ||
plugin: TSESLintPlugin; | ||
}; | ||
|
||
export = cjsExport; |
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
28 changes: 28 additions & 0 deletions
28
packages/typescript-eslint/tests/defineConfig-interop.test-d.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,28 @@ | ||
import { defineConfig } from 'eslint/config'; | ||
|
||
import * as tseslint from '../src/index.js'; | ||
|
||
// Type tests to ensure that migration from `tseslint.config()` -> `defineConfig()` | ||
// doesn't introduce type errors for the user. We don't care about the | ||
// `defineConfig()` -> `tseslint.config()` direction. | ||
describe('tseslint.config() should be replaceable with defineConfig()', () => { | ||
it('should work with recommended setup', () => { | ||
expectTypeOf(defineConfig).toBeCallableWith(tseslint.configs.recommended); | ||
}); | ||
|
||
it('should allow manual assignment of the plugin', () => { | ||
expectTypeOf(defineConfig).toBeCallableWith({ | ||
plugins: { | ||
ts: tseslint.plugin, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should allow manual assignment of the parser', () => { | ||
expectTypeOf(defineConfig).toBeCallableWith({ | ||
languageOptions: { | ||
parser: tseslint.parser, | ||
}, | ||
}); | ||
}); | ||
}); |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't remember -- is this the loose type or the strict type?
Perhaps we should deprecate this to rename it? Or change the type to the ESLint types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a loose one; it's just a
T | Promise<T>
version of the type of the parameter type oftseslint.config(...configs)
.I think deprecating makes sense 👍