|
| 1 | +// @ts-check |
| 2 | +import { fileURLToPath } from 'node:url'; |
| 3 | +import { includeIgnoreFile } from '@eslint/compat'; |
| 4 | +import { defineConfig } from 'eslint/config'; |
| 5 | +import globals from 'globals'; |
| 6 | +import js from '@eslint/js'; |
| 7 | +import ts from 'typescript-eslint'; |
| 8 | +import react from 'eslint-plugin-react'; |
| 9 | +import json from '@eslint/json'; |
| 10 | +// @ts-expect-error |
| 11 | +import cypress from 'eslint-plugin-cypress'; |
| 12 | +import prettierConfig from 'eslint-config-prettier/flat'; |
| 13 | + |
| 14 | +// paths shouldn't start with ./ |
| 15 | + |
| 16 | +const gitignorePath = fileURLToPath( |
| 17 | + new URL( |
| 18 | + '.gitignore', |
| 19 | + // @ts-expect-error ts doesn't respect this file as a module, can ignore |
| 20 | + import.meta.url, |
| 21 | + ), |
| 22 | +); |
| 23 | + |
| 24 | +export default defineConfig( |
| 25 | + includeIgnoreFile(gitignorePath, 'Imported .gitignore patterns'), |
| 26 | + { |
| 27 | + name: 'ignores', |
| 28 | + ignores: [ |
| 29 | + // generated files we don't control |
| 30 | + '**/package-lock.json', |
| 31 | + 'src/config/generated/**', |
| 32 | + // has it's own eslint |
| 33 | + 'experimental/license-inventory', |
| 34 | + // vendored code we're not changing |
| 35 | + 'src/ui/assets/js/**', |
| 36 | + 'src/ui/assets/css/**', |
| 37 | + ], |
| 38 | + }, |
| 39 | + |
| 40 | + { |
| 41 | + name: 'JSON', |
| 42 | + files: ['**/*.json'], |
| 43 | + plugins: { json }, |
| 44 | + extends: [json.configs.recommended], |
| 45 | + language: 'json/json', |
| 46 | + }, |
| 47 | + |
| 48 | + { |
| 49 | + name: 'JSON - proxy.config.json override', |
| 50 | + files: ['**/proxy.config.json'], |
| 51 | + // allow empty keys in proxy.config.json for now |
| 52 | + rules: { 'json/no-empty-keys': 'off' }, |
| 53 | + }, |
| 54 | + |
| 55 | + // attempt at accurately linting each "type" of code we have |
| 56 | + // much of this can be consolidated going forward, or split out in |
| 57 | + // the case of the frontend |
| 58 | + { |
| 59 | + name: 'JS', |
| 60 | + files: ['**/*.{js,jsx,mjs,cjs,ts,tsx}'], |
| 61 | + plugins: { js }, |
| 62 | + extends: [js.configs.recommended], |
| 63 | + languageOptions: { |
| 64 | + globals: { |
| 65 | + ...globals.node, |
| 66 | + // allow commonjs during the migration |
| 67 | + ...globals.commonjs, |
| 68 | + }, |
| 69 | + }, |
| 70 | + rules: { 'no-unused-vars': 'warn', 'no-undef': 'warn', 'guard-for-in': 'error' }, |
| 71 | + }, |
| 72 | + |
| 73 | + { |
| 74 | + name: 'TS', |
| 75 | + files: ['**/*.{js,jsx,ts,tsx}'], |
| 76 | + plugins: { '@typescript-eslint': ts.plugin }, |
| 77 | + extends: [ts.configs.recommended], |
| 78 | + languageOptions: { globals: { ...globals.node } }, |
| 79 | + rules: { |
| 80 | + 'no-async-promise-executor': 'warn', // to resolve and return to default |
| 81 | + '@typescript-eslint/no-explicit-any': 'off', // temporary until TS refactor is complete |
| 82 | + // '@typescript-eslint/no-unused-vars': 'off', // temporary until TS refactor is complete |
| 83 | + // "no-unused-vars": 'off', |
| 84 | + '@typescript-eslint/no-unused-vars': [ |
| 85 | + // TODO: increase this to error |
| 86 | + 'off', |
| 87 | + { |
| 88 | + // allow ignoring/skipping a var with a _ prefix |
| 89 | + // also allow for `...otherStuff` syntax, particularly common in react |
| 90 | + argsIgnorePattern: '^_', |
| 91 | + caughtErrorsIgnorePattern: '^_', |
| 92 | + destructuredArrayIgnorePattern: '^_', |
| 93 | + varsIgnorePattern: '^_', |
| 94 | + ignoreRestSiblings: true, |
| 95 | + }, |
| 96 | + ], |
| 97 | + '@typescript-eslint/no-require-imports': 'off', // prevents error on old "require" imports |
| 98 | + }, |
| 99 | + }, |
| 100 | + |
| 101 | + { |
| 102 | + name: 'JS minus type checking', |
| 103 | + // disable type-aware linting on JS files |
| 104 | + files: ['**/*.js'], |
| 105 | + extends: [ts.configs.disableTypeChecked], |
| 106 | + }, |
| 107 | + |
| 108 | + // web/react content |
| 109 | + { |
| 110 | + name: 'web/react', |
| 111 | + files: [ |
| 112 | + 'src/ui/**/*.{js,jsx,mjs,cjs,ts,tsx}', |
| 113 | + // TODO: split website into separate linting |
| 114 | + 'website/src/**/*.{js,jsx,mjs,cjs,ts,tsx}', |
| 115 | + ], |
| 116 | + plugins: { react }, |
| 117 | + extends: [react.configs.flat.recommended], |
| 118 | + languageOptions: { globals: { ...globals.browser, ...globals.commonjs } }, |
| 119 | + settings: { react: { version: 'detect' } }, |
| 120 | + rules: { |
| 121 | + 'react/jsx-uses-react': 'error', |
| 122 | + 'react/jsx-uses-vars': 'error', |
| 123 | + 'react/prop-types': 'off', |
| 124 | + }, |
| 125 | + }, |
| 126 | + |
| 127 | + // tests |
| 128 | + { |
| 129 | + name: 'tests', |
| 130 | + files: ['**/*.test.{js,mjs,cjs}'], |
| 131 | + languageOptions: { |
| 132 | + // allow global functions e.g. describe, it, expect, etc. |
| 133 | + // from mocha and chai in tests |
| 134 | + globals: { ...globals.mocha, ...globals.chai }, |
| 135 | + }, |
| 136 | + rules: { |
| 137 | + '@typescript-eslint/no-unused-vars': [ |
| 138 | + // TODO: increase to 'error' |
| 139 | + 'warn', |
| 140 | + { |
| 141 | + argsIgnorePattern: '^_', |
| 142 | + caughtErrorsIgnorePattern: '^_', |
| 143 | + destructuredArrayIgnorePattern: '^_', |
| 144 | + varsIgnorePattern: '^_', |
| 145 | + ignoreRestSiblings: true, |
| 146 | + // same as rule above but exclude unused error vars in try catch for |
| 147 | + // now due to many warnings in tests |
| 148 | + caughtErrors: 'none', |
| 149 | + }, |
| 150 | + ], |
| 151 | + // allow for chai `expect().to.xyz` |
| 152 | + '@typescript-eslint/no-unused-expressions': 'off', |
| 153 | + }, |
| 154 | + }, |
| 155 | + |
| 156 | + // cypress e2e tests |
| 157 | + { |
| 158 | + name: 'cypress', |
| 159 | + files: ['cypress/**/*.{js,mjs,cjs,ts}'], |
| 160 | + extends: [cypress.configs.recommended], |
| 161 | + rules: { |
| 162 | + // TODO: fix and remove 'warn' override |
| 163 | + 'cypress/unsafe-to-chain-command': 'warn', |
| 164 | + }, |
| 165 | + }, |
| 166 | + |
| 167 | + // disables rules which prettier controls |
| 168 | + // https://prettier.io/docs/integrating-with-linters |
| 169 | + prettierConfig, |
| 170 | +); |
0 commit comments