|
| 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' |
| 6 | +import json from 'eslint-plugin-json' |
| 7 | + |
| 8 | + |
| 9 | +export default tseslint.config( |
| 10 | + { ignores: [ |
| 11 | + 'dist', |
| 12 | + 'node_modules', |
| 13 | + '.yalc', |
| 14 | + 'src/rest/*' // do not lint generated code |
| 15 | + ] }, |
| 16 | + { |
| 17 | + extends: [js.configs.recommended, ...tseslint.configs.recommended], |
| 18 | + files: ['**/*.{ts,tsx,js,jsx}'], |
| 19 | + languageOptions: { |
| 20 | + ecmaVersion: "latest", |
| 21 | + globals: globals.browser, |
| 22 | + sourceType: "module" |
| 23 | + }, |
| 24 | + plugins: { |
| 25 | + 'react-hooks': reactHooks, |
| 26 | + 'react-refresh': reactRefresh, |
| 27 | + }, |
| 28 | + rules: { |
| 29 | + ...reactHooks.configs.recommended.rules, |
| 30 | + 'react-refresh/only-export-components': [ |
| 31 | + 'warn', |
| 32 | + { allowConstantExport: true }, |
| 33 | + ], |
| 34 | + indent: ["error", 2, { |
| 35 | + SwitchCase: 1, |
| 36 | + }], |
| 37 | + curly: "error", // enforce braces for one-line blocks |
| 38 | + "no-tabs": "error", // enforce no tabs |
| 39 | + "no-console": ["warn", { |
| 40 | + allow: ["warn", "error", "debug"], |
| 41 | + }], |
| 42 | + "consistent-return": "warn", // https://eslint.org/docs/latest/rules/consistent-return |
| 43 | + "prefer-arrow-callback": ["warn"], |
| 44 | + "object-curly-spacing": ["warn", "always"], // enforce consistent spacing inside braces |
| 45 | + "func-style": "off", // function expressions or arrow functions are equally valid |
| 46 | + "no-unneeded-ternary": "warn", // disallow unnecessary ternary expressions |
| 47 | + // React rules: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules |
| 48 | + "react/prop-types": "off", // PropTypes are not forced |
| 49 | + "react/forbid-prop-types": "off", // all PropTypes are allowed |
| 50 | + "react-hooks/rules-of-hooks": "error", // https://react.dev/reference/rules/rules-of-hooks |
| 51 | + "react-hooks/exhaustive-deps": "warn", // Hooks dependency array, sometimes it's better to ignore |
| 52 | + }, |
| 53 | + }, |
| 54 | + { // Linting for tsconfig.json files allows comments |
| 55 | + files: ["tsconfig*.json"], |
| 56 | + plugins: { json }, |
| 57 | + processor: "json/json", |
| 58 | + rules: { |
| 59 | + ...json.configs["recommended-with-comments"].rules, |
| 60 | + } |
| 61 | + }, |
| 62 | + { // Linting for *.json files do now allow comments |
| 63 | + files: ["**/*.json"], |
| 64 | + ignores: ["tsconfig*.json"], |
| 65 | + plugins: { json }, |
| 66 | + processor: "json/json", |
| 67 | + rules: { |
| 68 | + ...json.configs.recommended.rules, |
| 69 | + } |
| 70 | + } |
| 71 | +) |
0 commit comments