|
| 1 | +import eslint from '@eslint/js' |
| 2 | +import tseslint from 'typescript-eslint' |
| 3 | + |
| 4 | +import nodePlugin from 'eslint-plugin-n' |
| 5 | +import sortImports from 'eslint-plugin-sort-imports-es6-autofix' |
| 6 | +import unusedImports from 'eslint-plugin-unused-imports' |
| 7 | + |
| 8 | +export default tseslint.config( |
| 9 | + eslint.configs.recommended, |
| 10 | + ...tseslint.configs.recommended, |
| 11 | + ...tseslint.configs.recommendedTypeChecked, |
| 12 | + nodePlugin.configs["flat/recommended-script"], |
| 13 | + { |
| 14 | + languageOptions: { |
| 15 | + parserOptions: { |
| 16 | + // Explicitly require all modules being linted to have tsconfig.eslint.json |
| 17 | + project: ['./tsconfig.eslint.json'], |
| 18 | + tsconfigRootDir: import.meta.dirname, |
| 19 | + }, |
| 20 | + }, |
| 21 | + plugins: { |
| 22 | + unusedImports, |
| 23 | + sortImports, |
| 24 | + }, |
| 25 | + rules: { |
| 26 | + // Explicit offs |
| 27 | + '@typescript-eslint/no-misused-promises': 'off', |
| 28 | + '@typescript-eslint/no-unsafe-enum-comparison': 'off', |
| 29 | + '@typescript-eslint/require-await': 'off', |
| 30 | + '@typescript-eslint/restrict-template-expressions': 'off', |
| 31 | + '@typescript-eslint/no-base-to-string': 'off', |
| 32 | + 'avoidEscape': 'off', |
| 33 | + 'camelcase': 'off', |
| 34 | + 'no-async-promise-executor': 'off', |
| 35 | + 'no-unreachable-loop': 'off', |
| 36 | + 'no-unused-vars': 'off', |
| 37 | + 'no-constant-condition': 'off', |
| 38 | + |
| 39 | + // Explicit warns |
| 40 | + 'unusedImports/no-unused-imports': 'warn', |
| 41 | + 'sortImports/sort-imports-es6': [1, { |
| 42 | + ignoreCase: false, |
| 43 | + ignoreMemberSort: false, |
| 44 | + memberSyntaxSortOrder: ['none', 'single', 'multiple', 'all'] |
| 45 | + }], |
| 46 | + |
| 47 | + // Explicit errors |
| 48 | + 'array-callback-return': 'error', |
| 49 | + 'block-scoped-var': 'error', |
| 50 | + 'dot-notation': 'error', |
| 51 | + 'new-cap': [2, { 'properties': false }], // Used by ethers event filters |
| 52 | + 'no-empty': [2, { 'allowEmptyCatch': true }], |
| 53 | + 'no-new': 'error', |
| 54 | + 'prefer-const': [2, { 'destructuring': 'all' }], |
| 55 | + 'n/no-new-require': 'error', |
| 56 | + 'n/no-path-concat': 'error', |
| 57 | + // Note: for @typescript-eslint/return-await', you must disable the base rule as it can report incorrect errors |
| 58 | + 'no-return-await': 'off', |
| 59 | + '@typescript-eslint/return-await': 'error', |
| 60 | + |
| 61 | + // Custom - These allow `any`. Remove over time as codebase is cleaned up |
| 62 | + '@typescript-eslint/no-explicit-any': 'off', |
| 63 | + '@typescript-eslint/no-unsafe-assignment': 'off', |
| 64 | + '@typescript-eslint/no-unsafe-argument': 'off', |
| 65 | + '@typescript-eslint/no-unsafe-call': 'off', |
| 66 | + '@typescript-eslint/no-unsafe-member-access': 'off', |
| 67 | + '@typescript-eslint/no-unsafe-return': 'off', |
| 68 | + '@typescript-eslint/no-redundant-type-constituents': 'off', |
| 69 | + |
| 70 | + // Custom - Set to 1 or 2 over time as codebase is cleaned up. Possibly add options |
| 71 | + '@typescript-eslint/prefer-nullish-coalescing': 'off', |
| 72 | + '@typescript-eslint/no-unnecessary-type-assertion': 'off', |
| 73 | + '@typescript-eslint/no-unused-vars': 'off', |
| 74 | + '@typescript-eslint/no-floating-promises': 'off', |
| 75 | + // Could be a 1 but --fix does not correctly indent |
| 76 | + 'no-else-return': 'off', |
| 77 | + // Could be a 1 but erroneously fixes nested items. Nesting is user error but still not worth the hassle |
| 78 | + // https://github.com/eslint/eslint/issues/3400 |
| 79 | + 'no-lonely-if': 'off', |
| 80 | + // Nice to have but need to clean up first |
| 81 | + '@typescript-eslint/no-unnecessary-condition': 0, |
| 82 | + // Remove when ethers v6 is used and we do not import entire ethers paths |
| 83 | + // Remove when asn1.js is updated to modern package |
| 84 | + 'n/no-missing-import': [2, { 'allowModules': [ 'ethers', 'asn1.js' ] }], |
| 85 | + // Remove when ethers v6 is used and we do not import entire ethers paths |
| 86 | + // Remove when plugin supports workspaces |
| 87 | + // https://github.com/eslint-community/eslint-plugin-n/issues/209 |
| 88 | + 'n/no-extraneous-import': [2, { |
| 89 | + 'allowModules': [ |
| 90 | + '@ethersproject/abstract', |
| 91 | + '@ethersproject/abstract-provider', |
| 92 | + '@ethersproject/bignumber', |
| 93 | + '@ethersproject/networks', |
| 94 | + '@ethersproject/properties', |
| 95 | + '@ethersproject/web', |
| 96 | + 'typescript-eslint' |
| 97 | + ] |
| 98 | + }], |
| 99 | + // Remove when we have more graceful shutdown logic |
| 100 | + 'n/no-process-exit': 0, |
| 101 | + }, |
| 102 | + ignores: [ |
| 103 | + 'node_modules', |
| 104 | + 'build', |
| 105 | + 'dist' |
| 106 | + ] |
| 107 | + } |
| 108 | +) |
0 commit comments