Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

codelyzer

mgechev2.4mMIT6.0.2TypeScript support: included

Linting for Angular applications, following angular.io/styleguide.

Angular, style guide, styleguide, nglint, codelyzer, lint, tslint

readme

npm version Downloads Build Status code style: prettier Conventional Commits Gitter Chat

codelyzer

A set of tslint rules for static code analysis of Angular TypeScript projects.
(If you are using ESLint check out the new angular-eslint repository.)

You can run the static code analyzer over web apps, NativeScript, Ionic, etc.

Vote for your favorite feature here. For more details about the feature request process see this document

How to use?

Angular CLI

Angular CLI has support for codelyzer. In order to validate your code with CLI and the custom Angular specific rules just use:

ng new codelyzer
ng lint

Note that by default all components are aligned with the style guide so you won't see any errors in the console.

Angular Seed

Another project which has out of the box integration with codelyzer is angular-seed. In order to run the linter you should:

# Skip if you've already cloned Angular Seed
git clone https://github.com/mgechev/angular-seed

# Skip if you've already installed all the dependencies of Angular Seed
cd angular-seed && npm i

# Run all the tslint and codelyzer rules
npm run lint

Note that by default all components are aligned with the style guide so you won't see any errors in the console.

Custom Setup

Preset

You can use the tslint-angular preset. All you need is:

npm i tslint-angular

After that create a tslint.json file with the following configuration:

{
  "extends": ["tslint-angular"]
}

Run the linter with:

./node_modules/.bin/tslint -c tslint.json

TSLint will now complain that there are rules which require type checking. In order to fix this, use the -p config option:

./node_modules/.bin/tslint -p tsconfig.json -c tslint.json

Custom Installation

You can easily use codelyzer with your custom setup:

npm i codelyzer tslint @angular/compiler @angular/core

A. Using codelyzer package in PATH

Create the following tslint.json file like:

{
  "extends": ["codelyzer"],
  "rules": {
    "component-class-suffix": true,
    "component-max-inline-declarations": true,
    "component-selector": [true, "element", "sg", "kebab-case"],
    "contextual-lifecycle": true,
    "directive-class-suffix": true,
    "directive-selector": [true, "attribute", "sg", "camelCase"],
    "no-attribute-decorator": true,
    "no-conflicting-lifecycle": true,
    "no-forward-ref": true,
    "no-host-metadata-property": true,
    "no-input-rename": true,
    "no-inputs-metadata-property": true,
    "no-lifecycle-call": true,
    "no-output-native": true,
    "no-output-on-prefix": true,
    "no-output-rename": true,
    "no-outputs-metadata-property": true,
    "no-pipe-impure": true,
    "no-queries-metadata-property": true,
    "no-unused-css": true,
    "prefer-inline-decorator": true,
    "prefer-output-readonly": true,
    "template-banana-in-box": true,
    "template-conditional-complexity": [true, 4],
    "template-cyclomatic-complexity": [true, 5],
    "template-i18n": [true, "check-id", "check-text"],
    "template-no-negated-async": true,
    "template-use-track-by-function": true,
    "use-component-selector": true,
    "use-component-view-encapsulation": true,
    "use-lifecycle-interface": true,
    "use-pipe-transform-interface": true
  }
}

To run TSLint with this setup you can use one of the following alternatives:

  1. Install codelyzer globally npm install -g codelyzer

  2. Run TSLint from a package.json script by adding a script like tslint . to your package.json, similar to:

"scripts": {
  ...
  "lint": "tslint .",
  ...
},

Then run npm run lint

B. Using codelyzer from node_modules directory

Now create the following tslint.json file where your node_modules directory is:

{
  "rulesDirectory": ["node_modules/codelyzer"],
  "rules": {
    "component-class-suffix": true,
    "component-max-inline-declarations": true,
    "component-selector": [true, "element", "sg", "kebab-case"],
    "contextual-lifecycle": true,
    "directive-class-suffix": true,
    "directive-selector": [true, "attribute", "sg", "camelCase"],
    "no-attribute-decorator": true,
    "no-conflicting-lifecycle": true,
    "no-forward-ref": true,
    "no-host-metadata-property": true,
    "no-input-rename": true,
    "no-inputs-metadata-property": true,
    "no-lifecycle-call": true,
    "no-output-native": true,
    "no-output-on-prefix": true,
    "no-output-rename": true,
    "no-outputs-metadata-property": true,
    "no-pipe-impure": true,
    "no-queries-metadata-property": true,
    "no-unused-css": true,
    "prefer-inline-decorator": true,
    "prefer-output-readonly": true,
    "template-banana-in-box": true,
    "template-conditional-complexity": [true, 4],
    "template-cyclomatic-complexity": [true, 5],
    "template-i18n": [true, "check-id", "check-text"],
    "template-no-negated-async": true,
    "template-use-track-by-function": true,
    "use-component-selector": true,
    "use-component-view-encapsulation": true,
    "use-lifecycle-interface": true,
    "use-pipe-transform-interface": true
  }
}

Next you can create a component file in the same directory with name component.ts and the following content:

import { Component } from '@angular/core';

@Component({
  selector: 'codelyzer',
  template: ` <h1>Hello {{ name }}!</h1> `,
})
class Codelyzer {
  name: string = 'World';

  ngOnInit() {
    console.log('Initialized');
  }
}

As last step you can execute all the rules against your code with tslint:

./node_modules/.bin/tslint -c tslint.json component.ts

You should see the following output:

component.ts[4, 13]: The selector of the component "Codelyzer" should have prefix "sg" (https://goo.gl/cix8BY)
component.ts[12, 3]: Implement lifecycle hook interface OnInit for method ngOnInit in class Codelyzer (https://goo.gl/w1Nwk3)
component.ts[9, 7]: The name of the class Codelyzer should end with the suffix Component (https://goo.gl/5X1TE7)

Editor Configuration

Note that you need to have tslint plugin install on your editor.

Codelyzer should work out of the box with Atom but for VSCode you will have to open Code > Preferences > User Settings, and enter the following config:

{
  "tslint.rulesDirectory": "./node_modules/codelyzer",
  "typescript.tsdk": "node_modules/typescript/lib"
}

Now you should have the following result:

VSCode Codelyzer

Enjoy!

Changelog

You can find it here.

Below you can find a recommended configuration which is based on the Angular Style Guide.

{
  // The rules component-selector and directive-selector have the following arguments:
  // [ENABLED, "attribute" | "element", "prefix" | ["listOfPrefixes"], "camelCase" | "kebab-case"]
  "component-selector": [true, "element", ["cmp-prefix1", "cmp-prefix2"], "kebab-case"],
  "directive-selector": [true, "attribute", ["dir-prefix1", "dir-prefix2"], "camelCase"],

  "component-max-inline-declarations": true,
  "contextual-lifecycle": true,
  "no-conflicting-lifecycle": true,
  "no-host-metadata-property": true,
  "no-input-rename": true,
  "no-inputs-metadata-property": true,
  "no-output-native": true,
  "no-output-on-prefix": true,
  "no-output-rename": true,
  "no-outputs-metadata-property": true,
  "no-queries-metadata-property": true,
  "prefer-inline-decorator": true,
  "template-banana-in-box": true,
  "template-no-negated-async": true,
  "use-lifecycle-interface": true,
  "use-pipe-transform-interface": true,

  // The rules component-class-suffix and directive-class-suffix have the following arguments:
  // [ENABLED, "suffix" | ["listOfSuffixes"]]
  // Where "suffix" is/are your custom(s) suffix(es), for instance "Page" for Ionic components.
  "component-class-suffix": [true, "Component"],
  "directive-class-suffix": [true, "Directive"]
}

Rules Status

Rule Status
component-class-suffix Stable
component-max-inline-declarations Stable
component-selector Stable
contextual-decorator Stable
contextual-lifecycle Stable
directive-class-suffix Stable
directive-selector Stable
import-destructuring-spacing Stable
no-attribute-decorator Stable
no-forward-ref Stable
no-host-metadata-property Stable
no-input-prefix Stable
no-input-rename Stable
no-inputs-metadata-property Stable
no-lifecycle-call Stable
no-output-native Stable
no-output-on-prefix Stable
no-output-rename Stable
no-outputs-metadata-property Stable
no-pipe-impure Stable
no-queries-metadata-property Stable
prefer-inline-decorator Stable
prefer-output-readonly Stable
template-banana-in-box Stable
template-cyclomatic-complexity Stable
template-no-call-expression Stable
template-no-negated-async Stable
template-use-track-by-function Stable
use-component-selector Stable
use-component-view-encapsulation Stable
use-lifecycle-interface Stable
use-pipe-decorator Stable
use-pipe-transform-interface Stable
prefer-on-push-component-change-detection Experimental
no-conflicting-lifecycle Experimental
no-unused-css Experimental
pipe-prefix Experimental
relative-url-prefix Experimental
template-accessibility-alt-text Experimental
template-accessibility-elements-content Experimental
template-accessibility-label-for Experimental
template-accessibility-tabindex-no-positive Experimental
template-accessibility-table-scope Experimental
template-accessibility-valid-aria Experimental
template-click-events-have-key-events Experimental
template-conditional-complexity Experimental
template-i18n Experimental
template-mouse-events-have-key-events Experimental
template-no-any Experimental
template-no-autofocus Experimental
template-no-distracting-elements Experimental
angular-whitespace Deprecated

Disable a rule that validates Template or Styles

Lint rules can be disabled by adding a marker in TypeScript files. More information here.

To disable rules that validate templates or styles you'd need to add a marker in the TypeScript file referencing them.

import { Component } from '@angular/core';

/* tslint:disable:template-use-track-by-function */
@Component({
  selector: 'codelyzer',
  templateUrl: './codelyzer.component.html',
})
class Codelyzer {}

Advanced configuration

Codelyzer supports any template and style language by custom hooks. If you're using Sass for instance, you can allow codelyzer to analyze your styles by creating a file .codelyzer.js in the root of your project (where the node_modules directory is). In the configuration file can implement custom pre-processing and template resolution logic:

// Demo of transforming Sass styles
var sass = require('node-sass');

module.exports = {
  // Definition of custom interpolation strings
  interpolation: ['{{', '}}'],

  // You can transform the urls of your external styles and templates
  resolveUrl(url, decorator) {
    return url;
  },

  // Transformation of the templates. This hooks is quite useful
  // if you're using any other templating language, for instance
  // jade, markdown, haml, etc.
  //
  // NOTE that this method WILL NOT throw an error in case of invalid template.
  //
  transformTemplate(code, url, decorator) {
    return { code: code, url: url };
  },

  // Transformation of styles. This hook is useful is you're using
  // any other style language, for instance Sass, Less, etc.
  //
  // NOTE that this method WILL NOT throw an error in case of invalid style.
  //
  transformStyle(code, url, decorator) {
    var result = { code: code, url: url };
    if (url && /\.scss$/.test(url)) {
      var transformed = sass.renderSync({ data: code, sourceMap: true, outFile: '/dev/null' });
      result.source = code;
      result.code = transformed.css.toString();
      result.map = transformed.map.toString();
    }
    return result;
  },

  // Custom predefined directives in case you get error for
  // missing property and you are using a template reference
  predefinedDirectives: [{ selector: 'form', exportAs: 'ngForm' }],

  // None = 0b000, Error = 0b001, Info = 0b011, Debug = 0b111
  logLevel: 0b111,
};

Contributors

mgechev wKoza rafaelss95 preslavsh mohammedzamakhan rokerkony
mgechev wKoza rafaelss95 preslavsh mohammedzamakhan rokerkony
GregOnNet alan-agius4 kevinphelps eppsilon csvn ghsyeung
GregOnNet alan-agius4 kevinphelps eppsilon csvn ghsyeung
Kobzol mattlewis92 lazarljubenovic sagittarius-rev connor4312 Foxandxss
Kobzol mattlewis92 lazarljubenovic sagittarius-rev connor4312 Foxandxss
gbilodeau NagRock Hotell Martin-Wegner comfroels plantain-00
gbilodeau NagRock Hotell Martin-Wegner comfroels plantain-00
nexus-uw alexkpek loktionov129 alisd23 aboyton bmvantunes
nexus-uw alexkpek loktionov129 alisd23 aboyton bmvantunes
Moeriki sneas EmmanuelDemey eromano Manduro karol-depka
Moeriki sneas EmmanuelDemey eromano Manduro karol-depka
leosvelperez muhammadghazali PapsOu rwlogel robzenn92 rtfpessoa
leosvelperez muhammadghazali PapsOu rwlogel robzenn92 rtfpessoa
santoshyadav198613 scttcper stschake tmair YogliB cexbrayat
santoshyadav198613 scttcper stschake tmair YogliB cexbrayat
clydin reduckted someblue
clydin reduckted someblue

License

MIT

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

6.0.1 (2020-09-30)

Bug Fixes

  • add Angular v11 in peer dependencies (#979) (cd88bd5)

6.0.0 (2020-09-30)

Bug Fixes

  • add Angular v11 in peer dependencies (#979) (cd88bd5)

5.3.0 (2020-07-02)

Features

  • add support for angular v10 (d27202c)

Bug Fixes

  • deps: update dependency app-root-path to v3 (#923) (4218091)
  • add support for tslint 6.0+ (#961) (ef5f158)
  • deps: update dependency codemirror to v5.51.0 (#914) (87bbfd5)
  • deps: update dependency typescript to v3 (#837) (49c2828)
  • 3.6 compile time errors (0066e93)

5.2.3 (2020-03-26)

Bug Fixes

  • add support for tslint 6.0+ (#961) (ef5f158)
  • deps: update dependency codemirror to v5.51.0 (#914) (87bbfd5)
  • deps: update dependency typescript to v3 (#837) (49c2828)
  • 3.6 compile time errors (0066e93)

5.2.1 (2020-03-03)

Bug Fixes

  • deps: update dependency codemirror to v5.51.0 (#914) (87bbfd5)
  • deps: update dependency typescript to v3 (#837) (49c2828)
  • 3.6 compile time errors (0066e93)

5.2.0 (2019-10-22)

Bug Fixes

Features

5.1.2 (2019-09-26)

Bug Fixes

  • angular: update function call broken by Angular changes (#857) (d916eb3)
  • deps: update dependency codelyzer to v5.1.1 (#894) (2902c31)
  • deps: update dependency codemirror to v5.49.0 (#877) (76fa03e)

5.1.1 (2019-09-19)

Bug Fixes

  • deps: pin dependencies (#826) (fa40a63)
  • deps: update dependency codelyzer to v5 (#847) (98deb50)
  • deps: update dependency codemirror to v5.48.2 (#839) (21504e1)
  • deps: update dependency tslint to v3.15.1 (#841) (fc80f4e)
  • rule: template-click-events-have-key-events - support pseudo events (#893) (5b57bd6)

5.1.0 (2019-06-02)

Bug Fixes

  • rule: 'contextual-decorator' - decorators with arguments, accessors and some missing decorators not being handled (#798) (efbcb69)
  • rule: template-banana-in-box regex failing in some environments (#820) (3b82574)

Features

  • rule: add use-injectable-provided-in (#814) (656816f)

5.0.1 (2019-04-25)

Bug Fixes

  • rule: detect trackBy function when ngFor spans multiple lines (#813) (2260dfd)
  • rule: template-accessibility-label-for not recognizing options and interpolated values (#812) (1fb5d8a)

5.0.0 (2019-03-27)

BREAKING CHANGES

Angular CLI will automatically migrate your projects to reflect the latest config.

  • contextual-life-cycle is renamed to contextual-lifecycle
  • no-conflicting-life-cycle-hooks is renamed to no-conflicting-lifecycle
  • no-life-cycle-call is renamed to no-lifecycle-call
  • use-life-cycle-interface is renamed to use-lifecycle-interface
  • decorator-not-allowed is renamed to contextual-decorator
  • enforce-component-selector is renamed to use-component-selector
  • no-output-named-after-standard-event is renamed to no-output-native
  • use-host-property-decorator is renamed to no-host-metadata-property
  • use-input-property-decorator is renamed to no-inputs-metadata-property
  • use-output-property-decorator is renamed to no-outputs-metadata-property
  • no-queries-parameter is renamed to no-queries-metadata-property
  • pipe-impure is renamed to no-pipe-impure
  • use-view-encapsulation is renamed to use-component-view-encapsulation
  • i18n is renamed to template-i18n
  • banana-in-box is renamed to template-banana-in-box
  • no-template-call-expression is renamed to template-no-call-expression
  • templates-no-negated-async is renamed to template-no-negated-async
  • trackBy-function is renamed to template-use-track-by-function
  • no-attribute-parameter-decorator is renamed to no-attribute-decorator
  • max-inline-declarations is renamed to component-max-inline-declarations

Bug Fixes

  • rule: template-use-track-by-function not reporting failures involving multiple *ngFor directives (#721) (9269be6), closes #718
  • rule: template-no-call-expression should allow $any usages (#735) (a75c204)
  • rule: no-input-rename reporting some failures incorrectly (#723) (f692dcb)
  • rule: prefer-inline-decorator should not set a max number of options (#787) (31b2b6a)
  • rule: add template-accessibility-elements-content to index.ts (#803) (1e8cbbf), closes #801
  • rule: NgModule not being handled for contextual-lifecycle and contextual-decorators (#790) (cedfa2e)
  • rule: prefer-inline-decorator not reporting failures for some cases (#794) (a76ebbc)
  • update peerDependencies (d5bfbd5)
  • improve ngWalker by preventing an error when a class has no name (#788) (17c0fe2)

Features

  • rule: add component-change-detection (#737) (a23ccde), closes #135
  • rule: add relative-url-prefix (#725) (f12f27b)
  • rule: add template-accessibility-alt-text (#741) (0815ec5)
  • rule: add template-accessibility-elements-content (#742) (6ff8c56)
  • rule: add template-accessibility-label-for (#739) (76c24fa)
  • rule: add template-accessibility-tabindex-no-positive (#744) (43902f7)
  • rule: add template-accessibility-table-scope (#743) (2832615)
  • rule: add template-accessibility-valid-aria (#746) (762f67f)
  • rule: add template-click-events-have-key-events (#761) (b0b330f)
  • rule: add template-mouse-events-have-key-events (#759) (3a7b15d)
  • rule: add template-no-autofocus (#749) (799382f)
  • rule: add template-no-distracting-elements (#760) (6b21a9e)
  • rule: add template-no-any (#755) (77a5e32)
  • rule: prefer-inline-decorator now accept options (#794) (a76ebbc)
  • add support for svg templates (#800) (dadf8ec)

5.0.0-beta.2 (2019-03-25)

Bug Fixes

  • rule: NgModule not being handled for contextual-lifecycle and contextual-decorators (#790) (cedfa2e)

5.0.0-beta.1 (2019-03-14)

Bug Fixes

  • update peerDependencies (d5bfbd5)

5.0.0-beta.0 (2019-03-12)

This release contains many breaking changes due to the rename of several rules (see more at (bbf7a32)). Currently, there's an open PR (https://github.com/angular/angular-cli/pull/13801) that will help migrate your app if you are affected by these changes.

BREAKING CHANGES

  • contextual-life-cycle is renamed to contextual-lifecycle
  • no-conflicting-life-cycle-hooks is renamed to no-conflicting-lifecycle
  • no-life-cycle-call is renamed to no-lifecycle-call
  • use-life-cycle-interface is renamed to use-lifecycle-interface
  • decorator-not-allowed is renamed to contextual-decorator
  • enforce-component-selector is renamed to use-component-selector
  • no-output-named-after-standard-event is renamed to no-output-native
  • use-host-property-decorator is renamed to no-host-metadata-property
  • use-input-property-decorator is renamed to no-inputs-metadata-property
  • use-output-property-decorator is renamed to no-outputs-metadata-property
  • no-queries-parameter is renamed to no-queries-metadata-property
  • pipe-impure is renamed to no-pipe-impure
  • use-view-encapsulation is renamed to use-component-view-encapsulation
  • i18n is renamed to template-i18n
  • banana-in-box is renamed to template-banana-in-box
  • no-template-call-expression is renamed to template-no-call-expression
  • templates-no-negated-async is renamed to template-no-negated-async
  • trackBy-function is renamed to template-use-track-by-function
  • no-attribute-parameter-decorator is renamed to no-attribute-decorator
  • max-inline-declarations is renamed to component-max-inline-declarations

Bug Fixes

  • rule: template-use-track-by-function not reporting failures involving multiple *ngFor directives (#721) (9269be6), closes #718
  • rule: template-no-call-expression should allow $any usages (#735) (a75c204)
  • rule: no-input-rename reporting some failures incorrectly (#723) (f692dcb)
  • rule: prefer-inline-decorator should not set a max number of options (#787) (31b2b6a)
  • improve ngWalker by preventing an error when a class has no name (#787) (17c0fe2)

Features

  • rule: add component-change-detection (#737) (a23ccde), closes #135
  • rule: add relative-url-prefix (#725) (f12f27b)
  • rule: add template-accessibility-alt-text (#741) (0815ec5)
  • rule: add template-accessibility-elements-content (#742) (6ff8c56)
  • rule: add template-accessibility-label-for (#739) (76c24fa)
  • rule: add template-accessibility-tabindex-no-positive (#744) (43902f7)
  • rule: add template-accessibility-table-scope (#743) (2832615)
  • rule: add template-accessibility-valid-aria (#746) (762f67f)
  • rule: add template-click-events-have-key-events (#761) (b0b330f)
  • rule: add template-mouse-events-have-key-events (#759) (3a7b15d)
  • rule: add template-no-autofocus (#749) (799382f)
  • rule: add template-no-distracting-elements (#760) (6b21a9e)
  • rule: add template-no-any (#755) (77a5e32)

4.5.0 (2018-10-04)

Bug Fixes

  • assertFailure should not catch the exception thrown by assert (#703) (#704) (0bac287)
  • rule: no-unused-css leaving blank lines after applying fixes (#701) (c69e2ae)

Features

4.4.4 (2018-08-13)

Bug Fixes

  • errors not being displayed in the correct files (#700) (db3cf5a)

4.4.3 (2018-08-06)

Bug Fixes

  • url not passed to transformStyle when using styleUrls (#686) (5a84041)
  • templates-no-negated-async: not reporting failures for some cases (#694) (2ffe2ea)

4.4.2 (2018-06-25)

Bug Fixes

  • no-output-on-prefix: fix regular expression (#674) (adc974a)

4.4.1 (2018-06-23)

Bug Fixes

4.4.0 (2018-06-23)

Bug Fixes

  • no-input-prefix: exact strings not being reported (#597) (1ed8d8c)
  • no-input-rename: aria attributes not being allowed to be renamed (#665) (2c905ab), closes #663
  • no-input-rename: fix bugs (#585) (75f9de6), closes #580
  • no-template-call-expression: not being exported (#582) (ad57552), closes #577
  • no-life-cycle-call: fix bugs (#575) (4415cc2), closes #573
  • no-input-prefix: not being able to check for multiple concurrent prefixes (#590) (43d415a), closes #589
  • no-output-rename: not being reported for some cases (#614) (5e34f41), closes #613
  • template-conditional-complexity: not reporting failures for '[ngIf]' (#611) (7fc3b09), closes #607
  • template-cyclomatic-complexity: not reporting failures for '[ngForOf]' and '[ngIf]' (#612) (fedd331), closes #609
  • trackBy-function: not reporting failures for '[ngForOf]' (#610) (af52912), closes #608
  • some rules not considering options correctly (#617) (bce0026)

Features

  • import-destructuring-spacing: add fixer (#595) (2acc27b)
  • max-inline-declarations: add option to limit animations lines (#569) (25f3e16), closes #568
  • rule: add no-queries-parameter rule (#571) (e9f4d23)
  • rule: add prefer-inline-decorator rule (#586) (5d5e21d), closes #549
  • build scripts are not cross-platform #581 204c8ef, closes #454
  • upgrade TypeScript dependency to 2.7.2 #584 d4bf62d, closes #583
  • turn on strict TS compilation mode (#631) (da0f553), closes #629
  • externalizing template, css visitor abstractions and NgWalker (#658) (b79ea58)

Credits to the codelyzer's maintainers and contributors.

4.3.0

New Rules

  • max-inline-declarations which limits the size of inline templates and/or styles. Credits to NagRock #536 174ed46.
  • prefer-output-readonly requires the @Outputs of a component to be readonly. Credits to rafaelss95 #515 3d652d1.
  • no-conflicting-life-cycle-hooks prevents to implement OnChanges and DoCheck on the same class. Credits to rafaelss95 #560 e521115.
  • enforce-component-selector Component Selector Required #551 b9c899b. Credits to wKoza.
  • no-life-cycle-call disallow explicit calls to lifecycle hooks. Credits to rafaelss95 #427 3e10013

Bug Fixes

  • Possible bug with no-input-rename #374 f3a53bd.
  • Removed dependency on @angular/platform-browser-dynamic #525 671e954.
  • Rule contextual-life-cycle too aggressively scoped #545 dcb4b3e.
  • no-output-named-after-standard-event Does Not Check Output Rename #537 96d9292.
  • Template Conditional Complexity reports incorrect threshold #533 5851306.

A lot of credits go to rafaelss95, wKoza. The rest of the amazing people who work on codelyzer, can be found here.

4.2.1

Bug Fixes

  • Improved peerDependencies range.

4.2.0

New Rules

  • template-cyclomatic-complexity which limits the estimated Cyclomatic complexity in your templates. Credits to wKoza.
  • template-conditional-complexity which limits the complexity of boolean expressions inside of your templates. Credits to wKoza.

Features

  • Support for Angular version 6 #524 50fa2d6
  • Cyclomatic complexity rule template-cyclomatic-complexity #514 3221330
  • Limiting template condition complexity (rule template-conditional-complexity) #508 bb86295
  • Complete Rules Status section in README and complete Rules Page #501 1fe9d22

Bug Fixes

  • "extends": ["codelyzer"] is broken #505 7b76dfa
  • Message for 'use-host-property-decorator' includes invalid link to Angular style docs #510 5fc77c9

4.1.0

Features

  • Feature request: no output named after a standard DOM event #473 ae3f07b
  • Support for Angular Compiler 5.2 #496 6a6b3de

Bug Fixes

  • i18n check-text edge cases #442 4c1c8d4
  • Codelyzer hanging for "styles" attribute in Angular component #446 a31c6d2 and 9c90ac3
  • no-output-on-prefix incorrectly throws error if output property name starts with "one" #480 9b844cc

Thanks to @gbilodeau for NoOutputNamedAfterStandardEventRule and wKoza for the code reviews!

4.0.2

Bug Fixes

  • Two issues in angular-whitespace related to check-semicolon and check-interpolation #469 2ef7438
  • Check multiple semicolons inside the directive expressions #472 e6036d2

Thanks to @sagittarius-rev for the bug fixes!

4.0.1

Bug Fixes

  • Fix noOutputOnPrefixRule and rename it to no-output-on-prefix. You can now enable it with:
"no-output-on-prefix": true
  • Fix broken tests for noOutputOnPrefixRule.

4.0.0

Features

Enable the new rule by adding the following line in your tslint.json config file:

"no-output-on-prefix-name": true

Thanks to @eromano for the rule implementation!

Breaking Changes

  • The rules templates-use-public, no-access-missing-member, invoke-injectable and template-to-ng-template no longer exist. Remove them from your tslint.json configuration.

3.2.1

Features

Bug Fixes

3.2.0

Features

  • i18n best practices #377 5ef90aa
  • Add a rule which verifies the use of the life cycle methods according to the type of class (Component, Directive, Service,...) #363 6b042f7
  • Friendlier checking of validator directive names #397 28ecbdd

Bug Fixes

  • Error on validating a pipe with @Pipe decorator where we use a shorthand syntax for passing properties #399 8e3fafb
  • Broken check-pipe option of angular-whitespace #365 bef790b
  • Some rules report false positives #379 8719674 4721aca bef790b

Thanks to @wKoza for working on the introduced features, bug fixes and code reviews!

3.1.2

Features

  • Ensure whitespaces after semicolon in structural dir #330 25667f9

Thanks to @wKoza for code reviews and implementation of "check-semicolon".

angular-whitespace: [true, "check-semicolon", "check-interpolation", "check-pipe"] - Checks if there's whitespace after semicolon, around an expression surrounded by interpolation characters, and after a pipe symbol.

Bug Fixes

  • Auto fix for check-interpolation part of angularWhitespace is broken #345 0be8563
  • check-pipe should ignore i18n meaning and description | separator #359 5aad7f3
  • check-pipe breaks with ngFor #346 fa08a3b

3.1.1

Bug Fixes

  • Incorrect rule name in documentation #344 6656b81
  • Proper displacement in the reports for non-TypeScript files #343 c503510

3.1.0

New rules

  • angular-whitespace: [true, "check-interpolation", "check-pipe"] - Checks if there's whitespace around an expression surrounded by interpolation characters, and after a pipe symbol.
  • banana-in-box: true - Checks for proper banana in a box syntax - [(ngModel)] instead of ([ngModel]).
  • templates-no-negated-async: true - Enforces (foo | async) === false, rather than !(foo | async), because of the initial falsy value emitted.
  • use-view-encapsulation: true - Enforces enabled view encapsulation.

Special thanks to @wKoza, @GregOnNet and @connor4312 for their contributions.

Features

  • Align to the template parser API of Angular compiler 4.1.0 #301 0fcdcd1
  • Align to the changes in the template parser API 4.1.3 #319 b608296
  • Rule for enforcing ViewEncapsulation #300 509c8d9. Big thanks to @GregOnNet.
  • Add a no-negated-async rule #332 0f0924d. Big thanks to @connor4312.
  • Enforce proper banana in a box syntax #331 f95b2d5
  • Ensure whitespace around interpolation #320 335776f

Bug Fixes

  • Template micro-syntax closure and 'bind only to public class members' #220 61f9fe9
  • Report warnings when bound to private iterable in *ngFor #306 36705fc
  • 'templates-use-public' throws error when attempting to access a property of a property with the [] syntax #315 6323d2c
  • no-access-missing-member doesn't work with external HTML #311 b608296
  • rules name in documentation aren't consistent #325 7a67607. Big thanks to @wKoza.
  • Our links to angular.io are broken #333 5a532b4. Big thanks to @wKoza.
  • Report errors twice #336 44a9306

3.0.1

Bug Fixes

3.0.0

Major release required because of the breaking changes introduced by tslint@5. The ngast support will be pushed to codelyzer@4.

Features

  • Support for tslint@5 #281 01bffd5 49b1e80
  • Allow more than one selector kind of directives & components #290 4fa35f6
    "directive-selector": [true, ["attribute", "element"], "sg", "camelCase"],
    "component-selector": [true, ["element", "attribute"], "sg", "kebab-case"],
  • Specs for the support of as syntax in expressions #289 a7500cb

Refactoring

  • Rename ng2Walker to ngWalker 01bffd5
  • Refactor selector-related rules to depend on less mutable state 4fa35f6

2.1.1

Bug Fixes

  • Breaking change in the TypeScript AST regarding importDestructuringSpacingRule #282 eebf10a

2.1.0

Features

  • Automatic removal of dead styles (experimental) #244 30f2667
  • Warning for the deprecated <template> element #280 0d0e81c
  • Rise a warning if given class implements PipeTransform but is not decorated with @Pipe #104 638e72f

Bug Fixes

  • no-unused-css ignores elements with structural directives #249 0aff6b7
  • Improve position to line & character and line & character to position #245 30f2667

3.0.0-beta.4

Features

  • Support for Angular 4.0.0-rc.5 & ngast 0.0.15 #270 35aa900

3.0.0-beta.3

Bug Fixes

  • Update peerDependency ngast to version ^0.0.6 #257 30e921a.

3.0.0-beta.2

Bug Fixes

  • Update peerDependency ngast to version ^0.0.4 #257 30e921a.

3.0.0-beta.1

Features

  • Deep metadata collection with ngast ✨ 🎆 ✨ #217 de13ceb
  • Built-in support for template references.

Bug Fixes

  • Access to inline template objects results in "no-access-missing-member" rule being triggerred #231 d10e980
  • no-access-missing-member and async pipe #190 de13ceb

3.0.0-beta.0

Breaking Changes

  • Remove importDestructuringSpacing. Can be enforced with the tslint's rule whitespace.
  • no-access-missing-member, use-life-cycle-interface and template-use-public require type checking which means that tslint should be run with the corresponding options

The rules should now be run as follows:

$ tslint --type-check --project src/client/tsconfig.json

Features

  • no-access-missing-member support for inheritance #191 2901718
  • use-life-cycle-interface support for inheritance #64 d0d7138
  • template-use-public support for inheritance #240 2e285e2

2.0.1

Features

Bug Fixes

  • Fix semantic error when declaration's generation is enabled #221 c694405
  • Inconsistent links to the style guide sections #233 c9e87f6

2.0.0

Bug Fixes

  • The rule for binding to publich members breaks for readonly properties #206 cc3ed9a
  • Add checks for ngIf and ngSwitch #193 0118b56
  • Support for tslint@^4.3.1 (4.3.0 was broken) 3e7edfa
  • Support for Angular 4 #214 4d79933

Refactoring

  • Refactoring readTemplate and readStyle to use Maybe<T> 373b152

2.0.0-beta.4

Features

  • Allow multiple suffixes for better compatibility with Ionic #194 08fdaf0
  • Add declarations of frequiently used directive declarations #199 36f5cb4
  • Support for Angular 2.4.x #201 ad81f2d
  • Support for tslint@^4.1.0 #204 13b722e

Bug Fixes

  • Warn when component element selector doesn't have a dash #192 36f5cb4

2.0.0-beta.3

Bug Fixes

  • Restrict peerDependencies to Angular <=2.3 >=2.2.0 #188 08a0029

2.0.0-beta.2

Features

Bug Fixes

2.0.0-beta.1

Breaking Changes

  • The rules directive-selector-name, component-selector-name, directive-selector-type, component-selector-type, component-selector-prefix, directive-selector-prefix no longer exist. Instead use:

    // The rule have the following arguments:
    // [ENABLED, "attribute" | "element", "selectorPrefix" | ["listOfPrefixes"], "camelCase" | "kebab-case"]
    "directive-selector": [true, "attribute", "sg", "camelCase"],
    "component-selector": [true, "element", "sg", "kebab-case"],

Features

  • External template support via command line interface. Note that the VSCode tslint plugin cannot report warnings in CSS and HTML files yet #94 67d5a07
  • Support for custom hooks for transpilation of languages which transpile to HTML, CSS #164 1ca7068
  • Source map support. You can have pug templates and get error reporting in the correct position if inside of the hook you return not only the transpiled version of the template but also the source map 1ca7068
  • Optional configuration file .codelyzer.js which should be located in the root of your project (the directory where node_modules is) 1ca7068
  • Support for tslint ^4.0.0 #157 8c5dbf6
  • Improve no-unused-css 0a9d9014

Bug Fixes

  • Do not throw error when validating @Pipes without metadata #111 eb6ccc0d
  • Use proper syntax types for TypeScript 2.1.x #145 d49cc26
  • More consistent naming for selector-related rules #79 3373dff
  • Support for templateRefs #151 52ba382
  • Support for properties declared inline into the constructor #153 23fe633
  • Report missing styles in the correct position #166 e9575fb
  • Proper selector prefix matching #103 7285121
  • Selectors compatible with the spec #15 3373dffe

1.0.0-beta.4

Bug Fixes

  • Migrate to the compiler API changes introduced by Angular 2.2 #152 fe3083b

1.0.0-beta.3

Features

  • Introduce support for unused CSS styles in components.

Bug Fixes

  • Migrate to API changes introduced by Angular 2.1.1 #128 787ff3b.
  • Do not consider $event as non-declared variable #129 8751184.
  • Consider template variables such as let foo of bars #123 cbd86e1.
  • Consider getters and setters when listing all the declared in controller symbols #118 6060ce0.

1.0.0-beta.2

Bug Fixes

  • Migrate to the compiler API changes introduced by Angular 2.1.

1.0.0-beta.1

Features

Bug Fixes

  • Do not process webpack dynamically injected templates #106 ff2dc85.
  • Do not process @Component decorators which are not invoked as expressions #110 5ee2422
  • Preserve the original interpolation expression #99 5ee2422.
  • Consider both property access and method invocation when deciding if property is used or not #97 da15305.
  • Migrate to the changes introduced by Angular 2.0.2 #107 06483ce.

1.0.0-beta.0

Features

  • Linting over inline templates #90 4347d09.
  • Use Injectable() instead of Injectable #70 c84df93.
  • Show warning when binding to non-public class members #87 c849808.
  • Support for TypeScript 2.1.0 #72 a002661.

Bug Fixes

  • On non-implemented life-cycle hook/PipeTransform interface, mark only the corresponding method #89 a9104b2.
  • Do not throw error when interface is implemented but under a namespace #91 a9104b2.

Refactoring

  • Migrate from typings to @types f9cc498.