Skip to content

Commit 221ea98

Browse files
authored
Add allowTestedProperty option to property rules (#241)
1 parent d8bb76d commit 221ea98

File tree

457 files changed

+6676
-897
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

457 files changed

+6676
-897
lines changed

docs/index.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,43 @@ For example:
138138
// }
139139
}
140140
```
141+
142+
### The `allowTestedProperty` mode
143+
144+
This plugin has rules to report forbidden property accesses.
145+
These rules report all forbidden property accesses by default, but if you want to allow existence-tested properties in your scripts, you can use the `allowTestedProperty` mode.
146+
147+
<eslint-playground type="good">
148+
149+
```ts
150+
/*eslint es-x/no-string-prototype-trimstart-trimend: [error, { aggressive: true, allowTestedProperty: true }], es-x/no-string-prototype-trimleft-trimright: [error, { aggressive: true, allowTestedProperty: true }], */
151+
function trimEnd(str) {
152+
if (String.prototype.trimEnd) {
153+
return str.trimEnd();
154+
}
155+
if (String.prototype.trimRight) {
156+
return str.trimRight();
157+
}
158+
return str.replace(/\s+$/, "");
159+
}
160+
```
161+
162+
</eslint-playground>
163+
164+
If you configured the `allowTestedProperty` mode, this plugin will allow the use of tested properties.
165+
For example:
166+
167+
```json
168+
{
169+
"plugins": ["es-x"],
170+
"rules": {
171+
"es-x/no-string-prototype-trimstart-trimend": "error",
172+
"es-x/no-string-prototype-trimleft-trimright": "error"
173+
},
174+
175+
// `settings['es-x'].allowTestedProperty = true` means the allowTestedProperty mode.
176+
"settings": {
177+
"es-x": { "allowTestedProperty": true }
178+
}
179+
}
180+
```

docs/rules/no-array-from.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,28 @@ const array = Array.from("hello")
2424

2525
</eslint-playground>
2626

27+
## 🔧 Options
28+
29+
This rule has an option.
30+
31+
```jsonc
32+
{
33+
"rules": {
34+
"es-x/no-array-from": [
35+
"error",
36+
{
37+
"allowTestedProperty": false
38+
}
39+
]
40+
}
41+
}
42+
```
43+
44+
### allowTestedProperty: boolean
45+
46+
Configure the allowTestedProperty mode for only this rule.
47+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
48+
2749
## 🚀 Version
2850

2951
This rule was introduced in [eslint-plugin-es] v1.2.0.

docs/rules/no-array-isarray.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,28 @@ var array = Array.isArray(obj)
2424

2525
</eslint-playground>
2626

27+
## 🔧 Options
28+
29+
This rule has an option.
30+
31+
```jsonc
32+
{
33+
"rules": {
34+
"es-x/no-array-isarray": [
35+
"error",
36+
{
37+
"allowTestedProperty": false
38+
}
39+
]
40+
}
41+
}
42+
```
43+
44+
### allowTestedProperty: boolean
45+
46+
Configure the allowTestedProperty mode for only this rule.
47+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
48+
2749
## 🚀 Version
2850

2951
This rule was introduced in [eslint-plugin-es] v3.0.0.

docs/rules/no-array-of.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,28 @@ const array = Array.of(1, 2, 3)
2424

2525
</eslint-playground>
2626

27+
## 🔧 Options
28+
29+
This rule has an option.
30+
31+
```jsonc
32+
{
33+
"rules": {
34+
"es-x/no-array-of": [
35+
"error",
36+
{
37+
"allowTestedProperty": false
38+
}
39+
]
40+
}
41+
}
42+
```
43+
44+
### allowTestedProperty: boolean
45+
46+
Configure the allowTestedProperty mode for only this rule.
47+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
48+
2749
## 🚀 Version
2850

2951
This rule was introduced in [eslint-plugin-es] v1.2.0.

docs/rules/no-array-prototype-at.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,30 @@ This rule is silent by default because it's hard to know types. You need to conf
3030

3131
This rule has an option.
3232

33-
```yaml
34-
rules:
35-
es-x/no-array-prototype-at: [error, { aggressive: false }]
33+
```jsonc
34+
{
35+
"rules": {
36+
"es-x/no-array-prototype-at": [
37+
"error",
38+
{
39+
"aggressive": false,
40+
"allowTestedProperty": false
41+
}
42+
]
43+
}
44+
}
3645
```
3746

3847
### aggressive: boolean
3948

4049
Configure the aggressive mode for only this rule.
4150
This is prior to the `settings['es-x'].aggressive` setting.
4251

52+
### allowTestedProperty: boolean
53+
54+
Configure the allowTestedProperty mode for only this rule.
55+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
56+
4357
## 🚀 Version
4458

4559
This rule was introduced in v8.0.0.

docs/rules/no-array-prototype-copywithin.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,30 @@ foo.copyWithin(0, 1, 2)
3030

3131
This rule has an option.
3232

33-
```yaml
34-
rules:
35-
es-x/no-array-prototype-copywithin: [error, { aggressive: false }]
33+
```jsonc
34+
{
35+
"rules": {
36+
"es-x/no-array-prototype-copywithin": [
37+
"error",
38+
{
39+
"aggressive": false,
40+
"allowTestedProperty": false
41+
}
42+
]
43+
}
44+
}
3645
```
3746

3847
### aggressive: boolean
3948

4049
Configure the aggressive mode for only this rule.
4150
This is prior to the `settings['es-x'].aggressive` setting.
4251

52+
### allowTestedProperty: boolean
53+
54+
Configure the allowTestedProperty mode for only this rule.
55+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
56+
4357
## 🚀 Version
4458

4559
This rule was introduced in [eslint-plugin-es] v5.0.0.

docs/rules/no-array-prototype-entries.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,30 @@ foo.entries()
3030

3131
This rule has an option.
3232

33-
```yaml
34-
rules:
35-
es-x/no-array-prototype-entries: [error, { aggressive: false }]
33+
```jsonc
34+
{
35+
"rules": {
36+
"es-x/no-array-prototype-entries": [
37+
"error",
38+
{
39+
"aggressive": false,
40+
"allowTestedProperty": false
41+
}
42+
]
43+
}
44+
}
3645
```
3746

3847
### aggressive: boolean
3948

4049
Configure the aggressive mode for only this rule.
4150
This is prior to the `settings['es-x'].aggressive` setting.
4251

52+
### allowTestedProperty: boolean
53+
54+
Configure the allowTestedProperty mode for only this rule.
55+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
56+
4357
## 🚀 Version
4458

4559
This rule was introduced in [eslint-plugin-es] v5.0.0.

docs/rules/no-array-prototype-every.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,30 @@ foo.every(e => e !== 0)
3030

3131
This rule has an option.
3232

33-
```yaml
34-
rules:
35-
es-x/no-array-prototype-every: [error, { aggressive: false }]
33+
```jsonc
34+
{
35+
"rules": {
36+
"es-x/no-array-prototype-every": [
37+
"error",
38+
{
39+
"aggressive": false,
40+
"allowTestedProperty": false
41+
}
42+
]
43+
}
44+
}
3645
```
3746

3847
### aggressive: boolean
3948

4049
Configure the aggressive mode for only this rule.
4150
This is prior to the `settings['es-x'].aggressive` setting.
4251

52+
### allowTestedProperty: boolean
53+
54+
Configure the allowTestedProperty mode for only this rule.
55+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
56+
4357
## 🚀 Version
4458

4559
This rule was introduced in [eslint-plugin-es] v5.0.0.

docs/rules/no-array-prototype-fill.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,30 @@ foo.fill(0)
3030

3131
This rule has an option.
3232

33-
```yaml
34-
rules:
35-
es-x/no-array-prototype-fill: [error, { aggressive: false }]
33+
```jsonc
34+
{
35+
"rules": {
36+
"es-x/no-array-prototype-fill": [
37+
"error",
38+
{
39+
"aggressive": false,
40+
"allowTestedProperty": false
41+
}
42+
]
43+
}
44+
}
3645
```
3746

3847
### aggressive: boolean
3948

4049
Configure the aggressive mode for only this rule.
4150
This is prior to the `settings['es-x'].aggressive` setting.
4251

52+
### allowTestedProperty: boolean
53+
54+
Configure the allowTestedProperty mode for only this rule.
55+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
56+
4357
## 🚀 Version
4458

4559
This rule was introduced in [eslint-plugin-es] v5.0.0.

docs/rules/no-array-prototype-filter.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,30 @@ foo.filter(e => e !== 0)
3030

3131
This rule has an option.
3232

33-
```yaml
34-
rules:
35-
es-x/no-array-prototype-filter: [error, { aggressive: false }]
33+
```jsonc
34+
{
35+
"rules": {
36+
"es-x/no-array-prototype-filter": [
37+
"error",
38+
{
39+
"aggressive": false,
40+
"allowTestedProperty": false
41+
}
42+
]
43+
}
44+
}
3645
```
3746

3847
### aggressive: boolean
3948

4049
Configure the aggressive mode for only this rule.
4150
This is prior to the `settings['es-x'].aggressive` setting.
4251

52+
### allowTestedProperty: boolean
53+
54+
Configure the allowTestedProperty mode for only this rule.
55+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
56+
4357
## 🚀 Version
4458

4559
This rule was introduced in [eslint-plugin-es] v5.0.0.

0 commit comments

Comments
 (0)