Skip to content

Commit ba04293

Browse files
build: update ESLint new docs (#4853)
1 parent 85680a0 commit ba04293

File tree

14 files changed

+70
-71
lines changed

14 files changed

+70
-71
lines changed

modules/eslint-plugin/scripts/generate-docs.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,25 @@ import { rulesForGenerate } from '../src/utils/helper-functions/rules';
55

66
const prettierConfig = resolveConfig.sync(__dirname);
77
const PLACEHOLDER = '<!-- MANUAL-DOC:START -->';
8-
const RULES_PATH = './projects/ngrx.io/content/guide/eslint-plugin/rules';
9-
10-
for (const [ruleName, { meta }] of Object.entries(rulesForGenerate)) {
11-
const docPath = path.join(RULES_PATH, `${ruleName}.md`);
12-
if (!existsSync(docPath)) {
13-
writeFileSync(docPath, ``);
14-
}
15-
const doc = readFileSync(docPath, 'utf-8');
16-
const docContent = doc.substring(
17-
doc.indexOf(PLACEHOLDER) + PLACEHOLDER.length
18-
);
19-
const newDoc = format(
20-
`# ${ruleName}
8+
const RULES_PATHS = [
9+
'./projects/ngrx.io/content/guide/eslint-plugin/rules',
10+
'./projects/www/src/app/pages/guide/eslint-plugin/rules',
11+
];
12+
13+
for (const rules of RULES_PATHS) {
14+
for (const [ruleName, { meta }] of Object.entries(rulesForGenerate)) {
15+
const docPath = path.join(rules, `${ruleName}.md`);
16+
if (!existsSync(docPath)) {
17+
writeFileSync(docPath, ``);
18+
}
19+
const doc = readFileSync(docPath, 'utf-8');
20+
const docContent = doc.substring(
21+
doc.indexOf(PLACEHOLDER) + PLACEHOLDER.length
22+
);
23+
const newDoc = format(
24+
`# ${ruleName}
2125
22-
${meta.version ? '> Required NgRx Version Range: ${meta.version}' : ''}
26+
${meta.version ? '> Required NgRx Version Range: ${meta.version}' : ''}
2327
2428
${meta.docs?.description}
2529
@@ -28,18 +32,19 @@ ${meta.docs?.description}
2832
- **Suggestion**: ${meta.hasSuggestions ? 'Yes' : 'No'}
2933
- **Requires type checking**: ${meta.docs?.requiresTypeChecking ? 'Yes' : 'No'}
3034
- **Configurable**: ${
31-
Array.isArray(meta.schema) && meta.schema.length ? 'Yes' : 'No'
32-
}
35+
Array.isArray(meta.schema) && meta.schema.length ? 'Yes' : 'No'
36+
}
3337
3438
<!-- Everything above this generated, do not edit -->
3539
<!-- MANUAL-DOC:START -->
3640
3741
${docContent}`,
38-
{
39-
parser: 'markdown',
40-
...prettierConfig,
41-
}
42-
);
42+
{
43+
parser: 'markdown',
44+
...prettierConfig,
45+
}
46+
);
4347

44-
writeFileSync(docPath, newDoc);
48+
writeFileSync(docPath, newDoc);
49+
}
4550
}

modules/eslint-plugin/src/configs/all.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
"@ngrx/prefer-effect-callback-in-block-statement": "error",
1515
"@ngrx/use-effects-lifecycle-interface": "error",
1616
"@ngrx/prefer-concat-latest-from": "error",
17+
"@ngrx/enforce-type-call": "error",
1718
"@ngrx/prefer-protected-state": "error",
1819
"@ngrx/signal-state-no-arrays-at-root-level": "error",
1920
"@ngrx/signal-store-feature-should-use-generic-type": "error",
2021
"@ngrx/with-state-no-arrays-at-root-level": "error",
21-
"@ngrx/enforce-type-call": "error",
2222
"@ngrx/avoid-combining-selectors": "error",
2323
"@ngrx/avoid-dispatching-multiple-actions-sequentially": "error",
2424
"@ngrx/avoid-duplicate-actions-in-reducer": "error",

modules/eslint-plugin/src/configs/all.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export default (
4242
'@ngrx/prefer-effect-callback-in-block-statement': 'error',
4343
'@ngrx/use-effects-lifecycle-interface': 'error',
4444
'@ngrx/prefer-concat-latest-from': 'error',
45+
'@ngrx/enforce-type-call': 'error',
4546
'@ngrx/prefer-protected-state': 'error',
4647
'@ngrx/signal-state-no-arrays-at-root-level': 'error',
4748
'@ngrx/signal-store-feature-should-use-generic-type': 'error',
@@ -64,7 +65,6 @@ export default (
6465
'@ngrx/prefix-selectors-with-select': 'error',
6566
'@ngrx/select-style': 'error',
6667
'@ngrx/use-consistent-global-store-name': 'error',
67-
'@ngrx/enforce-type-call': 'error',
6868
},
6969
},
7070
];

modules/eslint-plugin/src/configs/signals.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"parser": "@typescript-eslint/parser",
33
"plugins": ["@ngrx"],
44
"rules": {
5+
"@ngrx/enforce-type-call": "error",
56
"@ngrx/prefer-protected-state": "error",
67
"@ngrx/signal-state-no-arrays-at-root-level": "error",
78
"@ngrx/signal-store-feature-should-use-generic-type": "error",
8-
"@ngrx/with-state-no-arrays-at-root-level": "error",
9-
"@ngrx/enforce-type-call": "error"
9+
"@ngrx/with-state-no-arrays-at-root-level": "error"
1010
},
1111
"parserOptions": {
1212
"ecmaVersion": 2020,

modules/eslint-plugin/src/configs/signals.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default (
3030
},
3131
},
3232
rules: {
33+
'@ngrx/enforce-type-call': 'error',
3334
'@ngrx/prefer-protected-state': 'error',
3435
'@ngrx/signal-state-no-arrays-at-root-level': 'error',
3536
'@ngrx/signal-store-feature-should-use-generic-type': 'error',

projects/ngrx.io/content/guide/eslint-plugin/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ module.exports = tseslint.config({
126126

127127
| Name | Description | Category | Fixable | Has suggestions | Configurable | Requires type information |
128128
| ----------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | ---------- | ------- | --------------- | ------------ | ------------------------- |
129+
| [@ngrx/enforce-type-call](/guide/eslint-plugin/rules/enforce-type-call) | The `type` function must be called. | problem | Yes | No | No | No |
129130
| [@ngrx/prefer-protected-state](/guide/eslint-plugin/rules/prefer-protected-state) | A Signal Store prefers protected state | suggestion | No | Yes | No | No |
130131
| [@ngrx/signal-state-no-arrays-at-root-level](/guide/eslint-plugin/rules/signal-state-no-arrays-at-root-level) | signalState should accept a record or dictionary as an input argument. | problem | No | No | No | No |
131132
| [@ngrx/signal-store-feature-should-use-generic-type](/guide/eslint-plugin/rules/signal-store-feature-should-use-generic-type) | A custom Signal Store feature that accepts an input should define a generic type. | problem | Yes | No | No | No |

projects/ngrx.io/content/guide/eslint-plugin/rules/enforce-type-call.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# enforce-type-call
22

3-
The `type` function from `@ngrx/signals` must be called.
3+
The `type` function must be called.
44

55
- **Type**: problem
66
- **Fixable**: Yes
7-
- **Suggestion**: Yes
7+
- **Suggestion**: No
88
- **Requires type checking**: No
99
- **Configurable**: No
1010

projects/ngrx.io/content/guide/eslint-plugin/rules/no-dispatch-in-effects.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ export class Effects {
6767
ofType(loadDataSuccess),
6868
filter((response) => response.condition),
6969
exhaustMap(() =>
70-
this.dataService.getOtherData().pipe(
71-
map((data) => anotherAction(data)),
70+
this.dataService.getOtherData().pipe(
71+
map((data) => anotherAction(data)),
7272
catchError((error) => of(handleConditionError(error)))
7373
)
7474
)
Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# prefer-protected-state
22

3-
A Signal Store prefers protected state.
3+
A Signal Store prefers protected state
44

55
- **Type**: suggestion
66
- **Fixable**: No
@@ -18,23 +18,15 @@ This rule ensures that state changes are only managed by the Signal Store to pre
1818
Examples of **incorrect** code for this rule:
1919

2020
```ts
21-
const Store = signalStore(
22-
{ protectedState: false },
23-
withState({}),
24-
);
21+
const Store = signalStore({ protectedState: false }, withState({}));
2522
```
2623

2724
Examples of **correct** code for this rule:
2825

2926
```ts
30-
const Store = signalStore(
31-
withState({}),
32-
);
27+
const Store = signalStore(withState({}));
3328
```
3429

3530
```ts
36-
const Store = signalStore(
37-
{ protectedState: true },
38-
withState({}),
39-
);
31+
const Store = signalStore({ protectedState: true }, withState({}));
4032
```

projects/ngrx.io/content/guide/eslint-plugin/rules/require-super-ondestroy.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ Example of **incorrect** code for this rule:
1919

2020
```ts
2121
@Injectable()
22-
export class BooksStore extends ComponentStore<BooksState> implements OnDestroy
22+
export class BooksStore
23+
extends ComponentStore<BooksState>
24+
implements OnDestroy
2325
{
2426
// ... other BooksStore class members
2527

@@ -33,7 +35,9 @@ Example of **correct** code for this rule:
3335

3436
```ts
3537
@Injectable()
36-
export class BooksStore extends ComponentStore<BooksState> implements OnDestroy
38+
export class BooksStore
39+
extends ComponentStore<BooksState>
40+
implements OnDestroy
3741
{
3842
// ... other BooksStore class members
3943

0 commit comments

Comments
 (0)