|
| 1 | +// #region shared with https://github.com/paranext/paranext-multi-extension-template/blob/main/.eslintrc.cjs |
| 2 | + |
| 3 | +module.exports = { |
| 4 | + extends: [ |
| 5 | + // https://github.com/electron-react-boilerplate/eslint-config-erb/blob/main/index.js |
| 6 | + // airbnb rules are embedded in erb https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb |
| 7 | + 'erb', |
| 8 | + // https://github.com/import-js/eslint-plugin-import?tab=readme-ov-file#typescript |
| 9 | + 'plugin:import/recommended', |
| 10 | + 'plugin:import/typescript', |
| 11 | + // Make sure this is last so it gets the chance to override other configs. |
| 12 | + // See https://github.com/prettier/eslint-config-prettier and https://github.com/prettier/eslint-plugin-prettier |
| 13 | + 'plugin:prettier/recommended', |
| 14 | + ], |
| 15 | + |
| 16 | + rules: { |
| 17 | + // Some rules in this following shared region are not applied since they are overridden in subsequent regions |
| 18 | + // #region shared with https://github.com/paranext/paranext-core/blob/main/.eslintrc.js |
| 19 | + |
| 20 | + // #region ERB rules |
| 21 | + |
| 22 | + // Use `noImplicitReturns` instead. See https://typescript-eslint.io/rules/consistent-return/. |
| 23 | + 'consistent-return': 'off', |
| 24 | + 'import/default': 'off', |
| 25 | + 'import/extensions': 'off', |
| 26 | + // A temporary hack related to IDE not resolving correct package.json |
| 27 | + 'import/no-extraneous-dependencies': 'off', |
| 28 | + 'import/no-import-module-exports': 'off', |
| 29 | + 'import/no-unresolved': 'error', |
| 30 | + 'import/prefer-default-export': 'off', |
| 31 | + 'react/jsx-filename-extension': 'off', |
| 32 | + 'react/react-in-jsx-scope': 'off', |
| 33 | + |
| 34 | + // #endregion |
| 35 | + |
| 36 | + // #region Platform.Bible rules |
| 37 | + |
| 38 | + // Rules in each section are generally in alphabetical order. However, several |
| 39 | + // `@typescript-eslint` rules require disabling the equivalent ESLint rule. So in these cases |
| 40 | + // each ESLint rule is turned off immediately above the corresponding `@typescript-eslint` rule. |
| 41 | + 'class-methods-use-this': 'off', |
| 42 | + '@typescript-eslint/class-methods-use-this': [ |
| 43 | + 'error', |
| 44 | + { ignoreOverrideMethods: true, ignoreClassesThatImplementAnInterface: false }, |
| 45 | + ], |
| 46 | + '@typescript-eslint/explicit-member-accessibility': ['error', { accessibility: 'no-public' }], |
| 47 | + 'lines-between-class-members': 'off', |
| 48 | + '@typescript-eslint/lines-between-class-members': [ |
| 49 | + 'error', |
| 50 | + 'always', |
| 51 | + { exceptAfterSingleLine: true, exceptAfterOverload: true }, |
| 52 | + ], |
| 53 | + '@typescript-eslint/member-ordering': 'error', |
| 54 | + 'no-empty-function': 'off', |
| 55 | + '@typescript-eslint/no-empty-function': [ |
| 56 | + 'error', |
| 57 | + { |
| 58 | + allow: ['arrowFunctions', 'functions', 'methods'], |
| 59 | + }, |
| 60 | + ], |
| 61 | + '@typescript-eslint/no-explicit-any': 'error', |
| 62 | + 'no-redeclare': 'off', |
| 63 | + '@typescript-eslint/no-redeclare': 'error', |
| 64 | + 'no-restricted-imports': [ |
| 65 | + 'error', |
| 66 | + { |
| 67 | + patterns: [ |
| 68 | + { |
| 69 | + group: ['shared/*', 'renderer/*', 'extension-host/*', 'node/*', 'client/*', 'main/*'], |
| 70 | + message: `Importing from this path is not allowed. Try importing from @papi/core. Imports from paths like 'shared', 'renderer', 'node', 'client' and 'main' are not allowed to prevent unnecessary import break.`, |
| 71 | + }, |
| 72 | + ], |
| 73 | + }, |
| 74 | + ], |
| 75 | + 'no-shadow': 'off', |
| 76 | + '@typescript-eslint/no-shadow': 'error', |
| 77 | + 'no-use-before-define': 'off', |
| 78 | + '@typescript-eslint/no-use-before-define': [ |
| 79 | + 'error', |
| 80 | + { functions: false, allowNamedExports: true, typedefs: false, ignoreTypeReferences: true }, |
| 81 | + ], |
| 82 | + '@typescript-eslint/no-unnecessary-type-assertion': 'error', |
| 83 | + 'no-unused-vars': 'off', |
| 84 | + '@typescript-eslint/no-unused-vars': 'error', |
| 85 | + 'no-useless-constructor': 'off', |
| 86 | + '@typescript-eslint/no-useless-constructor': 'error', |
| 87 | + 'comma-dangle': ['error', 'always-multiline'], |
| 88 | + 'import/no-anonymous-default-export': ['error', { allowCallExpression: false }], |
| 89 | + indent: 'off', |
| 90 | + 'jsx-a11y/label-has-associated-control': [ |
| 91 | + 'error', |
| 92 | + { |
| 93 | + assert: 'either', |
| 94 | + }, |
| 95 | + ], |
| 96 | + // Should use our logger anytime you want logs that persist. Otherwise use console only in testing |
| 97 | + 'no-console': 'warn', |
| 98 | + 'no-null/no-null': 2, |
| 99 | + 'no-plusplus': ['error', { allowForLoopAfterthoughts: true }], |
| 100 | + 'no-type-assertion/no-type-assertion': 'error', |
| 101 | + 'prettier/prettier': ['warn', { tabWidth: 2, trailingComma: 'all' }], |
| 102 | + 'react/jsx-indent-props': ['warn', 2], |
| 103 | + 'react/jsx-props-no-spreading': ['error', { custom: 'ignore' }], |
| 104 | + 'react/require-default-props': 'off', |
| 105 | + |
| 106 | + // #endregion |
| 107 | + |
| 108 | + // #endregion |
| 109 | + |
| 110 | + // #region Overrides to rules from paranext-core |
| 111 | + |
| 112 | + 'import/no-unresolved': ['error', { ignore: ['@papi'] }], |
| 113 | + |
| 114 | + // #endregion |
| 115 | + }, |
| 116 | + globals: { |
| 117 | + globalThis: 'readonly', |
| 118 | + }, |
| 119 | + overrides: [ |
| 120 | + { |
| 121 | + files: ['*.ts', '*.tsx'], |
| 122 | + rules: { |
| 123 | + // #region shared with https://github.com/paranext/paranext-core/blob/main/.eslintrc.js |
| 124 | + |
| 125 | + // These are already handled by TypeScript |
| 126 | + 'no-dupe-class-members': 'off', |
| 127 | + |
| 128 | + // #endregion |
| 129 | + }, |
| 130 | + }, |
| 131 | + { |
| 132 | + // Allow this file to have overrides to rules from paranext-core |
| 133 | + files: ['.eslintrc.*js'], |
| 134 | + rules: { |
| 135 | + 'no-dupe-keys': 'off', |
| 136 | + }, |
| 137 | + }, |
| 138 | + { |
| 139 | + files: ['*.js'], |
| 140 | + rules: { |
| 141 | + strict: 'off', |
| 142 | + }, |
| 143 | + }, |
| 144 | + { |
| 145 | + files: ['./lib/*', './webpack/*'], |
| 146 | + rules: { |
| 147 | + // These files are scripts not running in Platform.Bible, so they can't use the logger |
| 148 | + 'no-console': 'off', |
| 149 | + }, |
| 150 | + }, |
| 151 | + { |
| 152 | + files: ['*.d.ts'], |
| 153 | + rules: { |
| 154 | + // Allow .d.ts files to self import so they can refer to their types in `papi-shared-types` |
| 155 | + 'import/no-self-import': 'off', |
| 156 | + }, |
| 157 | + }, |
| 158 | + ], |
| 159 | + parserOptions: { |
| 160 | + ecmaVersion: 2022, |
| 161 | + sourceType: 'module', |
| 162 | + project: './tsconfig.lint.json', |
| 163 | + tsconfigRootDir: __dirname, |
| 164 | + createDefaultProgram: true, |
| 165 | + }, |
| 166 | + plugins: ['@typescript-eslint', 'no-type-assertion', 'no-null'], |
| 167 | + settings: { |
| 168 | + 'import/resolver': { |
| 169 | + typescript: { |
| 170 | + alwaysTryTypes: true, |
| 171 | + }, |
| 172 | + }, |
| 173 | + 'import/parsers': { |
| 174 | + '@typescript-eslint/parser': ['.ts', '.tsx'], |
| 175 | + }, |
| 176 | + }, |
| 177 | +}; |
| 178 | + |
| 179 | +// #endregion |
0 commit comments