Thanks to visit codestin.com
Credit goes to github.com

Skip to content

LakMoore/angular-eslint

Β 
Β 

Repository files navigation

Angular ESLint

Monorepo for all the tooling which enables ESLint to lint Angular projects

Build Status NPM Version GitHub license NPM Downloads Codecov Commitizen friendly


This project is made possible thanks to the continued hard work going into https://github.com/typescript-eslint/typescript-eslint, and brilliant work on the original TSLint rule implementations in https://github.com/mgechev/codelyzer.

Feel free to begin playing with the tooling in your own projects and submit PRs with missing rules and bug fixes.

We would also be very grateful for documentation PRs!


Packages included in this project

Please follow the links below for the packages you care about.

  • @angular-eslint/builder - An Angular CLI Builder which is used to execute ESLint on your Angular projects using standard commands such as ng lint

  • @angular-eslint/eslint-plugin - An ESLint-specific plugin that contains rules which are specific to Angular projects. It can be combined with any other ESLint plugins in the normal way.

  • @angular-eslint/template-parser - An ESLint-specific parser which leverages the @angular/compiler to allow for custom ESLint rules to be written which assert things about your Angular templates.

  • @angular-eslint/eslint-plugin-template - An ESLint-specific plugin which, when used in conjunction with @angular-eslint/template-parser, allows for Angular template-specific linting rules to run.


Linting templates with Angular ESLint

You can change the parser in the main section of your eslint config file to the template parser in this project. The rules in /template will then be available to use in your main config section. If any rules in OTHER packages then complain about not having access to the parser they need, you can add an 'overrides' section to your config specifically for the template rules instead, e.g.:

// ... more config
"overrides": [
    {
      "files": ["*.component.html"],
      "parser": "@angular-eslint/template-parser",
      "plugins": ["@angular-eslint/template"],
      "rules": {
        "@angular-eslint/template/banana-in-a-box": "error",
        "@angular-eslint/template/cyclomatic-complexity": "error",
        "@angular-eslint/template/no-call-expression": "error",
        "@angular-eslint/template/no-negated-async": "error",
        "@angular-eslint/template/i18n": [
          "error",
          {
            "checkId": false,
            "checkText": true,
            "checkAttributes": true,
            "ignoreAttributes": [
              "field",
              "identifier"
            ]
          }
        ]
      }
    }
  ]
// ... more config

Linting inline-templates with the VSCode extension for ESLint

If you use vscode-eslint, and inline-templates on your Angular Components, you will need to make sure you add the following to your VSCode settings:

// ... more config

"eslint.options": {
  "extensions": [".ts", ".html"]
}

// ... more config

Please see the following issue for more information: microsoft/vscode-eslint#922


Migrating from Codelyzer and TSLint

We have some work in progress tooling to make this as automated as possible, but the reality is it will always be somewhat project-specific as to how much work will be involved in the migration.

The first step is to run the schematic to add @angular-eslint to your project:

ng add @angular-eslint/schematics

This will handle installing the latest version of all the relevant packages for you and adding them to the devDependencies of your package.json.

Soon this ng-add schematic will also handle applying some of the following steps for you automatically.

The migration involves a few different aspects:

  1. Replacing the builder the Angular CLI will use when you run ng lint

  2. Replacing your tslint.json files with .eslintrc.json files

  3. Populating the .eslintrc.json files appropriately to match the previous setup you had in the Codelyzer + TSLint world

The best reference configurations for performing your own migration are located within the Angular CLI integration test within this monorepo. Check out the relevant configuration files:

If you are looking for general help in migrating from TSLint to ESLint, you can check out this project: https://github.com/typescript-eslint/tslint-to-eslint-config

Rules List

βœ… = done
🚧 = work in progress

Functionality

Codelyzer rule Status
contextual-decorator
contextual-lifecycle βœ…
no-attribute-decorator βœ…
no-lifecycle-call βœ…
no-output-native βœ…
no-pipe-impure βœ…
prefer-on-push-component-change-detection βœ…
template-accessibility-alt-text
template-accessibility-elements-content
template-accessibility-label-for
template-accessibility-tabindex-no-positive
template-accessibility-table-scope
template-accessibility-valid-aria
template-banana-in-box βœ…
template-click-events-have-key-events
template-mouse-events-have-key-events
template-no-any
template-no-autofocus
template-no-distracting-elements
template-no-negated-async βœ…
use-injectable-provided-in βœ…
use-lifecycle-interface βœ…

Maintainability

Codelyzer rule Status
component-max-inline-declarations βœ…
no-conflicting-lifecycle βœ…
no-forward-ref βœ…
no-input-prefix βœ…
no-input-rename βœ…
no-output-on-prefix βœ…
no-output-rename βœ…
no-unused-css
prefer-output-readonly βœ…
relative-url-prefix βœ…
template-conditional-complexity
template-cyclomatic-complexity βœ…
template-i18n βœ…
template-no-call-expression βœ…
template-use-track-by-function
use-component-selector βœ…
use-component-view-encapsulation βœ…
use-pipe-decorator βœ…
use-pipe-transform-interface βœ…

Style

Codelyzer rule Status
angular-whitespace
component-class-suffix βœ…
component-selector βœ…
directive-class-suffix βœ…
directive-selector βœ…
import-destructuring-spacing
no-host-metadata-property βœ…
no-inputs-metadata-property βœ…
no-outputs-metadata-property βœ…
no-queries-metadata-property βœ…
pipe-prefix
prefer-inline-decorator

About

✨ Monorepo for all the tooling related to using ESLint with Angular

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 97.9%
  • JavaScript 1.7%
  • Other 0.4%