|
| 1 | +import eslint from '@eslint/js'; |
| 2 | +import importPlugin from 'eslint-plugin-import'; |
| 3 | +import jsdoc from 'eslint-plugin-jsdoc'; |
| 4 | +import redosDetector from 'eslint-plugin-redos-detector'; |
| 5 | +import regexpPlugin from 'eslint-plugin-regexp'; |
| 6 | +import pluginSecurity from 'eslint-plugin-security'; |
| 7 | +import tseslint from 'typescript-eslint'; |
| 8 | + |
| 9 | +export default tseslint.config( |
| 10 | + eslint.configs.recommended, |
| 11 | + tseslint.configs.strict, |
| 12 | + tseslint.configs.stylistic, |
| 13 | + jsdoc.configs['flat/recommended'], |
| 14 | + pluginSecurity.configs.recommended, |
| 15 | + regexpPlugin.configs['flat/recommended'], |
| 16 | + { |
| 17 | + files: ['src/**/*.ts'], |
| 18 | + extends: [importPlugin.flatConfigs.recommended], |
| 19 | + plugins: { jsdoc, 'redos-detector': redosDetector }, |
| 20 | + rules: { |
| 21 | + // Enable rules ----------------------------------------------------------- |
| 22 | + |
| 23 | + // TypeScript |
| 24 | + '@typescript-eslint/consistent-type-definitions': 'error', // Enforce declaring types using `interface` keyword for better TS performance. |
| 25 | + '@typescript-eslint/consistent-type-imports': 'warn', |
| 26 | + |
| 27 | + // Import |
| 28 | + 'import/extensions': ['error', 'always'], // Require file extensions |
| 29 | + |
| 30 | + // JSDoc |
| 31 | + 'jsdoc/tag-lines': ['error', 'any', { startLines: 1 }], |
| 32 | + 'jsdoc/sort-tags': [ |
| 33 | + 'error', |
| 34 | + { |
| 35 | + linesBetween: 1, |
| 36 | + tagSequence: [ |
| 37 | + { tags: ['deprecated'] }, |
| 38 | + { tags: ['param'] }, |
| 39 | + { tags: ['returns'] }, |
| 40 | + ], |
| 41 | + }, |
| 42 | + ], |
| 43 | + // NOTE: For overloads functions, we only require a JSDoc at the top |
| 44 | + // SEE: https://github.com/gajus/eslint-plugin-jsdoc/issues/666 |
| 45 | + 'jsdoc/require-jsdoc': [ |
| 46 | + 'error', |
| 47 | + { |
| 48 | + contexts: [ |
| 49 | + 'ExportNamedDeclaration[declaration.type="TSDeclareFunction"]:not(ExportNamedDeclaration[declaration.type="TSDeclareFunction"] + ExportNamedDeclaration[declaration.type="TSDeclareFunction"])', |
| 50 | + 'ExportNamedDeclaration[declaration.type="FunctionDeclaration"]:not(ExportNamedDeclaration[declaration.type="TSDeclareFunction"] + ExportNamedDeclaration[declaration.type="FunctionDeclaration"])', |
| 51 | + ], |
| 52 | + require: { |
| 53 | + FunctionDeclaration: false, |
| 54 | + }, |
| 55 | + }, |
| 56 | + ], |
| 57 | + 'jsdoc/check-tag-names': [ |
| 58 | + 'error', |
| 59 | + { |
| 60 | + definedTags: ['alpha', 'beta', '__NO_SIDE_EFFECTS__'], |
| 61 | + }, |
| 62 | + ], |
| 63 | + |
| 64 | + // Regexp |
| 65 | + 'regexp/no-super-linear-move': 'error', // Prevent DoS regexps |
| 66 | + 'regexp/no-control-character': 'error', // Avoid unneeded regexps characters |
| 67 | + 'regexp/no-octal': 'error', // Avoid unneeded regexps characters |
| 68 | + 'regexp/no-standalone-backslash': 'error', // Avoid unneeded regexps characters |
| 69 | + 'regexp/prefer-escape-replacement-dollar-char': 'error', // Avoid unneeded regexps characters |
| 70 | + 'regexp/prefer-quantifier': 'error', // Avoid unneeded regexps characters |
| 71 | + 'regexp/hexadecimal-escape': ['error', 'always'], // Avoid unneeded regexps characters |
| 72 | + 'regexp/sort-alternatives': 'error', // Avoid unneeded regexps characters |
| 73 | + 'regexp/require-unicode-regexp': 'error', // /u flag is faster and enables regexp strict mode |
| 74 | + 'regexp/prefer-regexp-exec': 'error', // Enforce that RegExp#exec is used instead of String#match if no global flag is provided, as exec is faster |
| 75 | + |
| 76 | + // Redos detector |
| 77 | + 'redos-detector/no-unsafe-regex': ['error', { ignoreError: true }], // Prevent DoS regexps |
| 78 | + |
| 79 | + // Disable rules ---------------------------------------------------------- |
| 80 | + |
| 81 | + // TypeScript |
| 82 | + '@typescript-eslint/ban-ts-comment': 'off', |
| 83 | + '@typescript-eslint/no-non-null-assertion': 'off', |
| 84 | + '@typescript-eslint/consistent-indexed-object-style': 'off', |
| 85 | + '@typescript-eslint/no-inferrable-types': 'off', |
| 86 | + |
| 87 | + // Imports |
| 88 | + 'no-duplicate-imports': 'off', |
| 89 | + |
| 90 | + // JSDoc |
| 91 | + 'jsdoc/require-param-type': 'off', |
| 92 | + 'jsdoc/require-returns-type': 'off', |
| 93 | + |
| 94 | + // Security |
| 95 | + 'security/detect-object-injection': 'off', // Too many false positives |
| 96 | + 'security/detect-unsafe-regex': 'off', // Too many false positives, see https://github.com/eslint-community/eslint-plugin-security/issues/28 - we use the redos-detector plugin instead |
| 97 | + }, |
| 98 | + } |
| 99 | +); |
0 commit comments