Skip to content

Commit 3c7527e

Browse files
committed
Create doc of prefer-collections-with-pagination
1 parent 5b263ab commit 3c7527e

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

eslint-plugin/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ to have more information about the integration.
6565
⚠️ Configurations set to warn in.\
6666
✅ Set in the `recommended` configuration.
6767

68-
| Name | Description | ⚠️ |
69-
| :----------------------------------------------------------------------------- | :-------------------------------------------- | :- |
70-
| [no-multiple-access-dom-element](docs/rules/no-multiple-access-dom-element.md) | Disallow multiple access of same DOM element. ||
68+
| Name | Description | ⚠️ |
69+
| :------------------------------------------------------------------------------------- | :-------------------------------------------- | :- |
70+
| [no-multiple-access-dom-element](docs/rules/no-multiple-access-dom-element.md) | Disallow multiple access of same DOM element. ||
71+
| [prefer-collections-with-pagination](docs/rules/prefer-collections-with-pagination.md) | Prefer API collections with pagination ||
7172

7273
<!-- end auto-generated rules list -->
7374

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Prefer API collections with pagination (`@ecocode/prefer-collections-with-pagination`)
2+
3+
⚠️ This rule _warns_ in the ✅ `recommended` config.
4+
5+
<!-- end auto-generated rule header -->
6+
7+
## Rule details
8+
9+
This rule aims to reduce the size and thus the network weight of API returns that may contain many elements. This rule
10+
is built for the NestJS framework but can work with a controller @Controller() and a decorated method @Get().
11+
12+
## Examples
13+
14+
Examples of **incorrect** code for this rule:
15+
16+
```ts
17+
@Controller()
18+
class Test {
19+
@Get()
20+
public find(): Promise<string[]> {
21+
}
22+
}
23+
```
24+
25+
Examples of **correct** code for this rule:
26+
27+
```ts
28+
interface Pagination {
29+
items: string[];
30+
currentPage: number;
31+
totalPages: number;
32+
}
33+
34+
@Controller()
35+
class Test {
36+
@Get()
37+
public find(): Promise<Pagination> {
38+
}
39+
}
40+
```

eslint-plugin/lib/rules/prefer-collections-with-pagination.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const rule = createRule({
6363
name: "prefer-collections-with-pagination",
6464
meta: {
6565
docs: {
66-
description: "TODO",
66+
description: "Prefer API collections with pagination",
6767
category: "eco-design",
6868
recommended: "warn",
6969
},

0 commit comments

Comments
 (0)