|
| 1 | +import typescriptParser from '@typescript-eslint/parser'; |
| 2 | +import prettierPlugin from 'eslint-plugin-prettier'; |
| 3 | +import tsPlugin from '@typescript-eslint/eslint-plugin'; |
| 4 | +import angularPlugin from '@angular-eslint/eslint-plugin'; |
| 5 | +import angularTemplate from '@angular-eslint/eslint-plugin-template'; |
| 6 | +import angularTemplateParser from '@angular-eslint/template-parser'; |
| 7 | +import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'; |
| 8 | +import eslintPluginUnicorn from 'eslint-plugin-unicorn'; |
| 9 | +import js from '@eslint/js'; |
| 10 | +import eslintConfigPrettier from 'eslint-config-prettier'; |
| 11 | + |
| 12 | +export default [ |
| 13 | + { |
| 14 | + ignores: ['.cache/', '.git/', '.github/', 'node_modules/'], |
| 15 | + }, |
| 16 | + { |
| 17 | + files: ['**/*.ts'], |
| 18 | + languageOptions: { |
| 19 | + parser: typescriptParser, |
| 20 | + parserOptions: { |
| 21 | + project: ['./tsconfig.json', './tsconfig.app.json', './tsconfig.spec.json'], |
| 22 | + }, |
| 23 | + }, |
| 24 | + plugins: { |
| 25 | + '@typescript-eslint': tsPlugin, |
| 26 | + '@angular-eslint': angularPlugin, |
| 27 | + prettier: prettierPlugin, |
| 28 | + }, |
| 29 | + rules: { |
| 30 | + // TypeScript: https://typescript-eslint.io/rules/ |
| 31 | + ...tsPlugin.configs.recommended.rules, |
| 32 | + ...tsPlugin.configs.stylistic.rules, |
| 33 | + '@typescript-eslint/explicit-function-return-type': 'error', |
| 34 | + '@typescript-eslint/triple-slash-reference': 'warn', |
| 35 | + '@typescript-eslint/member-ordering': [ |
| 36 | + 'error', |
| 37 | + { |
| 38 | + default: { |
| 39 | + memberTypes: [ |
| 40 | + // Index signature |
| 41 | + 'signature', |
| 42 | + 'call-signature', |
| 43 | + |
| 44 | + // Fields |
| 45 | + 'public-static-field', |
| 46 | + 'protected-static-field', |
| 47 | + 'private-static-field', |
| 48 | + '#private-static-field', |
| 49 | + |
| 50 | + 'public-decorated-field', |
| 51 | + 'protected-decorated-field', |
| 52 | + 'private-decorated-field', |
| 53 | + |
| 54 | + 'public-instance-field', |
| 55 | + 'protected-instance-field', |
| 56 | + 'private-instance-field', |
| 57 | + '#private-instance-field', |
| 58 | + |
| 59 | + 'public-abstract-field', |
| 60 | + 'protected-abstract-field', |
| 61 | + |
| 62 | + 'public-field', |
| 63 | + 'protected-field', |
| 64 | + 'private-field', |
| 65 | + '#private-field', |
| 66 | + |
| 67 | + 'static-field', |
| 68 | + 'instance-field', |
| 69 | + 'abstract-field', |
| 70 | + |
| 71 | + 'decorated-field', |
| 72 | + |
| 73 | + 'field', |
| 74 | + |
| 75 | + // Static initialization |
| 76 | + 'static-initialization', |
| 77 | + |
| 78 | + // Constructors |
| 79 | + 'public-constructor', |
| 80 | + 'protected-constructor', |
| 81 | + 'private-constructor', |
| 82 | + |
| 83 | + 'constructor', |
| 84 | + |
| 85 | + // Accessors |
| 86 | + 'public-static-accessor', |
| 87 | + 'protected-static-accessor', |
| 88 | + 'private-static-accessor', |
| 89 | + '#private-static-accessor', |
| 90 | + |
| 91 | + 'public-decorated-accessor', |
| 92 | + 'protected-decorated-accessor', |
| 93 | + 'private-decorated-accessor', |
| 94 | + |
| 95 | + 'public-instance-accessor', |
| 96 | + 'protected-instance-accessor', |
| 97 | + 'private-instance-accessor', |
| 98 | + '#private-instance-accessor', |
| 99 | + |
| 100 | + 'public-abstract-accessor', |
| 101 | + 'protected-abstract-accessor', |
| 102 | + |
| 103 | + 'public-accessor', |
| 104 | + 'protected-accessor', |
| 105 | + 'private-accessor', |
| 106 | + '#private-accessor', |
| 107 | + |
| 108 | + 'static-accessor', |
| 109 | + 'instance-accessor', |
| 110 | + 'abstract-accessor', |
| 111 | + |
| 112 | + 'decorated-accessor', |
| 113 | + |
| 114 | + 'accessor', |
| 115 | + |
| 116 | + // Getters and Setters (merged) |
| 117 | + ['public-static-get', 'public-static-set'], |
| 118 | + ['protected-static-get', 'protected-static-set'], |
| 119 | + ['private-static-get', 'private-static-set'], |
| 120 | + ['#private-static-get', '#private-static-set'], |
| 121 | + |
| 122 | + ['public-decorated-get', 'public-decorated-set'], |
| 123 | + ['protected-decorated-get', 'protected-decorated-set'], |
| 124 | + ['private-decorated-get', 'private-decorated-set'], |
| 125 | + |
| 126 | + ['public-instance-get', 'public-instance-set'], |
| 127 | + ['protected-instance-get', 'protected-instance-set'], |
| 128 | + ['private-instance-get', 'private-instance-set'], |
| 129 | + ['#private-instance-get', '#private-instance-set'], |
| 130 | + |
| 131 | + ['public-abstract-get', 'public-abstract-set'], |
| 132 | + ['protected-abstract-get', 'protected-abstract-set'], |
| 133 | + |
| 134 | + ['public-get', 'public-set'], |
| 135 | + ['protected-get', 'protected-set'], |
| 136 | + ['private-get', 'private-set'], |
| 137 | + ['#private-get', '#private-set'], |
| 138 | + |
| 139 | + ['static-get', 'static-set'], |
| 140 | + ['instance-get', 'instance-set'], |
| 141 | + ['abstract-get', 'abstract-set'], |
| 142 | + |
| 143 | + ['decorated-get', 'decorated-set'], |
| 144 | + |
| 145 | + ['get', 'set'], |
| 146 | + |
| 147 | + // Methods |
| 148 | + 'public-static-method', |
| 149 | + 'protected-static-method', |
| 150 | + 'private-static-method', |
| 151 | + '#private-static-method', |
| 152 | + |
| 153 | + 'public-decorated-method', |
| 154 | + 'protected-decorated-method', |
| 155 | + 'private-decorated-method', |
| 156 | + |
| 157 | + 'public-instance-method', |
| 158 | + 'protected-instance-method', |
| 159 | + 'private-instance-method', |
| 160 | + '#private-instance-method', |
| 161 | + |
| 162 | + 'public-abstract-method', |
| 163 | + 'protected-abstract-method', |
| 164 | + |
| 165 | + 'public-method', |
| 166 | + 'protected-method', |
| 167 | + 'private-method', |
| 168 | + '#private-method', |
| 169 | + |
| 170 | + 'static-method', |
| 171 | + 'instance-method', |
| 172 | + 'abstract-method', |
| 173 | + |
| 174 | + 'decorated-method', |
| 175 | + |
| 176 | + 'method', |
| 177 | + ], |
| 178 | + }, |
| 179 | + }, |
| 180 | + ], |
| 181 | + '@typescript-eslint/consistent-type-definitions': ['error', 'type'], |
| 182 | + '@typescript-eslint/no-unused-vars': [ |
| 183 | + 'error', |
| 184 | + { |
| 185 | + args: 'all', |
| 186 | + argsIgnorePattern: '^_', |
| 187 | + caughtErrors: 'all', |
| 188 | + caughtErrorsIgnorePattern: '^_', |
| 189 | + destructuredArrayIgnorePattern: '^_', |
| 190 | + varsIgnorePattern: '^_', |
| 191 | + ignoreRestSiblings: true, |
| 192 | + }, |
| 193 | + ], |
| 194 | + |
| 195 | + // Angular: https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/README.md |
| 196 | + ...angularPlugin.configs.recommended.rules, |
| 197 | + '@angular-eslint/directive-selector': ['off', { type: 'attribute', style: 'camelCase' }], |
| 198 | + '@angular-eslint/component-selector': ['error', { type: 'element', prefix: 'ff', style: 'kebab-case' }], |
| 199 | + |
| 200 | + // EcmaScript: https://eslint.org/docs/latest/rules/ |
| 201 | + ...js.configs.recommended.rules, |
| 202 | + 'prefer-template': 'error', |
| 203 | + 'no-undef': 'off', |
| 204 | + 'no-unused-vars': 'off', // Handled by @typescript-eslint/no-unused-vars |
| 205 | + |
| 206 | + // Prettier: https://github.com/prettier/eslint-config-prettier?tab=readme-ov-file#special-rules |
| 207 | + ...eslintConfigPrettier.rules, |
| 208 | + 'prettier/prettier': 'warn', |
| 209 | + }, |
| 210 | + }, |
| 211 | + { |
| 212 | + files: ['**/*.html'], |
| 213 | + languageOptions: { |
| 214 | + parser: angularTemplateParser, |
| 215 | + }, |
| 216 | + plugins: { |
| 217 | + '@angular-eslint': angularPlugin, |
| 218 | + '@angular-eslint/template': angularTemplate, |
| 219 | + prettier: prettierPlugin, |
| 220 | + }, |
| 221 | + rules: { |
| 222 | + // Angular template: https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin-template/README.md |
| 223 | + ...angularTemplate.configs.recommended.rules, |
| 224 | + ...angularTemplate.configs.accessibility.rules, |
| 225 | + '@angular-eslint/template/prefer-self-closing-tags': 'error', |
| 226 | + '@angular-eslint/template/no-interpolation-in-attributes': ['error'], |
| 227 | + '@angular-eslint/template/click-events-have-key-events': 'off', |
| 228 | + '@angular-eslint/template/interactive-supports-focus': [ |
| 229 | + 'error', |
| 230 | + { |
| 231 | + allowList: ['li'], |
| 232 | + }, |
| 233 | + ], |
| 234 | + '@angular-eslint/contextual-decorator': 'warn', |
| 235 | + '@angular-eslint/prefer-signals': 'error', |
| 236 | + '@angular-eslint/template/attributes-order': [ |
| 237 | + 'error', |
| 238 | + { |
| 239 | + alphabetical: false, |
| 240 | + order: [ |
| 241 | + 'TEMPLATE_REFERENCE', |
| 242 | + 'ATTRIBUTE_BINDING', |
| 243 | + 'STRUCTURAL_DIRECTIVE', |
| 244 | + 'INPUT_BINDING', |
| 245 | + 'TWO_WAY_BINDING', |
| 246 | + 'OUTPUT_BINDING', |
| 247 | + ], |
| 248 | + }, |
| 249 | + ], |
| 250 | + |
| 251 | + // Prettier: https://github.com/prettier/eslint-config-prettier?tab=readme-ov-file#special-rules |
| 252 | + ...eslintConfigPrettier.rules, |
| 253 | + 'prettier/prettier': ['error', { parser: 'angular' }], |
| 254 | + }, |
| 255 | + }, |
| 256 | + // Unicorn: https://github.com/sindresorhus/eslint-plugin-unicorn |
| 257 | + eslintPluginUnicorn.configs.recommended, |
| 258 | + { |
| 259 | + rules: { |
| 260 | + 'unicorn/prevent-abbreviations': 'warn', |
| 261 | + 'unicorn/no-array-reduce': 'off', |
| 262 | + 'unicorn/prefer-ternary': 'warn', |
| 263 | + 'unicorn/no-null': 'off', |
| 264 | + 'unicorn/prefer-dom-node-text-content': 'warn', |
| 265 | + 'unicorn/consistent-function-scoping': [ |
| 266 | + 'error', |
| 267 | + { |
| 268 | + checkArrowFunctions: false, |
| 269 | + }, |
| 270 | + ], |
| 271 | + }, |
| 272 | + }, |
| 273 | + eslintPluginPrettierRecommended, |
| 274 | + // SonarJS: https://github.com/SonarSource/SonarJS/blob/master/packages/jsts/src/rules/README.md |
| 275 | + // sonarjs.configs.recommended, |
| 276 | + // { |
| 277 | + // rules: { |
| 278 | + // 'sonarjs/cognitive-complexity': 'error', |
| 279 | + // 'sonarjs/no-duplicate-string': 'error', |
| 280 | + // }, |
| 281 | + // }, |
| 282 | +]; |
0 commit comments