Skip to content

Commit

Permalink
Update Eslint to v9 (#235)
Browse files Browse the repository at this point in the history
* create initial config for eslint v9

Signed-off-by: Kangrui Johann Ye <[email protected]>

* include config for eslint and typescript eslint

Signed-off-by: Kangrui Johann Ye <[email protected]>

* fix build

Signed-off-by: Kangrui Johann Ye <[email protected]>

* bump version

Signed-off-by: Kangrui Johann Ye <[email protected]>

---------

Signed-off-by: Kangrui Johann Ye <[email protected]>
  • Loading branch information
strawberry-choco authored Oct 4, 2024
1 parent 6824f71 commit da60a0f
Show file tree
Hide file tree
Showing 18 changed files with 692 additions and 440 deletions.
6 changes: 0 additions & 6 deletions .eslintignore

This file was deleted.

20 changes: 0 additions & 20 deletions .eslintrc.js

This file was deleted.

46 changes: 46 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import tseslint from 'typescript-eslint';
import {includeIgnoreFile} from '@eslint/compat';
import {dirname, resolve} from 'node:path';
import {fileURLToPath} from 'node:url';
import { config } from '@cloudflight/eslint-plugin-typescript';

const filename = fileURLToPath(import.meta.url);
const directory = dirname(filename);
const gitignorePath = resolve(directory, '.gitignore');

export default tseslint.config(
includeIgnoreFile(gitignorePath),
{
// these files are temporarily disabled for linting
// until we are done with migrating everything to v9
ignores: [
'packages/eslint-plugin-angular/*',
'packages/eslint-plugin-node/*',
'packages/eslint-plugin-react/*',
'packages/eslint-plugin-vue/*',
'packages/eslint-plugin-typescript/src/configs/index.ts',
'packages/eslint-plugin-typescript/src/configs/recommended/*',
'packages/eslint-plugin-typescript/src/configs/recommended-json/*',
'packages/eslint-plugin-typescript/src/configs/recommended-package/*',
'packages/eslint-plugin-typescript/src/configs/recommended-typescript/recommended-typescript.config.ts',
'packages/eslint-plugin-typescript/src/configs/recommended-typescript/rules/custom.ts',
'packages/eslint-plugin-typescript/src/configs/recommended-typescript/rules/format.ts',
'packages/eslint-plugin-typescript/src/configs/recommended-typescript/rules/import.ts',
'packages/eslint-plugin-typescript/src/configs/recommended-typescript/rules/rxjs.ts',
'packages/eslint-plugin-typescript/src/rules/*',
'packages/eslint-plugin-typescript/src/util/*',
'scripts/*',
'.eslintrc.format.js',
'eslint.config.mjs',
]
},
...config,
{
languageOptions: {
parserOptions: {
project: ['./packages/*/tsconfig.json', './packages/*/tsconfig.spec.json'],
tsconfigRootDir: import.meta.dirname,
},
},
},
);
38 changes: 21 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflight/eslint-plugin",
"version": "0.26.0",
"version": "1.0.0-rc1",
"private": true,
"volta": {
"node": "20.12.2",
Expand All @@ -16,7 +16,7 @@
"description": "",
"scripts": {
"build": "yarn workspaces foreach -pA --topological-dev run build-package",
"lint": "eslint . && eslint --config .eslintrc.format.js .",
"lint": "eslint .",
"test": "yarn workspaces foreach -pA run test-package",
"postinstall": "husky",
"publish-workspaces": "node ./scripts/prepare.js && yarn workspaces foreach -A --no-private npm publish"
Expand All @@ -31,16 +31,18 @@
"@angular-eslint/eslint-plugin": "17.3.0",
"@angular-eslint/eslint-plugin-template": "17.3.0",
"@angular-eslint/template-parser": "17.3.0",
"@rushstack/eslint-patch": "1.10.2",
"@types/eslint": "8.56.10",
"@types/estree": "1.0.5",
"@types/jest": "29.5.12",
"@types/node": "20.12.10",
"@typescript-eslint/eslint-plugin": "7.8.0",
"@typescript-eslint/parser": "7.8.0",
"@typescript-eslint/utils": "7.8.0",
"@eslint/compat": "1.1.1",
"@eslint/js": "9.11.1",
"@types/eslint": "9.6.1",
"@types/eslint__js": "8.42.3",
"@types/estree": "1.0.6",
"@types/jest": "29.5.13",
"@types/node": "20.16.10",
"@typescript-eslint/eslint-plugin": "8.8.0",
"@typescript-eslint/parser": "8.8.0",
"@typescript-eslint/utils": "8.8.0",
"@vue/eslint-config-typescript": "13.0.0",
"eslint": "8.57.0",
"eslint": "9.11.1",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-json-es": "1.6.0",
"eslint-plugin-jsx-a11y": "6.8.0",
Expand All @@ -51,15 +53,17 @@
"eslint-plugin-rxjs": "5.0.3",
"eslint-plugin-security": "3.0.0",
"eslint-plugin-vue": "9.25.0",
"husky": "9.0.11",
"globals": "15.10.0",
"husky": "9.1.6",
"jest": "29.7.0",
"lint-staged": "15.2.2",
"ts-jest": "29.1.2",
"lint-staged": "15.2.10",
"ts-jest": "29.2.5",
"ts-node": "10.9.2",
"typescript": "5.4.5"
"typescript": "5.5.4",
"typescript-eslint": "8.8.0"
},
"lint-staged": {
"*.js": "eslint --config .eslintrc.format.js --fix",
"*.ts": "eslint --config .eslintrc.format.js --fix"
"*.js": "echo 'Not Implemented'",
"*.ts": "echo 'Not Implemented'"
}
}
3 changes: 1 addition & 2 deletions packages/eslint-plugin-angular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ The following dependencies are required:

```
"@cloudflight/eslint-plugin-typescript": ">=0.26.0",
"@rushstack/eslint-patch": "1.10.2",
"eslint": ">=8.0.0 <9.0.0"
"eslint": ">=9.0.0 < 10.0.0"
```

## Usage
Expand Down
9 changes: 5 additions & 4 deletions 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": "0.26.0",
"version": "1.0.0-rc1",
"description": "Cloudflight eslint-plugin & eslint-config for angular",
"volta": {
"extends": "../../package.json"
Expand All @@ -22,8 +22,9 @@
"publishConfig": {
"access": "public"
},
"private": true,
"scripts": {
"build-package": "tsc"
"build-packagex": "tsc"
},
"dependencies": {
"@angular-eslint/eslint-plugin": "^17.3.0",
Expand All @@ -32,9 +33,9 @@
},
"peerDependencies": {
"@cloudflight/eslint-plugin-typescript": "workspace:*",
"eslint": ">=8.0.0 <9.0.0"
"eslint": ">=9.0.0 < 10.0.0"
},
"devDependencies": {
"typescript": "5.4.5"
"typescript": "5.5.4"
}
}
3 changes: 1 addition & 2 deletions packages/eslint-plugin-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ The following dependencies are required:

```
"@cloudflight/eslint-plugin-typescript": ">=0.26.0",
"@rushstack/eslint-patch": "1.10.2",
"eslint": ">=8.0.0 <9.0.0"
"eslint": ">=9.0.0 < 10.0.0"
```

## Usage
Expand Down
9 changes: 5 additions & 4 deletions 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": "0.26.0",
"version": "1.0.0-rc1",
"description": "Cloudflight eslint-plugin & eslint-config for node",
"volta": {
"extends": "../../package.json"
Expand All @@ -22,8 +22,9 @@
"publishConfig": {
"access": "public"
},
"private": true,
"scripts": {
"build-package": "tsc"
"build-packagex": "tsc"
},
"dependencies": {
"eslint-plugin-no-unsanitized": "^4.0.2",
Expand All @@ -32,9 +33,9 @@
},
"peerDependencies": {
"@cloudflight/eslint-plugin-typescript": "workspace:*",
"eslint": ">=8.0.0 <9.0.0"
"eslint": ">=9.0.0 < 10.0.0"
},
"devDependencies": {
"typescript": "5.4.5"
"typescript": "5.5.4"
}
}
3 changes: 1 addition & 2 deletions packages/eslint-plugin-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ The following dependencies are required:

```
"@cloudflight/eslint-plugin-typescript": ">=0.26.0",
"@rushstack/eslint-patch": "1.10.2",
"eslint": ">=8.0.0 <9.0.0"
"eslint": ">=9.0.0 < 10.0.0"
```

## Usage
Expand Down
9 changes: 5 additions & 4 deletions 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": "0.26.0",
"version": "1.0.0-rc1",
"description": "Cloudflight eslint-plugin & eslint-config for React",
"volta": {
"extends": "../../package.json"
Expand All @@ -22,8 +22,9 @@
"publishConfig": {
"access": "public"
},
"private": true,
"scripts": {
"build-package": "tsc"
"build-packagex": "tsc"
},
"dependencies": {
"eslint-plugin-jsx-a11y": "^6.8.0",
Expand All @@ -32,9 +33,9 @@
},
"peerDependencies": {
"@cloudflight/eslint-plugin-typescript": "workspace:*",
"eslint": ">=8.0.0 <9.0.0"
"eslint": ">=9.0.0 < 10.0.0"
},
"devDependencies": {
"typescript": "5.4.5"
"typescript": "5.5.4"
}
}
3 changes: 1 addition & 2 deletions packages/eslint-plugin-typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ You can find the directory of all rules including their reasoning [here](src/con
The following dependencies are required:

```
"@rushstack/eslint-patch": "1.10.2",
"eslint": ">=8.0.0 <9.0.0"
"eslint": ">=9.0.0 < 10.0.0"
```

## Usage
Expand Down
17 changes: 10 additions & 7 deletions 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": "0.26.0",
"version": "1.0.0-rc1",
"description": "Cloudflight eslint-plugin & eslint-config for typescript",
"volta": {
"extends": "../../package.json"
Expand All @@ -24,20 +24,23 @@
},
"scripts": {
"build-package": "tsc",
"test-package": "jest"
"test-packagex": "jest"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"@eslint/js": "^9.11.1",
"@typescript-eslint/eslint-plugin": "^8.8.0",
"@typescript-eslint/parser": "^8.8.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-json-es": "^1.6.0",
"eslint-plugin-rxjs": "^5.0.3",
"eslint-plugin-simple-import-sort": "^12.1.0"
"eslint-plugin-simple-import-sort": "^12.1.0",
"globals": "^15.10.0",
"typescript-eslint": "^8.8.0"
},
"peerDependencies": {
"eslint": ">=8.0.0 <9.0.0"
"eslint": ">=9.0.0 < 10.0.0"
},
"devDependencies": {
"typescript": "5.4.5"
"typescript": "5.5.4"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,13 @@ import {TSESLint} from '@typescript-eslint/utils';
const pluginPrefix = '@typescript-eslint';

export const typescriptEslintRules: TSESLint.Linter.RulesRecord = {
[`${pluginPrefix}/ban-types`]: [
'error',
{
types: {
String: {message: 'Use string instead', fixWith: 'string'},
Boolean: {message: 'Use boolean instead', fixWith: 'boolean'},
Number: {message: 'Use number instead', fixWith: 'number'},
Symbol: {message: 'Use symbol instead', fixWith: 'symbol'},
Function: {
message:
// eslint-disable-next-line max-len
'The `Function` type accepts any function-like value.\nIt provides no type safety when calling the function, which can be a common source of bugs.\nIt also accepts things like class declarations, which will throw at runtime as they will not be called with `new`.\nIf you are expecting the function to accept certain arguments, you should explicitly define the function shape.',
},
Object: {
message:
// eslint-disable-next-line max-len
'The `Object` type actually means "any non-nullish value", so it is marginally better than `unknown`.\n- If you want a type meaning "any object", you probably want `Record<string, unknown>` instead.\n- If you want a type meaning "any value", you probably want `unknown` instead.',
},
'{}': {
message:
// eslint-disable-next-line max-len
'`{}` actually means "any non-nullish value".\n- If you want a type meaning "any object", you probably want `Record<string, unknown>` instead.\n- If you want a type meaning "any value", you probably want `unknown` instead.',
},
},
},
],
// we do not need to care about js codebases, they are outside our scope
[`${pluginPrefix}/consistent-generic-constructors`]: 'off',
[`${pluginPrefix}/consistent-type-assertions`]: ['error', {assertionStyle: 'never'}],
'default-param-last': 'off',
[`${pluginPrefix}/default-param-last`]: ['error'],
[`${pluginPrefix}/explicit-function-return-type`]: ['error', {allowExpressions: true}],
[`${pluginPrefix}/explicit-member-accessibility`]: ['error', {accessibility: 'explicit'}],
[`${pluginPrefix}/member-delimiter-style`]: [
'error',
{multiline: {delimiter: 'semi', requireLast: true}, singleline: {delimiter: 'semi', requireLast: false}},
],
[`${pluginPrefix}/member-ordering`]: [
'error',
{default: ['static-field', 'field', 'signature', 'constructor', 'static-method', 'method']},
Expand Down Expand Up @@ -70,11 +40,6 @@ export const typescriptEslintRules: TSESLint.Linter.RulesRecord = {
[`${pluginPrefix}/no-unused-vars`]: ['error', {args: 'none', ignoreRestSiblings: true}],
[`${pluginPrefix}/promise-function-async`]: ['error'],
[`${pluginPrefix}/require-array-sort-compare`]: ['error'],
semi: 'off',
[`${pluginPrefix}/semi`]: ['error'],
'no-extra-semi': 'off',
[`${pluginPrefix}/no-extra-semi`]: ['error'],
[`${pluginPrefix}/strict-boolean-expressions`]: ['error'],
[`${pluginPrefix}/switch-exhaustiveness-check`]: ['error'],
[`${pluginPrefix}/type-annotation-spacing`]: ['error'],
};
25 changes: 23 additions & 2 deletions packages/eslint-plugin-typescript/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
export {configs} from './configs';
export {rules} from './rules';
import pluginJs from '@eslint/js';
import tseslint from 'typescript-eslint';
import {eslintRules} from './configs/recommended-typescript/rules/eslint';
import {typescriptEslintRules} from './configs/recommended-typescript/rules/typescript-eslint';

export const config = tseslint.config(
{
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
ignores: ['jest.config*.ts'],
extends: [
pluginJs.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
],
rules: {
...eslintRules,
...typescriptEslintRules,
}
},
{
files: ['**/*.{js,mjs,cjs}'],
extends: [tseslint.configs.disableTypeChecked],
},
);
Loading

0 comments on commit da60a0f

Please sign in to comment.