Skip to content

Latest commit

Β 

History

History
150 lines (135 loc) Β· 72.7 KB

angular.md

File metadata and controls

150 lines (135 loc) Β· 72.7 KB

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-rxjs-x
  3. Add to your eslint.config.js file:

    import angular from '@code-pushup/eslint-config/angular.js';
    import tseslint from 'typescript-eslint';
    
    export default tseslint.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
            }
          ]
        }
      }
    );
  4. Refer to step 3 in TypeScript config's setup docs for how to set up tsconfig properly.

πŸ“ Rules (425)

345 rules are included from typescript config. For brevity, only the 80 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 (36)

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 interactive-supports-focus
[Accessibility] Ensures that elements with interactive handlers like (click) are focusable.
@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-x no-floating-observables
Require Observables to be handled appropriately.
rxjs-x no-ignored-notifier
Disallow observables not composed from the repeatWhen or retryWhen notifier.
rxjs-x no-ignored-replay-buffer
Disallow using ReplaySubject, publishReplay or shareReplay without specifying the buffer size.
rxjs-x no-ignored-takewhile-value
Disallow ignoring the value within takeWhile.
rxjs-x no-implicit-any-catch
Disallow implicit any error parameters in catchError operators.
πŸ”§, πŸ’‘
rxjs-x no-index
Disallow importing index modules.
rxjs-x no-internal
Disallow importing internal modules.
πŸ”§, πŸ’‘
rxjs-x no-redundant-notify
Disallow sending redundant notifications from completed or errored observables.
rxjs-x no-sharereplay
Disallow unsafe shareReplay usage.
rxjs-x no-subject-unsubscribe
Disallow calling the unsubscribe method of subjects.
rxjs-x no-unbound-methods
Disallow passing unbound methods.
rxjs-x no-unsafe-subject-next
Disallow unsafe optional next calls.
rxjs-x no-unsafe-takeuntil
Disallow applying operators after takeUntil.

⚠️ Warnings (44)

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 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-control-flow
Ensures that the built-in control flow is used.
@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-x finnish
Enforce Finnish notation.
πŸ§ͺ🚫
rxjs-x no-async-subscribe
Disallow passing async functions to subscribe.
rxjs-x no-compat
Disallow the rxjs-compat package.
rxjs-x no-create
Disallow the static Observable.create function.
rxjs-x no-exposed-subjects
Disallow public and protected subjects.
rxjs-x no-nested-subscribe
Disallow calling subscribe within a subscribe callback.
rxjs-x no-subscribe-in-pipe
Disallow calling of subscribe within any RxJS operator inside a pipe.
rxjs-x no-topromise
Disallow use of the toPromise method.
πŸ’‘
rxjs-x prefer-observer
Disallow passing separate handlers to subscribe and tap.
πŸ”§, πŸ’‘
rxjs-x prefer-root-operators
Disallow importing operators from rxjs/operators.
πŸ”§, πŸ’‘
rxjs-x throw-error
Enforce passing only Error values to throwError.