Skip to content
This repository has been archived by the owner on May 23, 2021. It is now read-only.

timdeschryver/ngrx-tslint-rules

Repository files navigation

The NgRx TSLint Plugin has been deprecated in favor of the ESLint version. See, eslint-plugin-ngrx for more info and a migrate guideline.

ngrx-tslint-rules

Installation

Using the Angular CLI

Use the ng-add command from the Angular CLI to be guided with the installation. We'll ask you for which rules you want to enable.

ng add ngrx-tslint-rules

Manual install with npm or yarn

First install ngrx-tslint-rules as a dependency with the following command.

npm install ngrx-tslint-rules --save-dev

Next, add ngrx-tslint-rules to your tslint.json file, and the rules to the rules config.

{
  "extends": ["ngrx-tslint-rules"],
  "rules": {
    ...
  }
}

To enable all recommended rules, use the recommended configuration file.

{
  "extends": ["ngrx-tslint-rules/recommended"]
}

The recommended rules also export the rules from rxjs-tslint-rules that can be applied to NgRx

Recommend Rules

By default all rules are enabled

Rule Description Examples
ngrx-action-hygiene Enforces the use of good action hygiene Example
ngrx-avoid-dispatching-multiple-actions-sequentially It is recommended to only dispatch one action at a time Example
ngrx-effect-creator-and-decorator An Effect should only use the effect creator (createEffect) or the Effect decorator (@Effect), but not both simultaneously Example
ngrx-no-dispatch-in-effects An Effect should not call store.dispatch, but should return an action Example
ngrx-no-duplicate-action-types An action type must be unique Example
ngrx-no-effect-decorator The createEffect creator function is preferred Example
ngrx-no-effects-in-providers The Effect should not be listed as a provider if it is added to the EffectsModule Example
ngrx-no-multiple-actions-in-effects An Effect should not return multiple actions Example
ngrx-no-multiple-stores Store should at most be one time injected Example
ngrx-no-reducer-in-key-names Avoid the word "reducer" in the key names Example
ngrx-no-typed-store A store should not be typed Example
ngrx-selector-for-select Using string or props drilling is not preferred, use a selector instead Example

Optional Rules

To enable optional rules add them to the rules section in your tslint.json file.

{
  "extends": ["ngrx-tslint-rules"],
  "rules": {
    "ngrx-on-reducer-explicit-return-type": true
  }
}
Rule Description Examples
ngrx-on-reducer-explicit-return-type Enforces type safety for on reducer callbacks Example

License

MIT