Skip to content

Latest commit

Β 

History

History
139 lines (126 loc) Β· 68.5 KB

angular.md

File metadata and controls

139 lines (126 loc) Β· 68.5 KB

@code-pushup/eslint-config/angular config

Config for Angular projects.

πŸ—οΈ Setup

  1. If you haven't already, make sure to install @code-pushup/eslint-config and its required peer dependencies.

  2. Since this plugin requires additional peer dependencies, you have to install them as well:

    npm install -D @angular-eslint/{eslint-plugin,eslint-plugin-template,template-parser} eslint-plugin-{deprecation,rxjs}
  3. Refer to step 3 in TypeScript config's setup docs for how to set up tsconfig properly.

  4. Add to extends in your .eslintrc file:

    {
      "extends": ["@code-pushup/eslint-config/angular"],
      // It is recommended that selectors in Angular use a common custom prefix
      // - see https://angular.io/guide/styleguide#style-02-07
      // To enforce this consistently, add the following rules:
      "rules": {
        "@angular-eslint/component-selector": [
          "warn",
          {
            "type": "element",
            "style": "kebab-case",
            "prefix": ["cp"] // <-- replace with your own prefix
          }
        ],
        "@angular-eslint/directive-selector": [
          "warn",
          {
            "type": "attribute",
            "style": "camelCase",
            "prefix": "cp" // <-- replace with your own prefix
          }
        ],
        "@angular-eslint/pipe-prefix": [
          "warn",
          {
            "prefixes": ["cp"] // <-- replace with your own prefix
          }
        ]
      }
    }

πŸ“ Rules (382)

307 rules are included from @code-pushup/eslint-config/typescript. For brevity, only the 75 additional rules are listed in this document.

πŸ”§ Automatically fixable by the --fix CLI option.
πŸ’‘ Manually fixable by editor suggestions.
πŸ§ͺ🚫 Disabled for test files.
πŸ§ͺ⚠️ Severity lessened to warning for test files.

🚨 Errors (33)

Plugin Rule Options Autofix Overrides
@angular-eslint contextual-decorator
Ensures that classes use contextual decorators in its body
@angular-eslint contextual-lifecycle
Ensures that lifecycle methods are used in a correct context
@angular-eslint no-conflicting-lifecycle
Ensures that directives not implement conflicting lifecycle interfaces.
@angular-eslint no-lifecycle-call
Disallows explicit calls to lifecycle methods
πŸ§ͺ⚠️
@angular-eslint use-component-view-encapsulation
Disallows using ViewEncapsulation.None
πŸ’‘
@angular-eslint use-pipe-transform-interface
Ensures that Pipes implement PipeTransform interface
πŸ”§
@angular-eslint/template alt-text
[Accessibility] Enforces alternate text for elements which require the alt, aria-label, aria-labelledby attributes.
@angular-eslint/template banana-in-box
Ensures that the two-way data binding syntax is correct
πŸ”§
@angular-eslint/template click-events-have-key-events
[Accessibility] Ensures that the click event is accompanied with at least one key event keyup, keydown or keypress.
@angular-eslint/template elements-content
[Accessibility] Ensures that the heading, anchor and button elements have content in it
@angular-eslint/template eqeqeq
Requires === and !== in place of == and !=
allowNullOrUndefined: true
{
  "allowNullOrUndefined": true
}
πŸ”§, πŸ’‘
@angular-eslint/template label-has-associated-control
[Accessibility] Ensures that a label element/component is associated with a form element
@angular-eslint/template mouse-events-have-key-events
[Accessibility] Ensures that the mouse events mouseout and mouseover are accompanied by focus and blur events respectively. Coding for the keyboard is important for users with physical disabilities who cannot use a mouse, AT compatibility, and screenreader users. See more at https://www.w3.org/WAI/WCAG21/Understanding/keyboard
@angular-eslint/template no-any
The use of "$any" nullifies the compile-time benefits of Angular's type system
πŸ’‘ πŸ§ͺ🚫
@angular-eslint/template no-distracting-elements
[Accessibility] Enforces that no distracting elements are used
πŸ”§
@angular-eslint/template no-duplicate-attributes
Ensures that there are no duplicate input properties or output event listeners
πŸ’‘
@angular-eslint/template no-negated-async
Ensures that async pipe results, as well as values used with the async pipe, are not negated
πŸ’‘
@angular-eslint/template role-has-required-aria
[Accessibility] Ensures elements with ARIA roles have all required properties for that role.
πŸ’‘
@angular-eslint/template table-scope
[Accessibility] Ensures that the scope attribute is only used on the <th> element
πŸ”§
@angular-eslint/template valid-aria
[Accessibility] Ensures that correct ARIA attributes and respective values are used
πŸ’‘
import no-namespace
Forbid namespace (a.k.a. "wildcard" *) imports.
πŸ”§
import no-nodejs-modules
Forbid Node.js builtin modules.
rxjs no-ignored-notifier
Forbids observables not composed from the repeatWhen or retryWhen notifier.
rxjs no-ignored-replay-buffer
Forbids using ReplaySubject, publishReplay or shareReplay without specifying the buffer size.
rxjs no-ignored-takewhile-value
Forbids ignoring the value within takeWhile.
rxjs no-index
Forbids the importation from index modules.
rxjs no-internal
Forbids the importation of internals.
πŸ”§, πŸ’‘
rxjs no-redundant-notify
Forbids redundant notifications from completed or errored observables.
rxjs no-sharereplay
Forbids using the shareReplay operator.
allowConfig: true
{
  "allowConfig": true
}
rxjs no-subject-unsubscribe
Forbids calling the unsubscribe method of a subject instance.
rxjs no-unbound-methods
Forbids the passing of unbound methods.
rxjs no-unsafe-subject-next
Forbids unsafe optional next calls.
rxjs no-unsafe-takeuntil
Forbids the application of operators after takeUntil.

⚠️ Warnings (42)

Plugin Rule Options Autofix Overrides
@angular-eslint component-class-suffix
Classes decorated with @Component must have suffix "Component" (or custom) in their name. See more at https://angular.dev/style-guide#style-02-03
@angular-eslint component-max-inline-declarations
Enforces a maximum number of lines in inline template, styles and animations. See more at https://angular.dev/style-guide#style-05-04
πŸ§ͺ🚫
@angular-eslint component-selector
Component selectors should follow given naming rules. See more at https://angular.dev/style-guide#style-02-07, https://angular.dev/style-guide#style-05-02
and https://angular.dev/style-guide#style-05-03.
type: element, style: kebab...
{
  "type": "element",
  "style": "kebab-case"
}
@angular-eslint directive-class-suffix
Classes decorated with @Directive must have suffix "Directive" (or custom) in their name. See more at https://angular.dev/style-guide#style-02-03
@angular-eslint directive-selector
Directive selectors should follow given naming rules. See more at https://angular.dev/style-guide#style-02-06 and https://angular.dev/style-guide#style-02-08.
type: attribute, style: cam...
{
  "type": "attribute",
  "style": "camelCase"
}
@angular-eslint no-attribute-decorator
The @Attribute decorator is used to obtain a single value for an attribute. This is a much less common use-case than getting a stream of values (using @Input), so often the @Attribute decorator is mistakenly used when @Input was what was intended. This rule disallows usage of @Attribute decorator altogether in order to prevent these mistakes.
@angular-eslint no-empty-lifecycle-method
Disallows declaring empty lifecycle methods
πŸ’‘
@angular-eslint no-input-rename
Ensures that input bindings are not aliased
πŸ”§, πŸ’‘
@angular-eslint no-inputs-metadata-property
Disallows usage of the inputs metadata property. See more at https://angular.dev/style-guide#style-05-12
@angular-eslint no-output-native
Ensures that output bindings, including aliases, are not named as standard DOM events
@angular-eslint no-output-on-prefix
Ensures that output bindings, including aliases, are not named "on", nor prefixed with it. See more at https://angular.dev/style-guide#style-05-16
@angular-eslint no-output-rename
Ensures that output bindings are not aliased
πŸ”§, πŸ’‘
@angular-eslint no-outputs-metadata-property
Disallows usage of the outputs metadata property. See more at https://angular.dev/style-guide#style-05-12
@angular-eslint no-pipe-impure
Disallows the declaration of impure pipes
πŸ’‘
@angular-eslint no-queries-metadata-property
Disallows usage of the queries metadata property. See more at https://angular.dev/style-guide#style-05-12.
@angular-eslint prefer-on-push-component-change-detection
Ensures component's changeDetection is set to ChangeDetectionStrategy.OnPush
πŸ’‘ πŸ§ͺ🚫
@angular-eslint prefer-output-readonly
Prefer to declare @Output as readonly since they are not supposed to be reassigned
πŸ’‘
@angular-eslint prefer-standalone-component
Ensures component standalone property is set to true in the component decorator
πŸ”§ πŸ§ͺ🚫
@angular-eslint relative-url-prefix
The ./ and ../ prefix is standard syntax for relative URLs; don't depend on Angular's current ability to do without that prefix. See more at https://angular.dev/style-guide#style-05-04
@angular-eslint sort-lifecycle-methods
Ensures that lifecycle methods are declared in order of execution
@angular-eslint use-component-selector
Component selector must be declared
πŸ§ͺ🚫
@angular-eslint use-injectable-provided-in
Using the providedIn property makes Injectables tree-shakable
πŸ’‘ πŸ§ͺ🚫
@angular-eslint use-lifecycle-interface
Ensures that classes implement lifecycle interfaces corresponding to the declared lifecycle methods. See more at https://angular.dev/style-guide#style-09-01
πŸ”§
@angular-eslint/template conditional-complexity
The conditional complexity should not exceed a rational limit
@angular-eslint/template cyclomatic-complexity
Checks cyclomatic complexity against a specified limit. It is a quantitative measure of the number of linearly independent paths through a program's source code
maxComplexity: 20
{
  "maxComplexity": 20
}
@angular-eslint/template interactive-supports-focus
[Accessibility] Ensures that elements with interactive handlers like (click) are focusable.
@angular-eslint/template no-autofocus
[Accessibility] Ensures that the autofocus attribute is not used
πŸ”§
@angular-eslint/template no-inline-styles
Disallows the use of inline styles in HTML templates
allowNgStyle: true, allowBi...
{
  "allowNgStyle": true,
  "allowBindToStyle": true
}
πŸ§ͺ🚫
@angular-eslint/template no-interpolation-in-attributes
Ensures that property-binding is used instead of interpolation in attributes.
@angular-eslint/template no-positive-tabindex
Ensures that the tabindex attribute is not positive
πŸ’‘
@angular-eslint/template prefer-ngsrc
Ensures ngSrc is used instead of src for img elements
πŸ§ͺ🚫
@angular-eslint/template prefer-self-closing-tags
Ensures that self-closing tags are used for elements with a closing tag but no content.
πŸ”§
@angular-eslint/template use-track-by-function
Ensures trackBy function is used
πŸ§ͺ🚫
rxjs finnish
Enforces the use of Finnish notation.
πŸ§ͺ🚫
rxjs no-async-subscribe
Forbids passing async functions to subscribe.
rxjs no-compat
Forbids importation from locations that depend upon rxjs-compat.
rxjs no-create
Forbids the calling of Observable.create.
rxjs no-exposed-subjects
Forbids exposed (i.e. non-private) subjects.
rxjs no-ignored-observable
Forbids the ignoring of observables returned by functions.
rxjs no-nested-subscribe
Forbids the calling of subscribe within a subscribe callback.
rxjs prefer-observer
Forbids the passing separate handlers to subscribe and tap.
πŸ”§, πŸ’‘
rxjs throw-error
Enforces the passing of Error values to error notifications.