Skip to content

Commit

Permalink
migrate import rules to eslint v9 (#243)
Browse files Browse the repository at this point in the history
Signed-off-by: Kangrui Johann Ye <[email protected]>
strawberry-choco authored Oct 15, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 896fc97 commit 9a9b9a8
Showing 17 changed files with 244 additions and 116 deletions.
6 changes: 5 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -20,7 +20,6 @@ export default tseslint.config(
'packages/eslint-plugin-typescript/src/configs/json.ts',
'packages/eslint-plugin-typescript/src/configs/package.ts',
'packages/eslint-plugin-typescript/src/configs/format.ts',
'packages/eslint-plugin-typescript/src/configs/import.ts',
'packages/eslint-plugin-typescript/src/configs/rxjs.ts',
'packages/eslint-plugin-typescript/src/rules/package/*',
'packages/eslint-plugin-typescript/src/rules/ts-config/*',
@@ -40,4 +39,9 @@ export default tseslint.config(
},
},
},
{
rules: {
'import-x/no-named-as-default-member': 'off',
},
},
);
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflight/eslint-plugin",
"version": "1.0.0-rc5",
"version": "1.0.0-rc6",
"private": true,
"volta": {
"node": "20.12.2",
@@ -41,7 +41,8 @@
"@vue/eslint-config-typescript": "14.0.0",
"angular-eslint": "18.3.1",
"eslint": "9.11.1",
"eslint-plugin-import": "2.29.1",
"eslint-import-resolver-typescript": "3.6.3",
"eslint-plugin-import-x": "4.3.1",
"eslint-plugin-json-es": "1.6.0",
"eslint-plugin-jsx-a11y": "6.8.0",
"eslint-plugin-n": "17.10.3",
10 changes: 9 additions & 1 deletion packages/eslint-plugin-angular/README.md
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ The plugin provides 3 different configurations:
- cloudflightAngularTypescriptConfig
- Only contains rules for TS files

Now open your `eslint.config.mts` and add one of the configurations:
Now open your `eslint.config.mjs` and add one of the configurations:

```ts
import { cloudflightAngularConfig } from '@cloudflight/eslint-plugin-angular';
@@ -54,6 +54,14 @@ export default [
tsconfigRootDir: import.meta.dirname,
},
},
settings: {
'import-x/resolver': {
typescript: {
alwaysTryTypes: true,
project: ['tsconfig*(.*).json'],
},
},
},
},
];
```
2 changes: 1 addition & 1 deletion packages/eslint-plugin-angular/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflight/eslint-plugin-angular",
"version": "1.0.0-rc5",
"version": "1.0.0-rc6",
"description": "Cloudflight eslint-plugin & eslint-config for angular",
"volta": {
"extends": "../../package.json"
10 changes: 9 additions & 1 deletion packages/eslint-plugin-node/README.md
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ In your `package.json` add the following:
}
```

Now open your `eslint.config.mts` and add one of the configurations:
Now open your `eslint.config.mjs` and add one of the configurations:

```ts
import { cloudflightNodeConfig } from '@cloudflight/eslint-plugin-node';
@@ -45,6 +45,14 @@ export default [
tsconfigRootDir: import.meta.dirname,
},
},
settings: {
'import-x/resolver': {
typescript: {
alwaysTryTypes: true,
project: ['tsconfig*(.*).json'],
},
},
},
},
];
```
2 changes: 1 addition & 1 deletion packages/eslint-plugin-node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflight/eslint-plugin-node",
"version": "1.0.0-rc5",
"version": "1.0.0-rc6",
"description": "Cloudflight eslint-plugin & eslint-config for node",
"volta": {
"extends": "../../package.json"
8 changes: 8 additions & 0 deletions packages/eslint-plugin-node/src/configs/import.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {TSESLint} from '@typescript-eslint/utils';

const pluginPrefix = 'import-x';

export const importEslintRules: TSESLint.Linter.RulesRecord = {
// the node ecosystem loves to use default exports for some reason
[`${pluginPrefix}/no-named-as-default-member`]: 'off',
};
2 changes: 2 additions & 0 deletions packages/eslint-plugin-node/src/index.ts
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import pluginSecurity from 'eslint-plugin-security';
import pluginNode from 'eslint-plugin-n';
import {securityRules} from './configs/security';
import {nodeRules} from './configs/node';
import {importEslintRules} from './configs/import';

export const cloudflightNodeConfig = tseslint.config(
...cloudflightTypescriptConfig,
@@ -18,6 +19,7 @@ export const cloudflightNodeConfig = tseslint.config(
rules: {
...nodeRules,
...securityRules,
...importEslintRules,
}
},
);
2 changes: 1 addition & 1 deletion packages/eslint-plugin-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflight/eslint-plugin-react",
"version": "1.0.0-rc5",
"version": "1.0.0-rc6",
"description": "Cloudflight eslint-plugin & eslint-config for React",
"volta": {
"extends": "../../package.json"
10 changes: 9 additions & 1 deletion packages/eslint-plugin-typescript/README.md
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ In your `package.json` add the following:
}
```

Now open your `eslint.config.mts` and add one of the configurations:
Now open your `eslint.config.mjs` and add one of the configurations:

```ts
import { cloudflightTypescriptConfig } from '@cloudflight/eslint-plugin-typescript';
@@ -45,6 +45,14 @@ export default [
tsconfigRootDir: import.meta.dirname,
},
},
settings: {
'import-x/resolver': {
typescript: {
alwaysTryTypes: true,
project: ['tsconfig*(.*).json'],
},
},
},
},
];
```
4 changes: 3 additions & 1 deletion packages/eslint-plugin-typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflight/eslint-plugin-typescript",
"version": "1.0.0-rc5",
"version": "1.0.0-rc6",
"description": "Cloudflight eslint-plugin & eslint-config for typescript",
"volta": {
"extends": "../../package.json"
@@ -30,6 +30,8 @@
"@eslint/js": "^9.11.1",
"@typescript-eslint/eslint-plugin": "^8.8.0",
"@typescript-eslint/parser": "^8.8.0",
"eslint-import-resolver-typescript": "3.6.3",
"eslint-plugin-import-x": "4.3.1",
"typescript-eslint": "^8.8.0"
},
"peerDependencies": {
2 changes: 1 addition & 1 deletion packages/eslint-plugin-typescript/src/configs/import.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {TSESLint} from '@typescript-eslint/utils';

const pluginPrefix = 'import';
const pluginPrefix = 'import-x';

export const importEslintRules: TSESLint.Linter.RulesRecord = {
[`${pluginPrefix}/first`]: ['error'],
29 changes: 28 additions & 1 deletion packages/eslint-plugin-typescript/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import pluginJs from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslintPluginImportX from 'eslint-plugin-import-x';
import * as tsParser from '@typescript-eslint/parser';
import {eslintRules} from './configs/eslint';
import {typescriptEslintRules, typescriptEslintRulesDisableTypeChecked} from './configs/typescript-eslint';
import {customRules} from './configs/custom';
import {cloudflightTypescriptPlugin} from './rules';
import {importEslintRules} from './configs/import';

export const cloudflightTypescriptConfig = tseslint.config(
/**
* @deprecated Use `cloudflightTypescriptConfig` instead
* This is only for internal use because eslint-plugin-import-x cannot work with vue-eslint-parser
*/
export const cloudflightTypescriptBaseConfig = tseslint.config(
{
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
plugins: {
@@ -30,3 +37,23 @@ export const cloudflightTypescriptConfig = tseslint.config(
}
},
);

export const cloudflightTypescriptConfig = tseslint.config(
// eslint-disable-next-line @typescript-eslint/no-deprecated
...cloudflightTypescriptBaseConfig,
{
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
extends: [
eslintPluginImportX.flatConfigs.recommended,
eslintPluginImportX.flatConfigs.typescript,
],
languageOptions: {
parser: tsParser,
ecmaVersion: 'latest',
sourceType: 'module',
},
rules: {
...importEslintRules,
},
}
);
10 changes: 9 additions & 1 deletion packages/eslint-plugin-vue/README.md
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ In your `package.json` add the following:
}
```

Now open your `eslint.config.mts` and add one of the configurations:
Now open your `eslint.config.mjs` and add one of the configurations:

```ts
import { cloudflightVueConfig } from '@cloudflight/eslint-plugin-vue';
@@ -45,6 +45,14 @@ export default [
tsconfigRootDir: import.meta.dirname,
},
},
settings: {
'import-x/resolver': {
typescript: {
alwaysTryTypes: true,
project: ['tsconfig*(.*).json'],
},
},
},
},
];
```
2 changes: 1 addition & 1 deletion packages/eslint-plugin-vue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflight/eslint-plugin-vue",
"version": "1.0.0-rc5",
"version": "1.0.0-rc6",
"description": "Cloudflight eslint-plugin & eslint-config for vue",
"volta": {
"extends": "../../package.json"
5 changes: 3 additions & 2 deletions packages/eslint-plugin-vue/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tseslint from 'typescript-eslint';
import { cloudflightTypescriptConfig } from '@cloudflight/eslint-plugin-typescript';
import { cloudflightTypescriptBaseConfig, cloudflightTypescriptConfig } from '@cloudflight/eslint-plugin-typescript';
import {TSESLint} from '@typescript-eslint/utils';
// @ts-expect-error .d.ts file for eslint-plugin-vue has been implemented but not released yet
// if the following line fails to build after updating the version, simply remove this comment
@@ -13,7 +13,8 @@ export const cloudflightVueConfig = tseslint.config(
{
files: ['**/*.vue'],
extends: [
...cloudflightTypescriptConfig,
// eslint-disable-next-line @typescript-eslint/no-deprecated
...cloudflightTypescriptBaseConfig,
// .d.ts file for eslint-plugin-vue has been implemented but not released yet, if the
// following line fails to build after updating the version, simply remove this comment
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/consistent-type-assertions
251 changes: 151 additions & 100 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit 9a9b9a8

Please sign in to comment.