From 0a7d5ea6c871159ce8bb5563636e8df90fba2af6 Mon Sep 17 00:00:00 2001 From: Stephen Cooper Date: Fri, 29 May 2020 14:55:14 +0100 Subject: [PATCH] update readme --- README.md | 21 +++++++++++++++++-- .../fixture.ts.lint | 8 +++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4277b5f..864d29f 100755 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Next, add `ngrx-tslint-rules` to your `tslint.json` file, and the rules to the ` } ``` -To enable all rules, use the `recommended` configuration file. +To enable all recommended rules, use the `recommended` configuration file. ```json { @@ -42,7 +42,7 @@ To enable all rules, use the `recommended` configuration file. > The recommended rules also export the rules from [rxjs-tslint-rules](https://github.com/cartant/rxjs-tslint-rules) that can be applied to NgRx -## Rules +## Recommend Rules > By default all rules are enabled @@ -61,6 +61,23 @@ To enable all rules, use the `recommended` configuration file. | ngrx-no-typed-store | A store should not be typed | [Example](https://github.com/timdeschryver/ngrx-tslint-rules/tree/master/test/rules/ngrx-no-typed-store/fixture.ts.lint) | | ngrx-selector-for-select | Using string or props drilling is not preferred, use a selector instead | [Example](https://github.com/timdeschryver/ngrx-tslint-rules/tree/master/test/rules/ngrx-selector-for-select/fixture.ts.lint) | +## Optional Rules + +To enable optional rules add them to the `rules` section in your `tslint.json` file. + +```json +{ + "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](https://github.com/timdeschryver/ngrx-tslint-rules/tree/master/test/rules/ngrx-on-reducer-explicit-return-type/fixture.ts.lint) | + ## License MIT diff --git a/test/rules/ngrx-on-reducer-explicit-return-type/fixture.ts.lint b/test/rules/ngrx-on-reducer-explicit-return-type/fixture.ts.lint index d3f3fd7..55e096c 100644 --- a/test/rules/ngrx-on-reducer-explicit-return-type/fixture.ts.lint +++ b/test/rules/ngrx-on-reducer-explicit-return-type/fixture.ts.lint @@ -18,7 +18,7 @@ function increaseFunc(state: State, value: number): State { const reducer = createReducer( initialState, - // No explicit return type when no action props + // No explicit return type defined means values can be assigned to non-existent properties. on(increment, s => ({ ~~~~~~~ ...s, @@ -34,12 +34,12 @@ const reducer = createReducer( counter: s.counter + 1, }), ), - // Do not require functions to have an explicit return type defined in on method + // Do not require functions to have an explicit return type as likely that the function is typed on(increment, incrementFunc), on(increment, s => incrementFunc(s)), on(increment, (s): State => incrementFunc(s)), - // No explicit return type when action has props + // No explicit return type on(increase, (s, action) => ({ ~~~~~~~~~~~~~~~~~ ...s, @@ -55,7 +55,7 @@ on( counter: s.counter + action.value, }), ), -// No explicit return type when action has props and deconstructed +// No explicit return type on(increase, (s, { value }) => ({ ~~~~~~~~~~~~~~~~~~~~ ...s,