Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Draft
kirkwaiblinger wants to merge12 commits intotypescript-eslint:main
base:main
Choose a base branch
Loading
fromkirkwaiblinger:fix-type-incompatibility
Draft
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletionspackages/eslint-plugin/package.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,6 +61,7 @@
},
"dependencies": {
"@eslint-community/regexpp": "^4.10.0",
"@eslint/config-helpers": "^0.2",
"@typescript-eslint/scope-manager": "8.32.1",
"@typescript-eslint/type-utils": "8.32.1",
"@typescript-eslint/utils": "8.32.1",
Expand Down
27 changes: 14 additions & 13 deletionspackages/eslint-plugin/raw-plugin.d.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
import type * as eslintConfigHelpers from '@eslint/config-helpers';
import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint';

import type plugin from './index';

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':eslintConfigHelpers.Config[];
'flat/base':eslintConfigHelpers.Config;
'flat/disable-type-checked':eslintConfigHelpers.Config;
'flat/eslint-recommended':eslintConfigHelpers.Config;
'flat/recommended':eslintConfigHelpers.Config[];
'flat/recommended-type-checked':eslintConfigHelpers.Config[];
'flat/recommended-type-checked-only':eslintConfigHelpers.Config[];
'flat/strict':eslintConfigHelpers.Config[];
'flat/strict-type-checked':eslintConfigHelpers.Config[];
'flat/strict-type-checked-only':eslintConfigHelpers.Config[];
'flat/stylistic':eslintConfigHelpers.Config[];
'flat/stylistic-type-checked':eslintConfigHelpers.Config[];
'flat/stylistic-type-checked-only':eslintConfigHelpers.Config[];
};
parser: FlatConfig.Parser;
plugin: typeof plugin;
Expand Down
1 change: 1 addition & 0 deletionspackages/typescript-eslint/package.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,6 +50,7 @@
"check-types": "npx nx typecheck"
},
"dependencies": {
"@eslint/config-helpers": "^0.2",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

ugh an0.x version sucks cos it means that every minor release we'll be forced to update our version or else users will be blocked.

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"
Expand Down
3 changes: 2 additions & 1 deletionpackages/typescript-eslint/project.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,7 +10,8 @@
"outputs": ["{options.outputFile}"]
},
"test": {
"executor": "@nx/vite:test"
"executor": "@nx/vite:test",
"dependsOn": ["^build", "typecheck"]
}
}
}
28 changes: 22 additions & 6 deletionspackages/typescript-eslint/src/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff 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';

Expand All@@ -6,7 +7,15 @@ import rawPlugin from '@typescript-eslint/eslint-plugin/use-at-your-own-risk/raw

import { config } from './config-helper';

export const parser: TSESLint.FlatConfig.Parser = rawPlugin.parser;
// 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
Expand All@@ -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: TSESLint.FlatConfig.Plugin = pluginBase as Omit<
typeof pluginBase,
'configs'
>;
export const plugin = pluginBase as unknown as eslintConfigHelpers.Plugin;

export const configs = {
/**
Expand DownExpand Up@@ -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;
Copy link
Member

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?

Copy link
MemberAuthor

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 aT | Promise<T> version of the type of the parameter type oftseslint.config(...configs).

I think deprecating makes sense 👍


/*
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff 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,
},
});
});
});
5 changes: 5 additions & 0 deletionspackages/typescript-eslint/vitest.config.mts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,6 +14,11 @@ const vitestConfig = mergeConfig(
dir: path.join(import.meta.dirname, 'tests'),
name: packageJson.name,
root: import.meta.dirname,

typecheck: {
enabled: true,
tsconfig: path.join(import.meta.dirname, 'tsconfig.spec.json'),
},
},
}),
);
Expand Down
4 changes: 3 additions & 1 deletionyarn.lock
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3448,7 +3448,7 @@ __metadata:
languageName: node
linkType: hard

"@eslint/config-helpers@npm:^0.2.1":
"@eslint/config-helpers@npm:^0.2, @eslint/config-helpers@npm:^0.2.1":
version: 0.2.2
resolution: "@eslint/config-helpers@npm:0.2.2"
checksum: 8a4091a2c8af5366513647ccad720f184c1b723f04c086755797a3a5cac69dc9013bc8a75453d9fc188fc4364460f0eae9f1584b77b28082e0d26bf48356ae8f
Expand DownExpand Up@@ -5528,6 +5528,7 @@ __metadata:
resolution: "@typescript-eslint/eslint-plugin@workspace:packages/eslint-plugin"
dependencies:
"@eslint-community/regexpp": ^4.10.0
"@eslint/config-helpers": ^0.2
"@types/mdast": ^4.0.3
"@types/natural-compare": "*"
"@typescript-eslint/rule-schema-to-typescript-types": 8.32.1
Expand DownExpand Up@@ -18952,6 +18953,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "typescript-eslint@workspace:packages/typescript-eslint"
dependencies:
"@eslint/config-helpers": ^0.2
"@typescript-eslint/eslint-plugin": 8.32.1
"@typescript-eslint/parser": 8.32.1
"@typescript-eslint/utils": 8.32.1
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp