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(typescript-eslint): make exported configs/plugin compatible withdefineConfig()
#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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Changes fromall commits
8e15765
a0775f0
1bcab8a
54341e0
29e647d
ff95b9a
526480d
31ba0c9
46e2e7e
c946e20
9bb9f95
6730308
File 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 |
---|---|---|
@@ -50,6 +50,7 @@ | ||
"check-types": "npx nx typecheck" | ||
}, | ||
"dependencies": { | ||
"@eslint/config-helpers": "^0.2", | ||
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. ugh an ESLint itself depends on this package so in some future when we drop v8 and older v9 versions -- we would be able to make this a peer dependency and just rely on the version installed that way. | ||
"@typescript-eslint/eslint-plugin": "8.32.1", | ||
"@typescript-eslint/parser": "8.32.1", | ||
"@typescript-eslint/utils": "8.32.1" | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import type * as eslintConfigHelpers from '@eslint/config-helpers'; | ||
// see the comment in config-helper.ts for why this doesn't use /ts-eslint | ||
import type { TSESLint } from '@typescript-eslint/utils'; | ||
@@ -6,7 +7,15 @@ import rawPlugin from '@typescript-eslint/eslint-plugin/use-at-your-own-risk/raw | ||
import { config } from './config-helper'; | ||
// Couldn't find a way to directly get to the eslint Linter.Parser type... | ||
// We don't want to get it directly from eslint, since the supported eslint versions include eslint 8.x as well. | ||
// '@eslint/config-helpers' doesn't re-export the Linter namespace, just some of its contents. | ||
// So this is a bit yucky but it should get the type we want. | ||
type ESLintParserType = NonNullable< | ||
NonNullable<eslintConfigHelpers.Config['languageOptions']>['parser'] | ||
>; | ||
export const parser = rawPlugin.parser as ESLintParserType; | ||
/* | ||
we could build a plugin object here without the `configs` key - but if we do | ||
@@ -31,10 +40,7 @@ use our new package); however legacy configs consumed via `@eslint/eslintrc` | ||
would never be able to satisfy this constraint and thus users would be blocked | ||
from using them. | ||
*/ | ||
export const plugin = pluginBase as unknown as eslintConfigHelpers.Plugin; | ||
export const configs = { | ||
/** | ||
@@ -120,8 +126,18 @@ export const configs = { | ||
*/ | ||
stylisticTypeCheckedOnly: | ||
rawPlugin.flatConfigs['flat/stylistic-type-checked-only'], | ||
} satisfies Record< | ||
string, | ||
eslintConfigHelpers.Config | eslintConfigHelpers.Config[] | ||
>; | ||
/** | ||
* The expected shape of the default export of an eslint flat config file. | ||
* | ||
* @deprecated ESLint core provides their own config types, and we now recommend using them instead. | ||
* @see {@link https://github.com/typescript-eslint/typescript-eslint/issues/10899} | ||
* @see {@link https://github.com/eslint/eslint/pull/19487} | ||
*/ | ||
export type Config = TSESLint.FlatConfig.ConfigFile; | ||
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. I can't remember -- is this the loose type or the strict type? 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. This is a loose one; it's just a I think deprecating makes sense 👍 | ||
/* | ||
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, | ||
}, | ||
}); | ||
}); | ||
}); |
Uh oh!
There was an error while loading.Please reload this page.