david-shortman / eslint-plugin-ngrx

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

eslint-plugin-ngrx

Installation

With ng-add

Install and configure the ESLint NgRx Plugin with the ng-add command. This command:

  • adds ngrx-eslint-plugin as a dev dependency;
  • adds the plugin to the ESLint plugins property;
  • adds the recommended config to the extends property of ESLint;
ng add ngrx-eslint-plugin

Manual

Install ESLint TypeScript parser

npm install @typescript-eslint/parser --save-dev

Install eslint-plugin-ngrx package

npm install eslint-plugin-ngrx --save-dev

Next, add eslint-plugin-ngrx to your ESLint config (for example in .eslintrc.js) and configure parser and parserOptions.

{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": 2019,
    "project": "./tsconfig.json",
    "sourceType": "module"
  },
  "plugins": ["ngrx"],
  "rules": {
    "ngrx/select-style": "error"
  }
}

To enable the recommended configuration, add it to your ESLint configuration file.

{
  "extends": ["plugin:ngrx/recommended"]
}

Rules

effects

Name Description Recommended Category Fixable Configurable
ngrx/no-dispatch-in-effects An Effect should not call store.dispatch suggestion warn (Possible Errors) No No
ngrx/no-effect-decorator-and-creator An Effect should only use the effect creator (createEffect) or the effect decorator (@Effect), but not both simultaneously problem error (Possible Errors) No No
ngrx/no-effect-decorator The createEffect creator function is preferred problem warn (Best Practices) Yes No
ngrx/no-effects-in-providers An Effect should not be listed as a provider if it is added to the EffectsModule problem error (Possible Errors) No No
ngrx/no-multiple-actions-in-effects An Effect should not return multiple actions. problem warn (Best Practices) No No
ngrx/prefer-concat-latest-from Use concatLatestFrom instead of withLatestFrom to prevent the selector from firing until the correct action is dispatched. suggestion warn (Possible Errors) Yes No
ngrx/prefer-effect-callback-in-block-statement A block statement is easier to troubleshoot. suggestion warn (Best Practices) Yes No
ngrx/use-effects-lifecycle-interface Ensures classes implement lifecycle interfaces corresponding to the declared lifecycle methods suggestion warn (Best Practices) Yes No
rxjs/no-cyclic-action Forbids effects that re-emit filtered actions. problem error (Possible Errors) No No
rxjs/no-unsafe-catch Forbids unsafe catchError usage in effects. problem error (Possible Errors) No No
rxjs/no-unsafe-first Forbids unsafe first/take usage in effects. problem error (Possible Errors) No No
rxjs/no-unsafe-switchmap Forbids unsafe switchMap usage in effects. problem error (Possible Errors) No No

store

Name Description Recommended Category Fixable Configurable
ngrx/avoid-combining-selectors Prefer combining selectors at the selector level with createSelector suggestion warn (Best Practices) No No
ngrx/avoid-dispatching-multiple-actions-sequentially It is recommended to only dispatch one action at a time. problem warn (Best Practices) No No
ngrx/avoid-mapping-selectors Avoid to add mapping logic in the component, instead move that logic in the projector method of createSelector. suggestion warn (Best Practices) No No
ngrx/good-action-hygiene Enforces the use of good action hygiene. suggestion warn (Best Practices) No No
ngrx/no-multiple-global-stores There should only be one global store injected suggestion warn (Best Practices) No No
ngrx/no-reducer-in-key-names Avoid the word "reducer" in the reducer key names suggestion warn (Best Practices) No No
ngrx/no-typed-global-store The global store should not be typed. suggestion warn (Best Practices) Yes No
ngrx/on-function-explicit-return-type On function should have an explicit return type problem warn (Possible Errors) No No
ngrx/prefer-inline-action-props Prefer using inline types instead of interfaces/classes. suggestion warn (Best Practices) No No
ngrx/select-style Selectors can be used either with 'select' as a pipeable operator or as a method problem warn (Best Practices) No Yes
ngrx/use-selector-in-select Using a selector in a select method is preferred in favor of strings or props drilling suggestion warn (Best Practices) No No

Configurations

Name Description
recommended The recommended config
store Only the recommended global store config
effects Only the recommended effects config
all All rules are enabled
strict All rules are enable and give errors

Migrating from ngrx-tslint-rules

If you were previously using TSLint for your project and especially the ngrx-tslint-rules package, you should check out the migration guide. You will find out how to replace the previous TSLint rule names by the new ESLint ones.

Contributors

Thanks goes to these wonderful people (emoji key):


Tim Deschryver

๐Ÿ’ป ๐Ÿค” ๐Ÿš‡ โš ๏ธ

Julien Saguet

๐Ÿ’ป โš ๏ธ ๐Ÿค” ๐Ÿ“–

Stephen Cooper

๐Ÿค”

Chris Paton

๐Ÿ’ป

Sebastian Weigel

๐Ÿ’ป

Rafael Santana

๐Ÿค” ๐Ÿ’ป โš ๏ธ

Armen Vardanyan

๐Ÿ“–

Michaรซl De Boey

๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!

About

License:Other


Languages

Language:TypeScript 98.9%Language:JavaScript 1.1%