Codelyzer core rules
Lint rules encode logic for syntactic & semantic checks of TypeScript, HTML, CSS and Angular expressions source code.
TypeScript-specific
These rules find errors related to TypeScript or Angular features:
Functionality
These rules catch common errors in JS programming or otherwise confusing constructs that are prone to producing bugs:
-
TS Onlycontextual-decorator - Ensures that classes use contextual decorators in its body.
-
TS Onlycontextual-lifecycle - Ensures that classes use allowed lifecycle method in its body.
-
TS Onlyno-attribute-decorator - Disallows usage of @Attribute decorator.
-
TS Onlyno-lifecycle-call - Disallows explicit calls to lifecycle methods.
-
TS Onlyno-output-native - Disallows naming directive outputs as standard DOM event.
-
TS Onlyno-pipe-impure - Disallows the declaration of impure pipes.
-
TS Onlyprefer-on-push-component-change-detection - Enforces component’s change detection to ChangeDetectionStrategy.OnPush.
-
TS Onlytemplate-accessibility-alt-text - Enforces alternate text for elements which require the alt, aria-label, aria-labelledby attributes
-
TS Onlytemplate-accessibility-elements-content - Ensures that the heading, anchor and button elements have content in it
-
TS Onlytemplate-accessibility-label-for - Checks if a label component is associated with a form element
-
TS Onlytemplate-accessibility-tabindex-no-positive - Ensures that the tabindex attribute is not positive
-
TS Onlytemplate-accessibility-table-scope - Ensures that scope is not used on any element except th
-
TS Onlytemplate-accessibility-valid-aria - Ensures that the correct ARIA attributes are used
-
TS Only Has Fixertemplate-banana-in-box - Ensures that the two-way data binding syntax is correct.
-
TS Onlytemplate-click-events-have-key-events - Ensures that the click event is accompanied with at least one key event keyup, keydown or keypress
-
TS Onlytemplate-mouse-events-have-key-events - Ensures that the Mouse Events mouseover and mouseout are accompanied with Key Events focus and blur
-
TS Onlytemplate-no-any - Disallows using ‘$any’ in templates.
-
TS Onlytemplate-no-autofocus - Ensure that autofocus property is not used
-
TS Onlytemplate-no-distracting-elements - Enforces that no distracting elements are used
-
TS Onlytemplate-no-negated-async - Ensures that strict equality is used when evaluating negations on async pipe output.
-
TS Onlyuse-injectable-provided-in - Enforces classes decorated with @Injectable to use the ‘providedIn’ property.
-
TS Onlyuse-lifecycle-interface - Ensures classes implement lifecycle interfaces corresponding to the declared lifecycle methods.
Maintainability
These rules make code maintenance easier:
-
TS Onlycomponent-max-inline-declarations - Disallows having too many lines in inline template and styles. Forces separate template or styles file creation.
-
TS Onlyno-conflicting-lifecycle - Ensures that directives not implement conflicting lifecycle interfaces.
-
TS Onlyno-forward-ref - Disallows usage of
forwardRef
references for DI. -
TS Onlyno-input-prefix - Input names should not be prefixed by the configured disallowed prefixes.
-
TS Onlyno-input-rename - Disallows renaming directive inputs by providing a string to the decorator.
-
TS Onlyno-output-on-prefix - Name events without the prefix on.
-
TS Onlyno-output-rename - Disallows renaming directive outputs by providing a string to the decorator.
-
TS Only Has Fixerno-unused-css - Disallows having an unused CSS rule in the component’s stylesheet.
-
TS Onlyprefer-output-readonly - Prefer to declare
@Output
as readonly since they are not supposed to be reassigned. -
TS Onlyrelative-url-prefix - The ./ prefix is standard syntax for relative URLs; don’t depend on Angular’s current ability to do without that prefix.
-
TS Onlytemplate-conditional-complexity - The condition complexity shouldn’t exceed a rational limit in a template.
-
TS Onlytemplate-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
-
TS Onlytemplate-i18n - Ensures following best practices for i18n.
-
TS Onlytemplate-no-call-expression - Disallows calling expressions in templates, except for output handlers.
-
TS Onlytemplate-use-track-by-function - Ensures trackBy function is used.
-
TS Onlyuse-component-selector - Component selector must be declared.
-
TS Onlyuse-component-view-encapsulation - Disallows using ViewEncapsulation.None.
-
TS Onlyuse-pipe-decorator - Ensures that classes implementing PipeTransform interface use @Pipe decorator.
-
TS Onlyuse-pipe-transform-interface - Ensures that classes decorated with @Pipe implement PipeTransform interface.
Style
These rules enforce consistent style across your codebase:
-
TS Only Has Fixerangular-whitespace - Ensures the proper formatting of Angular expressions.
-
TS Onlycomponent-class-suffix - Classes decorated with @Component must have suffix “Component” (or custom) in their name.
-
TS Onlycomponent-selector - Component selectors should follow given naming rules.
-
TS Onlydirective-class-suffix - Classes decorated with @Directive must have suffix “Directive” (or custom) in their name.
-
TS Onlydirective-selector - Directive selectors should follow given naming rules.
-
TS Only Has Fixerimport-destructuring-spacing - Ensures imports are consistent and tidy.
-
TS Onlyno-host-metadata-property - Disallows usage of the
host
metadata property. -
TS Onlyno-inputs-metadata-property - Disallows usage of the
inputs
metadata property. -
TS Onlyno-outputs-metadata-property - Disallows usage of the
outputs
metadata property. -
TS Onlyno-queries-metadata-property - Disallows usage of the
queries
metadata property. -
TS Onlypipe-prefix - Enforce consistent prefix for pipes.
-
TS Onlyprefer-inline-decorator - Ensures that declarations are on the same line as its decorator(s).