|
| 1 | +const js = require('@eslint/js'); |
| 2 | +const tseslint = require('@typescript-eslint/eslint-plugin'); |
| 3 | +const tsparser = require('@typescript-eslint/parser'); |
| 4 | +const prettier = require('eslint-plugin-prettier'); |
| 5 | +const prettierConfig = require('eslint-config-prettier'); |
| 6 | + |
| 7 | +module.exports = [ |
| 8 | + js.configs.recommended, |
| 9 | + { |
| 10 | + files: ['src/**/*.ts'], |
| 11 | + languageOptions: { |
| 12 | + parser: tsparser, |
| 13 | + parserOptions: { |
| 14 | + ecmaVersion: 2020, |
| 15 | + sourceType: 'module', |
| 16 | + project: './tsconfig.eslint.json', |
| 17 | + }, |
| 18 | + }, |
| 19 | + plugins: { |
| 20 | + '@typescript-eslint': tseslint, |
| 21 | + prettier: prettier, |
| 22 | + }, |
| 23 | + rules: { |
| 24 | + // TypeScript ESLint recommended rules |
| 25 | + ...tseslint.configs.recommended.rules, |
| 26 | + |
| 27 | + // Prettier integration |
| 28 | + 'prettier/prettier': 'error', |
| 29 | + |
| 30 | + // Converted from TSLint rules |
| 31 | + 'curly': ['error', 'multi-line', 'consistent'], |
| 32 | + 'max-classes-per-file': ['error', 5], |
| 33 | + '@typescript-eslint/naming-convention': [ |
| 34 | + 'error', |
| 35 | + { |
| 36 | + selector: 'variable', |
| 37 | + format: ['camelCase', 'PascalCase'], |
| 38 | + leadingUnderscore: 'allow', |
| 39 | + }, |
| 40 | + ], |
| 41 | + 'sort-imports': 'off', // equivalent to ordered-imports: false |
| 42 | + 'sort-keys': 'off', // equivalent to object-literal-sort-keys: false |
| 43 | + |
| 44 | + // Additional TypeScript-specific rules |
| 45 | + '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], |
| 46 | + '@typescript-eslint/explicit-function-return-type': 'off', |
| 47 | + '@typescript-eslint/explicit-module-boundary-types': 'off', |
| 48 | + '@typescript-eslint/no-explicit-any': 'warn', |
| 49 | + |
| 50 | + // Allow multiple variable declarations per statement (from TSLint config) |
| 51 | + 'one-var': 'off', |
| 52 | + |
| 53 | + // Disable some rules that might be too strict for this project |
| 54 | + '@typescript-eslint/no-inferrable-types': 'off', |
| 55 | + }, |
| 56 | + }, |
| 57 | + // Configuration for test files |
| 58 | + { |
| 59 | + files: ['test/**/*.ts'], |
| 60 | + languageOptions: { |
| 61 | + parser: tsparser, |
| 62 | + parserOptions: { |
| 63 | + ecmaVersion: 2020, |
| 64 | + sourceType: 'module', |
| 65 | + project: './tsconfig.eslint.json', |
| 66 | + }, |
| 67 | + globals: { |
| 68 | + describe: 'readonly', |
| 69 | + it: 'readonly', |
| 70 | + test: 'readonly', |
| 71 | + expect: 'readonly', |
| 72 | + beforeAll: 'readonly', |
| 73 | + afterAll: 'readonly', |
| 74 | + beforeEach: 'readonly', |
| 75 | + afterEach: 'readonly', |
| 76 | + // Mocha/Chai globals |
| 77 | + before: 'readonly', |
| 78 | + after: 'readonly', |
| 79 | + chai: 'readonly', |
| 80 | + }, |
| 81 | + }, |
| 82 | + plugins: { |
| 83 | + '@typescript-eslint': tseslint, |
| 84 | + prettier: prettier, |
| 85 | + }, |
| 86 | + rules: { |
| 87 | + // TypeScript ESLint recommended rules |
| 88 | + ...tseslint.configs.recommended.rules, |
| 89 | + |
| 90 | + // Prettier integration |
| 91 | + 'prettier/prettier': 'error', |
| 92 | + |
| 93 | + // Test-specific rule overrides |
| 94 | + '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], |
| 95 | + '@typescript-eslint/explicit-function-return-type': 'off', |
| 96 | + '@typescript-eslint/explicit-module-boundary-types': 'off', |
| 97 | + '@typescript-eslint/no-explicit-any': 'warn', |
| 98 | + '@typescript-eslint/no-unused-expressions': 'off', // Allow for Chai expressions |
| 99 | + |
| 100 | + // Allow multiple variable declarations per statement |
| 101 | + 'one-var': 'off', |
| 102 | + |
| 103 | + // Disable some rules that might be too strict for test files |
| 104 | + '@typescript-eslint/no-inferrable-types': 'off', |
| 105 | + }, |
| 106 | + }, |
| 107 | + prettierConfig, // This should be last to override other formatting rules |
| 108 | +]; |
0 commit comments