diff --git a/eslint.ts.react.config.base.mjs b/eslint.ts.react.config.base.mjs new file mode 100644 index 00000000..110f1e8a --- /dev/null +++ b/eslint.ts.react.config.base.mjs @@ -0,0 +1,89 @@ +import eslint from '@eslint/js'; +import tseslint from 'typescript-eslint'; +import react from 'eslint-plugin-react'; +import { fixupPluginRules } from '@eslint/compat'; +import eslintPluginReactHooks from 'eslint-plugin-react-hooks'; +import eslintConfigPrettier from 'eslint-config-prettier'; + +export default ( + tsconfigRootDir, + files = ['**/*.ts', '**/*.tsx'], + project = true, +) => [ + { + files, + ...eslint.configs.recommended, + }, + ...tseslint.configs.recommendedTypeChecked.map((config) => ({ + files, + ...config, + })), + ...tseslint.configs.stylisticTypeChecked.map((config) => ({ + files, + ...config, + })), + { + files, + languageOptions: { + parserOptions: { + project, + tsconfigRootDir, + }, + }, + }, + { + files, + ...react.configs.flat.recommended, + }, + { + files, + settings: { + react: { + version: 'detect', + }, + }, + }, + { + files, + plugins: { + 'react-hooks': fixupPluginRules(eslintPluginReactHooks), + }, + }, + { + files, + ...eslintConfigPrettier, + }, + { + files, + rules: { + '@typescript-eslint/no-unsafe-return': 'off', + '@typescript-eslint/no-unsafe-assignment': 'off', + '@typescript-eslint/no-unsafe-call': 'off', + '@typescript-eslint/no-unsafe-member-access': 'off', + '@typescript-eslint/no-misused-promises': [ + 'error', + { + checksVoidReturn: { + attributes: false, + }, + }, + ], + '@typescript-eslint/prefer-optional-chain': 'off', + '@typescript-eslint/no-base-to-string': 'off', + '@typescript-eslint/consistent-indexed-object-style': 'off', + '@typescript-eslint/prefer-nullish-coalescing': 'off', + '@typescript-eslint/consistent-type-definitions': 'off', + '@typescript-eslint/no-unused-vars': 'off', + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/prefer-for-of': 'off', + '@typescript-eslint/non-nullable-type-assertion-style': 'off', + '@typescript-eslint/class-literal-property-style': 'off', + '@typescript-eslint/no-redundant-type-constituents': 'off', + '@typescript-eslint/prefer-string-starts-ends-with': 'off', + '@typescript-eslint/no-duplicate-type-constituents': 'off', + '@typescript-eslint/array-type': 'off', + '@typescript-eslint/prefer-function-type': 'off', + 'react/prop-types': 'off', + }, + }, +]; diff --git a/eslint.ts.react.jest.config.base.mjs b/eslint.ts.react.jest.config.base.mjs new file mode 100644 index 00000000..4a4a2897 --- /dev/null +++ b/eslint.ts.react.jest.config.base.mjs @@ -0,0 +1,94 @@ +import eslint from '@eslint/js'; +import tseslint from 'typescript-eslint'; +import react from 'eslint-plugin-react'; +import { fixupPluginRules } from '@eslint/compat'; +import eslintPluginReactHooks from 'eslint-plugin-react-hooks'; +import jest from 'eslint-plugin-jest'; +import eslintConfigPrettier from 'eslint-config-prettier'; + +export default (files, tsconfigRootDir, project) => [ + { + files, + ...eslint.configs.recommended, + }, + ...tseslint.configs.recommendedTypeChecked.map((config) => ({ + files, + ...config, + })), + ...tseslint.configs.stylisticTypeChecked.map((config) => ({ + files, + ...config, + })), + { + files, + languageOptions: { + parserOptions: { + project, + tsconfigRootDir, + }, + }, + }, + { + files, + ...react.configs.flat.recommended, + }, + { + files, + settings: { + react: { + version: 'detect', + }, + }, + }, + { + files, + plugins: { + 'react-hooks': fixupPluginRules(eslintPluginReactHooks), + }, + }, + { + files, + ...jest.configs['flat/recommended'], + }, + { + files, + ...jest.configs['jest/style'], + }, + { + files, + ...eslintConfigPrettier, + }, + { + files, + rules: { + '@typescript-eslint/no-unsafe-return': 'off', + '@typescript-eslint/no-unsafe-assignment': 'off', + '@typescript-eslint/no-unsafe-call': 'off', + '@typescript-eslint/no-unsafe-member-access': 'off', + '@typescript-eslint/no-misused-promises': [ + 'error', + { + checksVoidReturn: { + attributes: false, + }, + }, + ], + '@typescript-eslint/prefer-optional-chain': 'off', + '@typescript-eslint/no-base-to-string': 'off', + '@typescript-eslint/consistent-indexed-object-style': 'off', + '@typescript-eslint/prefer-nullish-coalescing': 'off', + '@typescript-eslint/consistent-type-definitions': 'off', + '@typescript-eslint/no-unused-vars': 'off', + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/prefer-for-of': 'off', + '@typescript-eslint/non-nullable-type-assertion-style': 'off', + '@typescript-eslint/class-literal-property-style': 'off', + '@typescript-eslint/no-redundant-type-constituents': 'off', + '@typescript-eslint/prefer-string-starts-ends-with': 'off', + '@typescript-eslint/no-duplicate-type-constituents': 'off', + '@typescript-eslint/array-type': 'off', + '@typescript-eslint/prefer-function-type': 'off', + 'react/prop-types': 'off', + }, + }, +]; diff --git a/package.json b/package.json index 385ec655..a1868f97 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "@babel/core": "^7.25.2", "@babel/eslint-parser": "^7.25.1", "@changesets/cli": "^2.27.7", + "@eslint/compat": "^1.1.1", "@eslint/js": "^8.57.0", "@nrwl/nx-cloud": "^19.0.0", "@typescript-eslint/eslint-plugin": "^8.0.1", diff --git a/packages/react-dock/.eslintignore b/packages/react-dock/.eslintignore deleted file mode 100644 index d3c23dcb..00000000 --- a/packages/react-dock/.eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -demo -lib diff --git a/packages/react-dock/.eslintrc.cjs b/packages/react-dock/.eslintrc.cjs deleted file mode 100644 index 33fb8f94..00000000 --- a/packages/react-dock/.eslintrc.cjs +++ /dev/null @@ -1,21 +0,0 @@ -module.exports = { - extends: '../../eslintrc.js.base.json', - overrides: [ - { - files: ['*.ts', '*.tsx'], - extends: '../../eslintrc.ts.react.base.json', - parserOptions: { - tsconfigRootDir: __dirname, - project: true, - }, - }, - { - files: ['test/**/*.ts', 'test/**/*.tsx'], - extends: '../../eslintrc.ts.react.jest.base.json', - parserOptions: { - tsconfigRootDir: __dirname, - project: ['./tsconfig.test.json'], - }, - }, - ], -}; diff --git a/packages/react-dock/demo/.eslintignore b/packages/react-dock/demo/.eslintignore deleted file mode 100644 index 1521c8b7..00000000 --- a/packages/react-dock/demo/.eslintignore +++ /dev/null @@ -1 +0,0 @@ -dist diff --git a/packages/react-dock/demo/.eslintrc.js b/packages/react-dock/demo/.eslintrc.js deleted file mode 100644 index 6a8196ce..00000000 --- a/packages/react-dock/demo/.eslintrc.js +++ /dev/null @@ -1,17 +0,0 @@ -module.exports = { - extends: '../../../eslintrc.ts.react.base.json', - parserOptions: { - tsconfigRootDir: __dirname, - project: true, - }, - overrides: [ - { - files: ['webpack.config.ts'], - extends: '../../../eslintrc.ts.base.json', - parserOptions: { - tsconfigRootDir: __dirname, - project: ['./tsconfig.webpack.json'], - }, - }, - ], -}; diff --git a/packages/react-dock/demo/eslint.config.mjs b/packages/react-dock/demo/eslint.config.mjs new file mode 100644 index 00000000..fb96ee3e --- /dev/null +++ b/packages/react-dock/demo/eslint.config.mjs @@ -0,0 +1,15 @@ +import eslintJs from '../../../eslint.js.config.base.mjs'; +import eslintTs from '../../../eslint.ts.react.config.base.mjs'; + +export default [ + ...eslintJs, + ...eslintTs(import.meta.dirname), + ...eslintTs( + import.meta.dirname, + ['webpack.config.ts'], + ['./tsconfig.webpack.json'], + ), + { + ignores: ['dist'], + }, +]; diff --git a/packages/react-dock/demo/package.json b/packages/react-dock/demo/package.json index 010aa4f9..900794ce 100644 --- a/packages/react-dock/demo/package.json +++ b/packages/react-dock/demo/package.json @@ -6,7 +6,7 @@ "scripts": { "start": "cross-env TS_NODE_PROJECT=\"tsconfig.webpack.json\" webpack serve --open", "build": "cross-env TS_NODE_PROJECT=\"tsconfig.webpack.json\" webpack", - "lint": "eslint . --ext .ts,.tsx", + "lint": "eslint .", "type-check": "tsc --noEmit" }, "dependencies": { diff --git a/packages/react-dock/eslint.config.js b/packages/react-dock/eslint.config.js new file mode 100644 index 00000000..1ad99e50 --- /dev/null +++ b/packages/react-dock/eslint.config.js @@ -0,0 +1,14 @@ +import eslintJs from '../../eslint.js.config.base.mjs'; +import eslintTsReact from '../../eslint.ts.react.config.base.mjs'; +import eslintTsReactJest from '../../eslint.ts.react.jest.config.base.mjs'; + +export default [ + ...eslintJs, + ...eslintTsReact(import.meta.dirname), + ...eslintTsReactJest(['test/**/*.ts', 'test/**/*.tsx'], import.meta.dirname, [ + './tsconfig.test.json', + ]), + { + ignores: ['demo', 'lib'], + }, +]; diff --git a/packages/react-dock/package.json b/packages/react-dock/package.json index f8b4855d..4d08aff6 100644 --- a/packages/react-dock/package.json +++ b/packages/react-dock/package.json @@ -30,7 +30,7 @@ "build": "tsc", "clean": "rimraf lib", "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js", - "lint": "eslint . --ext .ts,.tsx", + "lint": "eslint .", "type-check": "tsc --noEmit", "prepack": "pnpm run clean && pnpm run build", "prepublish": "pnpm run lint && pnpm run test" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 27199bad..73621cc8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ importers: '@changesets/cli': specifier: ^2.27.7 version: 2.27.7 + '@eslint/compat': + specifier: ^1.1.1 + version: 1.1.1 '@eslint/js': specifier: ^8.57.0 version: 8.57.0 @@ -7038,6 +7041,11 @@ packages: engines: {node: ^12.0.0 || ^14.0.0 || >=16.0.0} dev: true + /@eslint/compat@1.1.1: + resolution: {integrity: sha512-lpHyRyplhGPL5mGEh6M9O5nnKk0Gz4bFI+Zu6tKlPpDUN7XshWvH9C/px4UVm87IAANE0W81CEsNGbS1KlzXpA==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + dev: true + /@eslint/eslintrc@2.1.4: resolution: {integrity: sha512-269Z39MS6wVJtsoUl10L60WdkhJVdPG24Q4eZTH3nnF6lpvSShEK3wQjDX9JRWAUPvPh7COouPpU9IrqaZFvtQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}