Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Commit 7d43270

Browse files
committed
docs: add rule docs
1 parent eea4673 commit 7d43270

File tree

2 files changed

+135
-0
lines changed

2 files changed

+135
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import RuleDetails from '@site/src/components/RuleDetails';
2+
3+
<RuleDetails version="5.3.0" severity="warning" />
4+
5+
Warns when a field is not added to `props` getter of a class that extends `Equtable` or `EquatableMixin`.
6+
7+
:::info
8+
9+
This rule is specific to [`equatable` package](https://pub.dev/packages/equatable). Enable it only if you use this package.
10+
11+
:::
12+
13+
### Example {#example}
14+
15+
**❌ Bad:**
16+
17+
```dart
18+
class AnotherPerson extends Equatable {
19+
const AnotherPerson(this.name, this.age);
20+
21+
final String name;
22+
23+
final int age;
24+
25+
@override
26+
List<Object> get props => [name]; // LINT
27+
}
28+
29+
class AndAnotherPerson extends Equatable {
30+
static final someProp = 'hello';
31+
32+
const AndAnotherPerson(this.name);
33+
34+
final String name;
35+
36+
@override
37+
List<Object> get props => [name];
38+
}
39+
40+
class SubPerson extends AndAnotherPerson {
41+
const SubPerson(this.value, String name) : super();
42+
43+
final int value;
44+
45+
@override
46+
List<Object> get props {
47+
return super.props..addAll([]); // LINT
48+
}
49+
}
50+
51+
class EquatableDateTimeSubclass extends EquatableDateTime {
52+
final int century;
53+
54+
EquatableDateTimeSubclass(
55+
this.century,
56+
int year, [
57+
int month = 1,
58+
int day = 1,
59+
int hour = 0,
60+
int minute = 0,
61+
int second = 0,
62+
int millisecond = 0,
63+
int microsecond = 0,
64+
]) : super(year, month, day, hour, minute, second, millisecond, microsecond);
65+
66+
@override
67+
List<Object> get props => super.props..addAll([]); // LINT
68+
}
69+
```
70+
71+
**✅ Good:**
72+
73+
```dart
74+
class AnotherPerson extends Equatable {
75+
const AnotherPerson(this.name, this.age);
76+
77+
final String name;
78+
79+
final int age;
80+
81+
@override
82+
List<Object> get props => [name, age];
83+
}
84+
85+
class AndAnotherPerson extends Equatable {
86+
static final someProp = 'hello';
87+
88+
const AndAnotherPerson(this.name);
89+
90+
final String name;
91+
92+
@override
93+
List<Object> get props => [name];
94+
}
95+
96+
class SubPerson extends AndAnotherPerson {
97+
const SubPerson(this.value, String name) : super();
98+
99+
final int value;
100+
101+
@override
102+
List<Object> get props {
103+
return super.props..addAll([value]);
104+
}
105+
}
106+
107+
class EquatableDateTimeSubclass extends EquatableDateTime {
108+
final int century;
109+
110+
EquatableDateTimeSubclass(
111+
this.century,
112+
int year, [
113+
int month = 1,
114+
int day = 1,
115+
int hour = 0,
116+
int minute = 0,
117+
int second = 0,
118+
int millisecond = 0,
119+
int microsecond = 0,
120+
]) : super(year, month, day, hour, minute, second, millisecond, microsecond);
121+
122+
@override
123+
List<Object> get props => super.props..addAll([century]);
124+
}
125+
```

website/docs/rules/index.mdx

+10
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,16 @@ Rules are grouped by category to help you understand their purpose. Each rule ha
281281
Prefer format comments like sentences.
282282
</RuleEntry>
283283

284+
<RuleEntry
285+
name="list-all-equatable-fields"
286+
type="common"
287+
severity="warning"
288+
version="5.3.0"
289+
>
290+
Warns when a field is not added to <code>props</code> getter of a class that
291+
extends <code>Equtable</code> or <code>EquatableMixin</code>.
292+
</RuleEntry>
293+
284294
<RuleEntry
285295
name="member-ordering"
286296
type="common"

0 commit comments

Comments
 (0)