|
| 1 | +const babelParser = require('@babel/eslint-parser'); |
| 2 | +const { fixupPluginRules } = require('@eslint/compat'); |
| 3 | +const { FlatCompat } = require('@eslint/eslintrc'); |
| 4 | +const js = require('@eslint/js'); |
| 5 | +const _import = require('eslint-plugin-import'); |
| 6 | +const jest = require('eslint-plugin-jest'); |
| 7 | +const jsdoc = require('eslint-plugin-jsdoc'); |
| 8 | +const promise = require('eslint-plugin-promise'); |
| 9 | +const security = require('eslint-plugin-security'); |
| 10 | +const globals = require('globals'); |
| 11 | + |
| 12 | +const compat = new FlatCompat({ |
| 13 | + baseDirectory: __dirname, |
| 14 | + recommendedConfig: js.configs.recommended, |
| 15 | + allConfig: js.configs.all, |
| 16 | +}); |
| 17 | + |
| 18 | +module.exports = [ |
| 19 | + { |
| 20 | + ignores: ['**/dist/'], |
| 21 | + }, |
| 22 | + ...compat.extends('eslint:recommended', 'prettier', 'plugin:prettier/recommended'), |
| 23 | + { |
| 24 | + plugins: { |
| 25 | + jsdoc, |
| 26 | + jest, |
| 27 | + promise, |
| 28 | + security, |
| 29 | + import: fixupPluginRules(_import), |
| 30 | + }, |
| 31 | + |
| 32 | + languageOptions: { |
| 33 | + globals: { |
| 34 | + ...globals.node, |
| 35 | + }, |
| 36 | + |
| 37 | + parser: babelParser, |
| 38 | + ecmaVersion: 5, |
| 39 | + sourceType: 'commonjs', |
| 40 | + |
| 41 | + parserOptions: { |
| 42 | + requireConfigFile: false, |
| 43 | + sourceType: 'script', |
| 44 | + }, |
| 45 | + }, |
| 46 | + |
| 47 | + settings: { |
| 48 | + 'import/resolver': { |
| 49 | + node: { |
| 50 | + extensions: ['.js', '.ts'], |
| 51 | + }, |
| 52 | + }, |
| 53 | + |
| 54 | + jsdoc: { |
| 55 | + preferredTypes: { |
| 56 | + Array: 'Array<object>', |
| 57 | + 'Array.': 'Array<object>', |
| 58 | + 'Array<>': '[]', |
| 59 | + 'Array.<>': '[]', |
| 60 | + 'Promise.<>': 'Promise<>', |
| 61 | + }, |
| 62 | + }, |
| 63 | + }, |
| 64 | + |
| 65 | + rules: { |
| 66 | + 'prettier/prettier': [ |
| 67 | + 'error', |
| 68 | + {}, |
| 69 | + { |
| 70 | + usePrettierrc: true, |
| 71 | + }, |
| 72 | + ], |
| 73 | + |
| 74 | + curly: ['error', 'all'], |
| 75 | + 'callback-return': ['error', ['callback', 'cb', 'next', 'done']], |
| 76 | + 'class-methods-use-this': 'off', |
| 77 | + 'consistent-return': 'off', |
| 78 | + 'handle-callback-err': ['error', '^.*err'], |
| 79 | + 'new-cap': 'off', |
| 80 | + 'no-console': 'error', |
| 81 | + 'no-else-return': 'error', |
| 82 | + 'no-eq-null': 'off', |
| 83 | + 'no-global-assign': 'error', |
| 84 | + 'no-loop-func': 'off', |
| 85 | + 'no-lone-blocks': 'error', |
| 86 | + 'no-negated-condition': 'error', |
| 87 | + 'no-shadow': 'error', |
| 88 | + 'no-template-curly-in-string': 'error', |
| 89 | + 'no-undef': 'error', |
| 90 | + 'no-underscore-dangle': 'off', |
| 91 | + 'no-unsafe-negation': 'error', |
| 92 | + 'no-use-before-define': ['error', 'nofunc'], |
| 93 | + 'no-useless-rename': 'error', |
| 94 | + |
| 95 | + 'padding-line-between-statements': [ |
| 96 | + 'error', |
| 97 | + { |
| 98 | + blankLine: 'always', |
| 99 | + |
| 100 | + prev: ['directive', 'block', 'block-like', 'multiline-block-like', 'cjs-export', 'cjs-import', 'class', 'export', 'import', 'if'], |
| 101 | + |
| 102 | + next: '*', |
| 103 | + }, |
| 104 | + { |
| 105 | + blankLine: 'never', |
| 106 | + prev: 'directive', |
| 107 | + next: 'directive', |
| 108 | + }, |
| 109 | + { |
| 110 | + blankLine: 'any', |
| 111 | + prev: '*', |
| 112 | + next: ['if', 'for', 'cjs-import', 'import'], |
| 113 | + }, |
| 114 | + { |
| 115 | + blankLine: 'any', |
| 116 | + prev: ['export', 'import'], |
| 117 | + next: ['export', 'import'], |
| 118 | + }, |
| 119 | + { |
| 120 | + blankLine: 'always', |
| 121 | + prev: '*', |
| 122 | + next: ['try', 'function', 'switch'], |
| 123 | + }, |
| 124 | + { |
| 125 | + blankLine: 'always', |
| 126 | + prev: 'if', |
| 127 | + next: 'if', |
| 128 | + }, |
| 129 | + { |
| 130 | + blankLine: 'never', |
| 131 | + prev: ['return', 'throw'], |
| 132 | + next: '*', |
| 133 | + }, |
| 134 | + ], |
| 135 | + |
| 136 | + 'no-new': 'off', |
| 137 | + 'no-empty': 'error', |
| 138 | + 'no-empty-function': 'error', |
| 139 | + 'valid-jsdoc': 'off', |
| 140 | + yoda: 'error', |
| 141 | + 'import/extensions': ['error', 'never'], |
| 142 | + 'import/no-unresolved': 'off', |
| 143 | + |
| 144 | + 'import/order': [ |
| 145 | + 'error', |
| 146 | + { |
| 147 | + 'newlines-between': 'always', |
| 148 | + |
| 149 | + alphabetize: { |
| 150 | + order: 'asc', |
| 151 | + caseInsensitive: true, |
| 152 | + }, |
| 153 | + }, |
| 154 | + ], |
| 155 | + |
| 156 | + 'jsdoc/check-alignment': 'error', |
| 157 | + 'jsdoc/check-indentation': 'off', |
| 158 | + 'jsdoc/check-param-names': 'off', |
| 159 | + 'jsdoc/check-tag-names': 'error', |
| 160 | + 'jsdoc/check-types': 'error', |
| 161 | + 'jsdoc/newline-after-description': 'off', |
| 162 | + 'jsdoc/no-undefined-types': 'off', |
| 163 | + 'jsdoc/require-description': 'off', |
| 164 | + 'jsdoc/require-description-complete-sentence': 'off', |
| 165 | + 'jsdoc/require-example': 'off', |
| 166 | + 'jsdoc/require-hyphen-before-param-description': 'error', |
| 167 | + 'jsdoc/require-param': 'error', |
| 168 | + 'jsdoc/require-param-description': 'off', |
| 169 | + 'jsdoc/require-param-name': 'error', |
| 170 | + 'jsdoc/require-param-type': 'error', |
| 171 | + 'jsdoc/require-returns-description': 'off', |
| 172 | + 'jsdoc/require-returns-type': 'error', |
| 173 | + 'jsdoc/valid-types': 'error', |
| 174 | + 'promise/always-return': 'error', |
| 175 | + 'promise/always-catch': 'off', |
| 176 | + |
| 177 | + 'promise/catch-or-return': [ |
| 178 | + 'error', |
| 179 | + { |
| 180 | + allowThen: true, |
| 181 | + }, |
| 182 | + ], |
| 183 | + |
| 184 | + 'promise/no-native': 'off', |
| 185 | + 'promise/param-names': 'error', |
| 186 | + 'security/detect-buffer-noassert': 'error', |
| 187 | + 'security/detect-child-process': 'error', |
| 188 | + 'security/detect-disable-mustache-escape': 'error', |
| 189 | + 'security/detect-eval-with-expression': 'error', |
| 190 | + 'security/detect-new-buffer': 'error', |
| 191 | + 'security/detect-no-csrf-before-method-override': 'error', |
| 192 | + 'security/detect-non-literal-fs-filename': 'error', |
| 193 | + 'security/detect-non-literal-regexp': 'error', |
| 194 | + 'security/detect-non-literal-require': 'off', |
| 195 | + 'security/detect-object-injection': 'off', |
| 196 | + 'security/detect-possible-timing-attacks': 'error', |
| 197 | + 'security/detect-pseudoRandomBytes': 'error', |
| 198 | + 'security/detect-unsafe-regex': 'error', |
| 199 | + strict: 'off', |
| 200 | + }, |
| 201 | + }, |
| 202 | + { |
| 203 | + files: ['**/*.test.js'], |
| 204 | + |
| 205 | + languageOptions: { |
| 206 | + globals: { |
| 207 | + ...jest.environments.globals.globals, |
| 208 | + }, |
| 209 | + }, |
| 210 | + }, |
| 211 | +]; |
0 commit comments