|
| 1 | +import tsParser from '@typescript-eslint/parser' |
| 2 | +import tsPlugin from '@typescript-eslint/eslint-plugin' |
| 3 | +import sonarjs from 'eslint-plugin-sonarjs' |
| 4 | +import jsdoc from 'eslint-plugin-jsdoc' |
| 5 | + |
| 6 | +const STRICT_RULES = { |
| 7 | + '@typescript-eslint/no-explicit-any': 'error', |
| 8 | + '@typescript-eslint/no-non-null-assertion': 'error', |
| 9 | + '@typescript-eslint/explicit-function-return-type': ['error', { |
| 10 | + allowExpressions: true, |
| 11 | + allowTypedFunctionExpressions: true, |
| 12 | + }], |
| 13 | + '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], |
| 14 | + |
| 15 | + // Structural metrics — all hard caps. High values signal a function doing too much. |
| 16 | + // - Function length: 50 lines (≤40 is the working norm). |
| 17 | + // - Indent depth: 3 levels. Non-negotiable. |
| 18 | + // - Cyclomatic complexity: 12. Genuine cases (e.g. dispatch over a finite enum) |
| 19 | + // can use `// eslint-disable-next-line complexity` with a one-line justification. |
| 20 | + 'max-lines-per-function': ['error', { max: 50, skipBlankLines: true, skipComments: true, IIFEs: true }], |
| 21 | + 'max-lines': ['error', { max: 400, skipBlankLines: true, skipComments: true }], |
| 22 | + 'max-depth': ['error', 3], |
| 23 | + 'complexity': ['error', 12], |
| 24 | + |
| 25 | + 'no-restricted-syntax': ['error', |
| 26 | + { |
| 27 | + selector: "TSAsExpression > TSTypeReference > Identifier[name='never']", |
| 28 | + message: '`as never` is forbidden. Use proper types or `// eslint-disable-next-line` with a specific reason.', |
| 29 | + }, |
| 30 | + { |
| 31 | + selector: 'TSAsExpression > TSAsExpression > TSUnknownKeyword', |
| 32 | + message: '`as unknown as X` double-cast is forbidden. Use proper types or `// eslint-disable-next-line` with a specific reason.', |
| 33 | + }, |
| 34 | + ], |
| 35 | + |
| 36 | + '@typescript-eslint/consistent-type-assertions': ['error', { |
| 37 | + assertionStyle: 'as', |
| 38 | + objectLiteralTypeAssertions: 'never', |
| 39 | + }], |
| 40 | + '@typescript-eslint/no-unnecessary-type-assertion': 'error', |
| 41 | + |
| 42 | + 'no-console': 'error', |
| 43 | + 'prefer-const': 'error', |
| 44 | + |
| 45 | + // Cognitive complexity (sonarjs) — readability metric |
| 46 | + 'sonarjs/cognitive-complexity': ['error', 15], |
| 47 | + |
| 48 | + // Async correctness |
| 49 | + '@typescript-eslint/no-floating-promises': 'error', |
| 50 | + '@typescript-eslint/no-misused-promises': 'error', |
| 51 | + '@typescript-eslint/require-await': 'error', |
| 52 | + '@typescript-eslint/await-thenable': 'error', |
| 53 | + |
| 54 | + // Boolean correctness — catches `if (someObj)` style bugs |
| 55 | + '@typescript-eslint/strict-boolean-expressions': ['error', { |
| 56 | + allowNullableBoolean: true, |
| 57 | + allowNullableObject: false, |
| 58 | + allowAny: false, |
| 59 | + }], |
| 60 | + |
| 61 | + // Type-level correctness |
| 62 | + '@typescript-eslint/no-unnecessary-condition': 'error', |
| 63 | + '@typescript-eslint/switch-exhaustiveness-check': 'error', |
| 64 | + '@typescript-eslint/no-base-to-string': 'error', |
| 65 | + '@typescript-eslint/no-confusing-void-expression': 'error', |
| 66 | + |
| 67 | + '@typescript-eslint/only-throw-error': 'error', |
| 68 | + |
| 69 | + '@typescript-eslint/ban-ts-comment': ['error', { |
| 70 | + 'ts-expect-error': 'allow-with-description', |
| 71 | + 'ts-ignore': true, |
| 72 | + 'ts-nocheck': true, |
| 73 | + 'ts-check': false, |
| 74 | + }], |
| 75 | + |
| 76 | + '@typescript-eslint/consistent-type-imports': ['error', { |
| 77 | + prefer: 'type-imports', |
| 78 | + fixStyle: 'inline-type-imports', |
| 79 | + }], |
| 80 | + |
| 81 | + 'eqeqeq': ['error', 'always', { null: 'ignore' }], |
| 82 | + |
| 83 | + '@typescript-eslint/prefer-readonly': 'error', |
| 84 | + |
| 85 | + 'max-params': ['error', 4], |
| 86 | + |
| 87 | + 'sonarjs/no-identical-functions': 'error', |
| 88 | + |
| 89 | + '@typescript-eslint/naming-convention': ['error', |
| 90 | + { selector: 'variableLike', format: ['camelCase', 'UPPER_CASE', 'PascalCase'], leadingUnderscore: 'allow' }, |
| 91 | + { selector: 'typeLike', format: ['PascalCase'] }, |
| 92 | + { selector: 'enumMember', format: ['camelCase', 'PascalCase'] }, |
| 93 | + ], |
| 94 | + |
| 95 | + // JSDoc-on-public-exports is required in libraries (so IDE hover docs stay in |
| 96 | + // sync). curveforge-ui is an end-user app, not an SDK consumers integrate |
| 97 | + // against, so this rule is disabled — the rest of the type discipline stands. |
| 98 | + 'jsdoc/require-jsdoc': 'off', |
| 99 | + 'jsdoc/check-tag-names': ['error', { definedTags: ['internal'] }], |
| 100 | + 'jsdoc/check-param-names': 'error', |
| 101 | + 'jsdoc/no-undefined-types': 'off', |
| 102 | +} |
| 103 | + |
| 104 | +export default [ |
| 105 | + { |
| 106 | + ignores: ['dist/**', 'node_modules/**', 'public/**', 'scripts/**'], |
| 107 | + }, |
| 108 | + { |
| 109 | + files: ['src/**/*.ts'], |
| 110 | + languageOptions: { |
| 111 | + parser: tsParser, |
| 112 | + parserOptions: { project: ['./tsconfig.json'] }, |
| 113 | + }, |
| 114 | + plugins: { '@typescript-eslint': tsPlugin, sonarjs, jsdoc }, |
| 115 | + rules: STRICT_RULES, |
| 116 | + }, |
| 117 | +] |
0 commit comments