|
| 1 | +import ts from '@typescript-eslint/eslint-plugin' |
| 2 | +import tsParser from '@typescript-eslint/parser' |
| 3 | +import prettier from 'eslint-config-prettier' |
| 4 | +import react from 'eslint-plugin-react' |
| 5 | +import reactHooks from 'eslint-plugin-react-hooks' |
| 6 | +import testingLibrary from 'eslint-plugin-testing-library' |
| 7 | +import jest from 'eslint-plugin-jest' |
| 8 | +import globals from 'globals' |
| 9 | + |
| 10 | +export default [ |
| 11 | + 'eslint:recommended', |
| 12 | + // Ignored dirs |
| 13 | + { |
| 14 | + ignores: ['dist/**/*', 'compiled/**/*', 'bundle/**/*'] |
| 15 | + }, |
| 16 | + // Temporary ignored dirs |
| 17 | + // TODO: remove signers on rewrite |
| 18 | + // TODO: remove e2e on rewrite |
| 19 | + { |
| 20 | + ignores: ['test/e2e/**/*', 'main/signers/**/*'] |
| 21 | + }, |
| 22 | + // All files |
| 23 | + { |
| 24 | + files: ['**/*.{js,mjs,ts,tsx}'], |
| 25 | + languageOptions: { |
| 26 | + ecmaVersion: 'latest', |
| 27 | + globals: { |
| 28 | + ...globals.es2021 |
| 29 | + } |
| 30 | + }, |
| 31 | + rules: { |
| 32 | + 'no-unused-vars': [ |
| 33 | + 'error', |
| 34 | + { |
| 35 | + args: 'after-used', |
| 36 | + ignoreRestSiblings: true, |
| 37 | + argsIgnorePattern: '^_', |
| 38 | + destructuredArrayIgnorePattern: '^_' |
| 39 | + } |
| 40 | + ] |
| 41 | + } |
| 42 | + }, |
| 43 | + // Main process files and scripts |
| 44 | + { |
| 45 | + files: [ |
| 46 | + '*.{js,mjs,ts}', |
| 47 | + 'scripts/**/*.mjs', |
| 48 | + 'main/**/*.{js,ts}', |
| 49 | + 'build/**/*.js', |
| 50 | + 'resources/**/*.{js,ts}', |
| 51 | + 'test/*.js', |
| 52 | + 'test/__mocks__/*.js', |
| 53 | + 'test/main/**/*.{js,ts}' |
| 54 | + ], |
| 55 | + ignores: ['resources/Components/**/*', 'resources/Hooks/**/*', 'resources/Native/**/*'], |
| 56 | + languageOptions: { |
| 57 | + globals: { |
| 58 | + ...globals.node |
| 59 | + } |
| 60 | + } |
| 61 | + }, |
| 62 | + // Renderer process files |
| 63 | + { |
| 64 | + files: [ |
| 65 | + 'app/**/*.js', |
| 66 | + 'main/dapps/server/inject/*.js', |
| 67 | + 'resources/app/**/*.js', |
| 68 | + 'resources/Components/**/*.js', |
| 69 | + 'resources/Hooks/**/*.js', |
| 70 | + 'resources/Native/**/*.js', |
| 71 | + 'resources/bridge/index.js', |
| 72 | + 'resources/link/index.js', |
| 73 | + 'test/app/**/*.js', |
| 74 | + 'test/resources/Components/**/*.js', |
| 75 | + 'test/resources/Hooks/**/*.js', |
| 76 | + 'test/resources/Native/**/*.js' |
| 77 | + ], |
| 78 | + languageOptions: { |
| 79 | + globals: { |
| 80 | + ...globals.browser, |
| 81 | + global: true |
| 82 | + } |
| 83 | + } |
| 84 | + }, |
| 85 | + // Renderer entry points |
| 86 | + { |
| 87 | + files: ['app/*/index.js'], |
| 88 | + languageOptions: { |
| 89 | + globals: { |
| 90 | + process: true |
| 91 | + } |
| 92 | + } |
| 93 | + }, |
| 94 | + // TS files |
| 95 | + { |
| 96 | + files: ['**/*.{ts,tsx}'], |
| 97 | + languageOptions: { |
| 98 | + parser: tsParser, |
| 99 | + parserOptions: { |
| 100 | + ecmaFeatures: { modules: true }, |
| 101 | + ecmaVersion: 'latest', |
| 102 | + project: './tsconfig.json' |
| 103 | + } |
| 104 | + }, |
| 105 | + plugins: { |
| 106 | + '@typescript-eslint': ts |
| 107 | + }, |
| 108 | + rules: { |
| 109 | + ...ts.configs['eslint-recommended'].rules, |
| 110 | + ...ts.configs.recommended.rules, |
| 111 | + 'no-undef': 'off', // redundant - TS will fail to compile with undefined vars |
| 112 | + '@typescript-eslint/no-unused-vars': [ |
| 113 | + 'error', |
| 114 | + { |
| 115 | + args: 'after-used', |
| 116 | + ignoreRestSiblings: true, |
| 117 | + argsIgnorePattern: '^_', |
| 118 | + destructuredArrayIgnorePattern: '^_' |
| 119 | + } |
| 120 | + ], |
| 121 | + '@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions'] }], // allow noop arrow functions, e.g. in a method signature for ensuring a parameter defaults to a function |
| 122 | + '@typescript-eslint/prefer-namespace-keyword': 'off', // use ES module syntax instead of namespace |
| 123 | + '@typescript-eslint/no-namespace': ['error', { allowDeclarations: true }] |
| 124 | + } |
| 125 | + }, |
| 126 | + // React / JSX files |
| 127 | + // TODO: simplify as '**/*.{jsx,tsx}' |
| 128 | + { |
| 129 | + files: [ |
| 130 | + 'app/**/*.js', |
| 131 | + 'resources/Components/**/*.js', |
| 132 | + 'resources/Hooks/**/*.js', |
| 133 | + 'resources/Native/**/*.js', |
| 134 | + 'resources/svg/index.js', |
| 135 | + 'test/app/**/*.js', |
| 136 | + 'test/resources/Components/**/*.js', |
| 137 | + 'test/resources/Hooks/**/*.js', |
| 138 | + 'test/resources/Native/**/*.js', |
| 139 | + 'test/jest.svg.js' |
| 140 | + ], |
| 141 | + plugins: { |
| 142 | + react, |
| 143 | + 'react-hooks': reactHooks |
| 144 | + }, |
| 145 | + languageOptions: { |
| 146 | + parserOptions: { |
| 147 | + ecmaFeatures: { |
| 148 | + jsx: true |
| 149 | + } |
| 150 | + } |
| 151 | + }, |
| 152 | + settings: { |
| 153 | + react: { |
| 154 | + version: 'detect' |
| 155 | + } |
| 156 | + }, |
| 157 | + rules: { |
| 158 | + ...react.configs.recommended.rules, |
| 159 | + ...react.configs['jsx-runtime'].rules, |
| 160 | + ...reactHooks.configs.recommended.rules, |
| 161 | + 'react/prop-types': 'off' // all type checking to be done in TS |
| 162 | + } |
| 163 | + }, |
| 164 | + // Test files |
| 165 | + { |
| 166 | + files: ['test/**/*.js', '**/__mocks__/**/*.js'], |
| 167 | + plugins: { |
| 168 | + jest |
| 169 | + }, |
| 170 | + languageOptions: { |
| 171 | + globals: { |
| 172 | + ...globals.jest |
| 173 | + } |
| 174 | + } |
| 175 | + // TODO: enable jest rules |
| 176 | + // rules: { |
| 177 | + // ...jest.configs.recommended.rules |
| 178 | + // } |
| 179 | + }, |
| 180 | + // Components test files |
| 181 | + { |
| 182 | + files: ['test/app/**/*.js', 'test/resources/Components/**/*.js', 'app/**/__mocks__/**/*.js'], |
| 183 | + plugins: { |
| 184 | + 'testing-library': testingLibrary |
| 185 | + }, |
| 186 | + rules: { |
| 187 | + ...testingLibrary.configs.react.rules |
| 188 | + } |
| 189 | + }, |
| 190 | + // ensure all rules work with prettier |
| 191 | + prettier |
| 192 | +] |
0 commit comments