|
| 1 | +// @ts-check |
| 2 | +const eslint = require('@eslint/js'); |
| 3 | +const tseslint = require('typescript-eslint'); |
| 4 | +const angular = require('angular-eslint'); |
| 5 | + |
| 6 | +module.exports = tseslint.config( |
| 7 | + { |
| 8 | + files: ['**/*.ts'], |
| 9 | + extends: [ |
| 10 | + eslint.configs.recommended, |
| 11 | + ...tseslint.configs.recommended, |
| 12 | + ...tseslint.configs.stylistic, |
| 13 | + ...angular.configs.tsRecommended, |
| 14 | + ], |
| 15 | + processor: angular.processInlineTemplates, |
| 16 | + rules: { |
| 17 | + // Component selectors should follow given naming rules. |
| 18 | + // @see http://codelyzer.com/rules/component-selector/ |
| 19 | + '@angular-eslint/component-selector': [ |
| 20 | + 'error', |
| 21 | + { |
| 22 | + type: 'element', |
| 23 | + prefix: 'ngx', |
| 24 | + style: 'kebab-case', |
| 25 | + }, |
| 26 | + ], |
| 27 | + // Directive selectors should follow given naming rules. |
| 28 | + // @see http://codelyzer.com/rules/directive-selector/ |
| 29 | + '@angular-eslint/directive-selector': [ |
| 30 | + 'error', |
| 31 | + { |
| 32 | + type: 'attribute', |
| 33 | + prefix: 'ngx', |
| 34 | + style: 'camelCase', |
| 35 | + }, |
| 36 | + ], |
| 37 | + // Prefer to declare @Output as readonly since they are not supposed |
| 38 | + // to be reassigned. |
| 39 | + // @see http://codelyzer.com/rules/prefer-output-readonly/ |
| 40 | + '@angular-eslint/prefer-output-readonly': ['error'], |
| 41 | + // Enforce use of component selector rules. |
| 42 | + // @see http://codelyzer.com/rules/component-selector/ |
| 43 | + '@angular-eslint/use-component-selector': ['error'], |
| 44 | + // Disallows using ViewEncapsulation.None. |
| 45 | + // @see http://codelyzer.com/rules/use-component-view-encapsulation/ |
| 46 | + '@angular-eslint/use-component-view-encapsulation': ['error'], |
| 47 | + // Ensure that components implement life cycle interfaces if they use |
| 48 | + // them. |
| 49 | + // @see http://codelyzer.com/rules/use-life-cycle-interface/ |
| 50 | + '@angular-eslint/use-lifecycle-interface': ['error'], |
| 51 | + // Require consistently using either T[] or Array<T> for arrays. |
| 52 | + // @see https://typescript-eslint.io/rules/array-type/ |
| 53 | + '@typescript-eslint/array-type': ['error', { default: 'array-simple' }], |
| 54 | + // Enforce consistent usage of type assertions. |
| 55 | + // @see https://typescript-eslint.io/rules/consistent-type-assertions/ |
| 56 | + '@typescript-eslint/consistent-type-assertions': [ |
| 57 | + 'error', |
| 58 | + { |
| 59 | + assertionStyle: 'as', |
| 60 | + objectLiteralTypeAssertions: 'never', |
| 61 | + }, |
| 62 | + ], |
| 63 | + // Enforce type definitions to consistently use either interface or type. |
| 64 | + // @see https://typescript-eslint.io/rules/consistent-type-definitions/ |
| 65 | + '@typescript-eslint/consistent-type-definitions': 'error', |
| 66 | + // Require explicit return types on functions and class methods. |
| 67 | + // @see https://typescript-eslint.io/rules/explicit-function-return-type/ |
| 68 | + '@typescript-eslint/explicit-function-return-type': [ |
| 69 | + 'error', |
| 70 | + { allowExpressions: true }, |
| 71 | + ], |
| 72 | + // Require explicit accessibility modifiers on class properties and methods. |
| 73 | + // @see https://typescript-eslint.io/rules/explicit-member-accessibility/ |
| 74 | + '@typescript-eslint/explicit-member-accessibility': [ |
| 75 | + 'error', |
| 76 | + { accessibility: 'explicit' }, |
| 77 | + ], |
| 78 | + // Require explicit return and argument types on exported functions' and |
| 79 | + // classes' public class methods. |
| 80 | + // @see https://typescript-eslint.io/rules/explicit-module-boundary-types/ |
| 81 | + '@typescript-eslint/explicit-module-boundary-types': 'error', |
| 82 | + // Require a consistent member declaration order. |
| 83 | + // @see https://typescript-eslint.io/rules/member-ordering/ |
| 84 | + '@typescript-eslint/member-ordering': [ |
| 85 | + 'error', |
| 86 | + { |
| 87 | + default: [ |
| 88 | + 'constructor', |
| 89 | + 'static-field', |
| 90 | + 'instance-field', |
| 91 | + 'static-method', |
| 92 | + 'instance-method', |
| 93 | + ], |
| 94 | + }, |
| 95 | + ], |
| 96 | + // Enforce naming conventions for everything across a codebase. |
| 97 | + // @see https://typescript-eslint.io/rules/naming-convention/ |
| 98 | + '@typescript-eslint/naming-convention': [ |
| 99 | + 'error', |
| 100 | + { |
| 101 | + selector: 'classProperty', |
| 102 | + format: ['PascalCase', 'camelCase'], |
| 103 | + modifiers: ['public'], |
| 104 | + }, |
| 105 | + { |
| 106 | + selector: 'function', |
| 107 | + format: ['camelCase'], |
| 108 | + }, |
| 109 | + { |
| 110 | + selector: 'interface', |
| 111 | + format: ['PascalCase'], |
| 112 | + custom: { |
| 113 | + regex: '^I[A-Z]', |
| 114 | + match: false, |
| 115 | + }, |
| 116 | + }, |
| 117 | + { |
| 118 | + selector: 'enumMember', |
| 119 | + format: ['UPPER_CASE'], |
| 120 | + }, |
| 121 | + ], |
| 122 | + // Disallow empty functions. |
| 123 | + // @see https://typescript-eslint.io/rules/no-empty-function/ |
| 124 | + '@typescript-eslint/no-empty-function': 'error', |
| 125 | + // Disallow the declaration of empty interfaces. |
| 126 | + // @see https://typescript-eslint.io/rules/no-empty-interface/ |
| 127 | + '@typescript-eslint/no-empty-interface': 'off', |
| 128 | + // Disallow the any type. |
| 129 | + // @see https://typescript-eslint.io/rules/no-explicit-any/ |
| 130 | + '@typescript-eslint/no-explicit-any': 'error', |
| 131 | + // Disallow TypeScript namespaces. |
| 132 | + // @see https://typescript-eslint.io/rules/no-namespace/ |
| 133 | + '@typescript-eslint/no-namespace': ['error', { allowDeclarations: true }], |
| 134 | + // Disallow unused expressions. |
| 135 | + // @see https://typescript-eslint.io/rules/no-unused-expressions/ |
| 136 | + '@typescript-eslint/no-unused-expressions': 'error', |
| 137 | + // Disallow unused variables. |
| 138 | + // @see https://typescript-eslint.io/rules/no-unused-vars/ |
| 139 | + '@typescript-eslint/no-unused-vars': [ |
| 140 | + 'error', |
| 141 | + { |
| 142 | + argsIgnorePattern: '^_', |
| 143 | + ignoreRestSiblings: true, |
| 144 | + varsIgnorePattern: '^_', |
| 145 | + }, |
| 146 | + ], |
| 147 | + // Enforce the use of for-of loop over the standard for loop where |
| 148 | + // possible. |
| 149 | + // @see https://typescript-eslint.io/rules/prefer-for-of/ |
| 150 | + '@typescript-eslint/prefer-for-of': ['warn'], |
| 151 | + // Enforce using function types instead of interfaces with call |
| 152 | + // signatures. |
| 153 | + // @see https://typescript-eslint.io/rules/prefer-function-type/ |
| 154 | + '@typescript-eslint/prefer-function-type': ['warn'], |
| 155 | + // Disallow two overloads that could be unified into one with a union |
| 156 | + // or an optional/rest parameter. |
| 157 | + // @see https://typescript-eslint.io/rules/unified-signatures/ |
| 158 | + '@typescript-eslint/unified-signatures': 'warn', |
| 159 | + // Require the use of === and !== |
| 160 | + // @see https://eslint.org/docs/latest/rules/eqeqeq |
| 161 | + eqeqeq: ['error'], |
| 162 | + // Require for-in loops to include an if statement |
| 163 | + // @see https://eslint.org/docs/latest/rules/guard-for-in |
| 164 | + 'guard-for-in': ['error'], |
| 165 | + // Disallow bitwise operators |
| 166 | + // @see https://eslint.org/docs/latest/rules/no-bitwise |
| 167 | + 'no-bitwise': ['error'], |
| 168 | + // Disallow the use of arguments.caller or arguments.callee |
| 169 | + // @see https://eslint.org/docs/latest/rules/no-caller |
| 170 | + 'no-caller': ['error'], |
| 171 | + // Disallow the use of console |
| 172 | + // @see https://eslint.org/docs/latest/rules/no-console |
| 173 | + 'no-console': ['error', { allow: ['warn', 'error'] }], |
| 174 | + // Disallow duplicate module imports |
| 175 | + // @see https://eslint.org/docs/latest/rules/no-duplicate-imports |
| 176 | + 'no-duplicate-imports': ['error'], |
| 177 | + // Disallow empty block statements |
| 178 | + // @see https://eslint.org/docs/latest/rules/no-empty |
| 179 | + 'no-empty': 'error', |
| 180 | + // Disallow the use of eval() |
| 181 | + // @see https://eslint.org/docs/latest/rules/no-eval |
| 182 | + 'no-eval': ['error'], |
| 183 | + // Disallow new operators with the String, Number, and Boolean objects |
| 184 | + // @see https://eslint.org/docs/latest/rules/no-new-wrappers |
| 185 | + 'no-new-wrappers': ['error'], |
| 186 | + // Disallow throwing literals as exceptions |
| 187 | + // @see https://eslint.org/docs/latest/rules/no-throw-literal |
| 188 | + 'no-throw-literal': ['error'], |
| 189 | + // Require let or const instead of var |
| 190 | + // @see https://eslint.org/docs/latest/rules/no-var |
| 191 | + 'no-var': ['error'], |
| 192 | + // Require or disallow method and property shorthand syntax for object |
| 193 | + // literals |
| 194 | + // @see https://eslint.org/docs/latest/rules/object-shorthand |
| 195 | + 'object-shorthand': ['error'], |
| 196 | + // Enforce variables to be declared either together or separately in |
| 197 | + // functions |
| 198 | + // @see https://eslint.org/docs/latest/rules/one-var |
| 199 | + 'one-var': ['error', 'never'], |
| 200 | + // Require using arrow functions for callbacks |
| 201 | + // @see https://eslint.org/docs/latest/rules/prefer-arrow-callback |
| 202 | + 'prefer-arrow/prefer-arrow-functions': 'off', |
| 203 | + // Require const declarations for variables that are never reassigned |
| 204 | + // after declared |
| 205 | + // @see https://eslint.org/docs/latest/rules/prefer-const |
| 206 | + 'prefer-const': ['error'], |
| 207 | + // Enforce the consistent use of the radix argument when using |
| 208 | + // parseInt() |
| 209 | + // @see https://eslint.org/docs/latest/rules/radix |
| 210 | + radix: ['error'], |
| 211 | + // Enforce consistent spacing after the // or /* in a comment |
| 212 | + // @see https://eslint.org/docs/latest/rules/spaced-comment |
| 213 | + 'spaced-comment': ['error', 'always', { block: { balanced: true } }], |
| 214 | + }, |
| 215 | + }, |
| 216 | + { |
| 217 | + files: ['**/*.html'], |
| 218 | + extends: [ |
| 219 | + ...angular.configs.templateRecommended, |
| 220 | + ...angular.configs.templateAccessibility, |
| 221 | + ], |
| 222 | + rules: {}, |
| 223 | + }, |
| 224 | +); |
0 commit comments