|
1 | | -import js from '@eslint/js' |
2 | | -import globals from 'globals' |
3 | | -import reactHooks from 'eslint-plugin-react-hooks' |
4 | | -import reactRefresh from 'eslint-plugin-react-refresh' |
5 | | -import tseslint from 'typescript-eslint' |
| 1 | +// eslint.config.js |
| 2 | +import path from "path"; |
| 3 | +import { fileURLToPath } from "url"; |
| 4 | +import { FlatCompat } from "@eslint/eslintrc"; |
| 5 | +import tsParser from "@typescript-eslint/parser"; |
| 6 | +import pluginPrettier from "eslint-plugin-prettier"; |
| 7 | +import pluginImport from "eslint-plugin-import"; |
| 8 | +import pluginReact from "eslint-plugin-react"; |
| 9 | +import pluginReactHooks from "eslint-plugin-react-hooks"; |
| 10 | +import pluginTs from "@typescript-eslint/eslint-plugin"; |
6 | 11 |
|
7 | | -export default tseslint.config( |
8 | | - { ignores: ['dist', "src/osparc-api-ts-client/*"] }, |
| 12 | +// __dirname in ESM |
| 13 | +const __filename = fileURLToPath(import.meta.url); |
| 14 | +const __dirname = path.dirname(__filename); |
| 15 | + |
| 16 | +// Pass in ESLint’s own recommended config |
| 17 | +const compat = new FlatCompat({ |
| 18 | + baseDirectory: __dirname, |
| 19 | + recommendedConfig: {}, |
| 20 | +}); |
| 21 | +export default [ |
| 22 | + { |
| 23 | + ignores: [ |
| 24 | + "**", // ignore everything |
| 25 | + "!src/**", // except files under src/ |
| 26 | + "src/osparc-api-ts-client/**", // ignore osparc-api-ts-client |
| 27 | + ], |
| 28 | + }, |
9 | 29 | { |
10 | | - extends: [js.configs.recommended, ...tseslint.configs.recommended], |
11 | | - files: ['**/*.{ts,tsx}'], |
| 30 | + plugins: { |
| 31 | + prettier: pluginPrettier, |
| 32 | + import: pluginImport, |
| 33 | + react: pluginReact, |
| 34 | + "react-hooks": pluginReactHooks, |
| 35 | + "@typescript-eslint": pluginTs, |
| 36 | + }, |
12 | 37 | languageOptions: { |
13 | | - ecmaVersion: 2020, |
14 | | - globals: globals.browser, |
| 38 | + parser: tsParser, |
| 39 | + parserOptions: { |
| 40 | + project: path.resolve(__dirname, "./tsconfig.app.json"), |
| 41 | + tsconfigRootDir: __dirname, |
| 42 | + sourceType: "module", |
| 43 | + ecmaFeatures: { jsx: true }, |
| 44 | + }, |
15 | 45 | }, |
16 | | - plugins: { |
17 | | - 'react-hooks': reactHooks, |
18 | | - 'react-refresh': reactRefresh, |
| 46 | + }, |
| 47 | + ...compat.extends( |
| 48 | + "eslint:recommended", |
| 49 | + "plugin:react/jsx-runtime", |
| 50 | + "plugin:import/recommended", |
| 51 | + "plugin:import/typescript", |
| 52 | + "plugin:react-hooks/recommended", |
| 53 | + "plugin:@typescript-eslint/recommended", |
| 54 | + "airbnb", |
| 55 | + "airbnb-typescript", |
| 56 | + "airbnb/hooks", |
| 57 | + "prettier", |
| 58 | + ), |
| 59 | + |
| 60 | + // 2) Your custom overrides for JS/TS files |
| 61 | + { |
| 62 | + files: ["src/**/*.{js,jsx,ts,tsx}"], |
| 63 | + settings: { |
| 64 | + react: { |
| 65 | + version: "detect", |
| 66 | + runtime: "automatic", |
| 67 | + }, |
| 68 | + "import/resolver": { |
| 69 | + typescript: { project: "./tsconfig.json" }, |
| 70 | + alias: { |
| 71 | + map: [["@", "./src"]], |
| 72 | + extensions: [".ts", ".tsx", ".js", ".jsx", ".json"], |
| 73 | + }, |
| 74 | + }, |
19 | 75 | }, |
| 76 | + |
20 | 77 | rules: { |
21 | | - ...reactHooks.configs.recommended.rules, |
| 78 | + "react/react-in-jsx-scope": "off", |
| 79 | + "react/prop-types": "off", |
| 80 | + "prettier/prettier": ["error"], |
| 81 | + "import/no-extraneous-dependencies": ["error", { devDependencies: true }], |
| 82 | + "no-underscore-dangle": "off", |
| 83 | + "react/require-default-props": "off", |
| 84 | + "react/function-component-definition": "off", |
| 85 | + "import/prefer-default-export": "off", |
| 86 | + "react/jsx-no-useless-fragment": "off", |
| 87 | + "no-restricted-syntax": "off", |
| 88 | + "@typescript-eslint/lines-between-class-members": "off", |
| 89 | + "max-classes-per-file": ["warn", 2], |
| 90 | + "prefer-regex-literals": "off", |
| 91 | + "no-control-regex": "off", |
| 92 | + "no-console": "off", |
| 93 | + "no-await-in-loop": "off", |
| 94 | + "react/jsx-props-no-spreading": "off", |
22 | 95 | "@typescript-eslint/no-unused-vars": [ |
23 | | - "warn", // or "error" |
| 96 | + "error", |
24 | 97 | { |
25 | | - "argsIgnorePattern": "^_", |
26 | | - "varsIgnorePattern": "^_", |
27 | | - "caughtErrorsIgnorePattern": "^_" |
28 | | - } |
29 | | - ], |
30 | | - 'react-refresh/only-export-components': [ |
31 | | - 'warn', |
32 | | - { allowConstantExport: true }, |
| 98 | + args: "all", |
| 99 | + argsIgnorePattern: "^_", |
| 100 | + caughtErrors: "all", |
| 101 | + caughtErrorsIgnorePattern: "^_", |
| 102 | + destructuredArrayIgnorePattern: "^_", |
| 103 | + varsIgnorePattern: "^_", |
| 104 | + ignoreRestSiblings: true, |
| 105 | + }, |
33 | 106 | ], |
34 | 107 | }, |
35 | 108 | }, |
36 | | -) |
| 109 | +]; |
0 commit comments