Install and configure the ESLint NgRx Plugin with the ng-add
command.
This command:
- adds
eslint-plugin-ngrx
as a dev dependency; - adds the plugin to the ESLint plugins property;
- adds the recommended config to the
extends
property of ESLint;
ng add eslint-plugin-ngrx
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"]
}
Name | Description | Recommended | Category | Fixable | Has suggestions | Configurable | Requires type information |
---|---|---|---|---|---|---|---|
ngrx/updater-explicit-return-type | Updater should have an explicit return type. |
problem | warn (Possible Errors) | No | No | No | No |
Name | Description | Recommended | Category | Fixable | Has suggestions | Configurable | Requires type information |
---|---|---|---|---|---|---|---|
ngrx/avoid-cyclic-effects | Avoid effects that re-emit filtered actions. | suggestion | error (Possible Errors) | No | No | No | Yes |
ngrx/no-dispatch-in-effects | An Effect should not call store.dispatch . |
suggestion | warn (Possible Errors) | Yes | Yes | 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) | Yes | Yes | No | No |
ngrx/no-effect-decorator | The createEffect creator function is preferred. |
problem | warn (Best Practices) | Yes | Yes | No | 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) | Yes | No | No | No |
ngrx/no-multiple-actions-in-effects | An Effect should not return multiple actions. |
problem | warn (Best Practices) | No | No | No | Yes |
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) | No | Yes | No | No |
ngrx/prefer-effect-callback-in-block-statement | A block statement is easier to troubleshoot. | suggestion | warn (Best Practices) | Yes | No | No | No |
ngrx/use-effects-lifecycle-interface | Ensures classes implement lifecycle interfaces corresponding to the declared lifecycle methods. | suggestion | warn (Best Practices) | Yes | No | 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 |
Name | Description | Recommended | Category | Fixable | Has suggestions | Configurable | Requires type information |
---|---|---|---|---|---|---|---|
ngrx/avoid-combining-selectors | Prefer combining selectors at the selector level with createSelector . |
suggestion | warn (Best Practices) | No | No | 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 | No | No |
ngrx/avoid-duplicate-actions-in-reducer | A Reducer should handle an Action once. |
problem | warn (Best Practices) | No | Yes | 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 | No | No |
ngrx/good-action-hygiene | Enforces the use of good action hygiene. | suggestion | warn (Best Practices) | No | No | No | No |
ngrx/no-multiple-global-stores | There should only be one global store injected. | suggestion | warn (Best Practices) | No | Yes | No | No |
ngrx/no-reducer-in-key-names | Avoid the word "reducer" in the key names. | suggestion | warn (Best Practices) | No | Yes | No | No |
ngrx/no-store-subscription | Don't create a store subscription, prefer to use the async pipe. | suggestion | warn (Best Practices) | No | No | No | No |
ngrx/no-typed-global-store | The global store should not be typed. | suggestion | warn (Best Practices) | No | Yes | No | No |
ngrx/on-function-explicit-return-type | On function should have an explicit return type. | problem | warn (Possible Errors) | No | Yes | No | No |
ngrx/prefer-inline-action-props | Prefer using inline types instead of interfaces/classes. | suggestion | warn (Best Practices) | No | Yes | No | No |
ngrx/prefer-one-generic-in-create-for-feature-selector | Prefer using a single generic to define the feature state. | suggestion | warn (Best Practices) | No | Yes | No | No |
ngrx/prefix-selectors-with-select | The selector should start with "select", for example "selectThing". | suggestion | warn (Best Practices) | No | Yes | No | No |
ngrx/select-style | Selectors can be used either with select as a pipeable operator or as a method. |
problem | warn (Best Practices) | Yes | No | Yes | No |
ngrx/use-consistent-global-store-name | Use a consistent name for the global store. | suggestion | warn (Best Practices) | No | Yes | Yes | No |
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 | No | No |
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 |
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.
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!