|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const pluginEslintCommentsConfigs = require('@eslint-community/eslint-plugin-eslint-comments/configs'); |
| 4 | +const pluginTypeScriptESLint = require('@typescript-eslint/eslint-plugin'); |
| 5 | +const parserTypeScriptESLint = require('@typescript-eslint/parser'); |
| 6 | +const pluginESLintPlugin = require('eslint-plugin-eslint-plugin'); |
| 7 | +const pluginImport = require('eslint-plugin-import'); |
| 8 | +const pluginN = require('eslint-plugin-n'); |
| 9 | +const pluginPrettier = require('eslint-plugin-prettier'); |
| 10 | +const pluginPrettierRecommended = require('eslint-plugin-prettier/recommended'); |
| 11 | +const globals = require('./src/globals.json'); |
| 12 | + |
| 13 | +/** @type {import('eslint').Linter.FlatConfig[]} */ |
| 14 | +const config = [ |
| 15 | + { files: ['**/*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}'] }, |
| 16 | + { ignores: ['.yarn', 'coverage/', 'lib/', 'src/rules/__tests__/fixtures'] }, |
| 17 | + { |
| 18 | + plugins: { |
| 19 | + // @ts-expect-error types are currently not considered compatible currently |
| 20 | + // todo: suspect this is because of differences in ESLint (types) versions |
| 21 | + '@typescript-eslint': pluginTypeScriptESLint, |
| 22 | + ...pluginEslintCommentsConfigs.recommended.plugins, |
| 23 | + import: pluginImport, |
| 24 | + 'eslint-plugin': pluginESLintPlugin, |
| 25 | + n: pluginN, |
| 26 | + prettier: pluginPrettier, |
| 27 | + }, |
| 28 | + languageOptions: { parser: parserTypeScriptESLint }, |
| 29 | + linterOptions: { |
| 30 | + reportUnusedDisableDirectives: 'error', |
| 31 | + }, |
| 32 | + rules: { |
| 33 | + ...pluginESLintPlugin.configs['flat/recommended'].rules, |
| 34 | + ...pluginEslintCommentsConfigs.recommended.rules, |
| 35 | + ...pluginPrettierRecommended.rules, |
| 36 | + }, |
| 37 | + }, |
| 38 | + { |
| 39 | + rules: { |
| 40 | + '@typescript-eslint/array-type': ['error', { default: 'array-simple' }], |
| 41 | + '@typescript-eslint/no-require-imports': 'error', |
| 42 | + '@typescript-eslint/ban-ts-comment': 'error', |
| 43 | + '@typescript-eslint/no-empty-object-type': 'error', |
| 44 | + '@typescript-eslint/no-unsafe-function-type': 'error', |
| 45 | + '@typescript-eslint/no-wrapper-object-types': 'error', |
| 46 | + '@typescript-eslint/consistent-type-imports': [ |
| 47 | + 'error', |
| 48 | + { disallowTypeAnnotations: false, fixStyle: 'inline-type-imports' }, |
| 49 | + ], |
| 50 | + '@typescript-eslint/no-import-type-side-effects': 'error', |
| 51 | + '@typescript-eslint/no-unused-vars': 'error', |
| 52 | + '@eslint-community/eslint-comments/no-unused-disable': 'error', |
| 53 | + 'eslint-plugin/require-meta-docs-description': [ |
| 54 | + 'error', |
| 55 | + { pattern: '^(Enforce|Require|Disallow|Suggest|Prefer)' }, |
| 56 | + ], |
| 57 | + 'eslint-plugin/test-case-property-ordering': 'error', |
| 58 | + 'no-else-return': 'error', |
| 59 | + 'no-negated-condition': 'error', |
| 60 | + eqeqeq: ['error', 'smart'], |
| 61 | + strict: 'error', |
| 62 | + 'prefer-template': 'error', |
| 63 | + 'object-shorthand': [ |
| 64 | + 'error', |
| 65 | + 'always', |
| 66 | + { avoidExplicitReturnArrows: true }, |
| 67 | + ], |
| 68 | + 'prefer-destructuring': [ |
| 69 | + 'error', |
| 70 | + { VariableDeclarator: { array: true, object: true } }, |
| 71 | + ], |
| 72 | + 'sort-imports': ['error', { ignoreDeclarationSort: true }], |
| 73 | + 'require-unicode-regexp': 'error', |
| 74 | + // TS covers these 2 |
| 75 | + 'n/no-missing-import': 'off', |
| 76 | + 'n/no-missing-require': 'off', |
| 77 | + 'n/no-unsupported-features/es-syntax': 'off', |
| 78 | + 'n/no-unsupported-features/es-builtins': 'error', |
| 79 | + 'import/no-commonjs': 'error', |
| 80 | + 'import/no-duplicates': 'error', |
| 81 | + 'import/no-extraneous-dependencies': 'error', |
| 82 | + 'import/no-unused-modules': 'error', |
| 83 | + 'import/order': [ |
| 84 | + 'error', |
| 85 | + { alphabetize: { order: 'asc' }, 'newlines-between': 'never' }, |
| 86 | + ], |
| 87 | + 'padding-line-between-statements': [ |
| 88 | + 'error', |
| 89 | + { blankLine: 'always', prev: '*', next: 'return' }, |
| 90 | + { blankLine: 'always', prev: ['const', 'let', 'var'], next: '*' }, |
| 91 | + { |
| 92 | + blankLine: 'any', |
| 93 | + prev: ['const', 'let', 'var'], |
| 94 | + next: ['const', 'let', 'var'], |
| 95 | + }, |
| 96 | + { blankLine: 'always', prev: 'directive', next: '*' }, |
| 97 | + { blankLine: 'any', prev: 'directive', next: 'directive' }, |
| 98 | + ], |
| 99 | + |
| 100 | + 'prefer-spread': 'error', |
| 101 | + 'prefer-rest-params': 'error', |
| 102 | + 'prefer-const': ['error', { destructuring: 'all' }], |
| 103 | + 'no-var': 'error', |
| 104 | + curly: 'error', |
| 105 | + }, |
| 106 | + }, |
| 107 | + { |
| 108 | + files: ['*.js'], |
| 109 | + rules: { |
| 110 | + '@typescript-eslint/no-require-imports': 'off', |
| 111 | + }, |
| 112 | + }, |
| 113 | + { |
| 114 | + files: ['*.test.js', '*.test.ts'], |
| 115 | + languageOptions: { globals }, |
| 116 | + }, |
| 117 | + { |
| 118 | + files: [ |
| 119 | + '.eslint-doc-generatorrc.js', |
| 120 | + 'eslint.config.js', |
| 121 | + 'babel.config.js', |
| 122 | + ], |
| 123 | + languageOptions: { |
| 124 | + sourceType: 'commonjs', |
| 125 | + }, |
| 126 | + rules: { |
| 127 | + '@typescript-eslint/no-require-imports': 'off', |
| 128 | + 'import/no-commonjs': 'off', |
| 129 | + }, |
| 130 | + }, |
| 131 | + { |
| 132 | + files: ['*.d.ts'], |
| 133 | + rules: { |
| 134 | + strict: 'off', |
| 135 | + }, |
| 136 | + }, |
| 137 | +]; |
| 138 | + |
| 139 | +module.exports = config; |
0 commit comments