Skip to content

Commit e84222a

Browse files
authored
Add rules for Annex B (#22)
* Add rules for legacy * Add no-escape-unescape * Add no-string-prototype-substr rule * Add no-string-create-html-methods rule * Add no-string-prototype-trimleft-trimright rule * Support for suggest * Add no-date-prototype-getyear-setyear rule * Add no-date-prototype-togmtstring * Add no-regexp-prototype-compile * Add no-labelled-function-declarations * Add no-function-declarations-in-if-statement-clauses-without-block * Support autofix * Add no-shadow-catch-param * Add no-initializers-in-for-in * fix test * fix tests * fix test * fix test * update test for eslint v4
1 parent 8f49a62 commit e84222a

Some content is hidden

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

43 files changed

+2278
-46
lines changed

docs/.vuepress/components/eslint-playground.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export default {
3131
return value === "bad" || value === "good"
3232
},
3333
},
34+
sourceType: {
35+
type: String,
36+
default: undefined,
37+
},
3438
},
3539
3640
data() {
@@ -73,7 +77,7 @@ export default {
7377
rules: {},
7478
parserOptions: {
7579
ecmaVersion: 2022,
76-
sourceType: "module",
80+
sourceType: this.sourceType || "module",
7781
},
7882
settings: {
7983
"es-x": { aggressive: true },

docs/.vuepress/config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ module.exports = {
2929
sidebar: [
3030
"/",
3131
"/rules/",
32-
...Object.keys(categories)
32+
...Object.values(categories)
33+
.filter((menu) => menu.rules.length)
3334
.map((category) => ({
34-
title: category,
35+
title: category.title,
3536
collapsable: false,
36-
children: categories[category].rules.map(({ ruleId }) => [
37+
children: category.rules.map(({ ruleId }) => [
3738
`/rules/${ruleId}`,
3839
`es-x/${ruleId}`,
3940
]),
40-
}))
41-
.filter((menu) => menu.children.length),
41+
})),
4242
],
4343
},
4444
}

docs/rules/README.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ This plugin provides the following rules.
44

55
- 🔧 mark means that the `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by the rule.
66

7-
## ES2023
8-
9-
There is a config that enables the rules in this category: `plugin:es-x/no-new-in-esnext`
10-
11-
| Rule ID | Description | |
12-
|:--------|:------------|:--:|
13-
| | Now there are no rules. | |
14-
157
## ES2022
168

179
There are multiple configs that enable all rules in this category: `plugin:es-x/no-new-in-es2022`, `plugin:es-x/restrict-to-es3`, `plugin:es-x/restrict-to-es5`, `plugin:es-x/restrict-to-es2015`, `plugin:es-x/restrict-to-es2016`, `plugin:es-x/restrict-to-es2017`, `plugin:es-x/restrict-to-es2018`, `plugin:es-x/restrict-to-es2019`, `plugin:es-x/restrict-to-es2020`, and `plugin:es-x/restrict-to-es2021`
@@ -231,3 +223,22 @@ There are multiple configs that enable all rules in this category: `plugin:es-x/
231223
| [es-x/no-string-prototype-trim](./no-string-prototype-trim.md) | disallow the `String.prototype.trim` method. | |
232224
| [es-x/no-trailing-commas](./no-trailing-commas.md) | disallow trailing commas in array/object literals. | |
233225

226+
## Legacy
227+
228+
Rules in this category disallow the syntax contained in [Annex B](https://tc39.es/ecma262/multipage/additional-ecmascript-features-for-web-browsers.html) or Legacy.
229+
The rules are not included in any preset.
230+
231+
| Rule ID | Description | |
232+
|:--------|:------------|:--:|
233+
| [es-x/no-date-prototype-getyear-setyear](./no-date-prototype-getyear-setyear.md) | disallow the `Date.prototype.{getYear,setYear}` methods. | |
234+
| [es-x/no-date-prototype-togmtstring](./no-date-prototype-togmtstring.md) | disallow the `Date.prototype.toGMTString` method. | 🔧 |
235+
| [es-x/no-escape-unescape](./no-escape-unescape.md) | disallow `escape` and `unescape`. | |
236+
| [es-x/no-function-declarations-in-if-statement-clauses-without-block](./no-function-declarations-in-if-statement-clauses-without-block.md) | disallow function declarations in if statement clauses without using blocks. | 🔧 |
237+
| [es-x/no-initializers-in-for-in](./no-initializers-in-for-in.md) | disallow initializers in for-in heads. | |
238+
| [es-x/no-labelled-function-declarations](./no-labelled-function-declarations.md) | disallow labelled function declarations. | |
239+
| [es-x/no-regexp-prototype-compile](./no-regexp-prototype-compile.md) | disallow the `RegExp.prototype.compile` method. | |
240+
| [es-x/no-shadow-catch-param](./no-shadow-catch-param.md) | disallow identifiers from shadowing catch parameter names. | |
241+
| [es-x/no-string-create-html-methods](./no-string-create-html-methods.md) | disallow HTML creation methods of string instances. | |
242+
| [es-x/no-string-prototype-substr](./no-string-prototype-substr.md) | disallow the `String.prototype.substr` method. | |
243+
| [es-x/no-string-prototype-trimleft-trimright](./no-string-prototype-trimleft-trimright.md) | disallow the `String.prototype.{trimLeft,trimRight}` methods. | 🔧 |
244+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# es-x/no-date-prototype-getyear-setyear
2+
> disallow the `Date.prototype.{getYear,setYear}` methods
3+
4+
This rule reports Annex B feature `Date.prototype.{getYear,setYear}` methods as errors.
5+
6+
This rule is silent by default because it's hard to know types. You need to configure [the aggressive mode](../#the-aggressive-mode) or TypeScript in order to enable this rule.
7+
8+
## 💡 Examples
9+
10+
⛔ Examples of **incorrect** code for this rule:
11+
12+
<eslint-playground type="bad" code="/*eslint es-x/no-date-prototype-getyear-setyear: [error, { aggressive: true }] */
13+
foo.getYear()
14+
foo.setYear(99)
15+
" />
16+
17+
## 🔧 Options
18+
19+
This rule has an option.
20+
21+
```yml
22+
rules:
23+
es-x/no-date-prototype-getyear-setyear: [error, { aggressive: false }]
24+
```
25+
26+
### aggressive: boolean
27+
28+
Configure the aggressive mode for only this rule.
29+
This is prior to the `settings['es-x'].aggressive` setting.
30+
31+
## 📚 References
32+
33+
- [Rule source](https://github.com/ota-meshi/eslint-plugin-es-x/blob/master/lib/rules/no-date-prototype-getyear-setyear.js)
34+
- [Test source](https://github.com/ota-meshi/eslint-plugin-es-x/blob/master/tests/lib/rules/no-date-prototype-getyear-setyear.js)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# es-x/no-date-prototype-togmtstring
2+
> disallow the `Date.prototype.toGMTString` method
3+
4+
- 🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
5+
6+
This rule reports Annex B feature `Date.prototype.toGMTString` method as errors.
7+
8+
This rule is silent by default because it's hard to know types. You need to configure [the aggressive mode](../#the-aggressive-mode) or TypeScript in order to enable this rule.
9+
10+
## 💡 Examples
11+
12+
⛔ Examples of **incorrect** code for this rule:
13+
14+
<eslint-playground type="bad" code="/*eslint es-x/no-date-prototype-togmtstring: [error, { aggressive: true }] */
15+
foo.toGMTString()
16+
" />
17+
18+
## 🔧 Options
19+
20+
This rule has an option.
21+
22+
```yml
23+
rules:
24+
es-x/no-date-prototype-togmtstring: [error, { aggressive: false }]
25+
```
26+
27+
### aggressive: boolean
28+
29+
Configure the aggressive mode for only this rule.
30+
This is prior to the `settings['es-x'].aggressive` setting.
31+
32+
## 📚 References
33+
34+
- [Rule source](https://github.com/ota-meshi/eslint-plugin-es-x/blob/master/lib/rules/no-date-prototype-togmtstring.js)
35+
- [Test source](https://github.com/ota-meshi/eslint-plugin-es-x/blob/master/tests/lib/rules/no-date-prototype-togmtstring.js)

docs/rules/no-escape-unescape.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# es-x/no-escape-unescape
2+
> disallow `escape` and `unescape`
3+
4+
This rule reports Annex B feature `escape` and `unescape` as errors.
5+
6+
## Examples
7+
8+
⛔ Examples of **incorrect** code for this rule:
9+
10+
<eslint-playground type="bad" code="/*eslint es-x/no-escape-unescape: error */
11+
escape('%&')
12+
unescape('%25%26')
13+
" />
14+
15+
## 📚 References
16+
17+
- [Rule source](https://github.com/ota-meshi/eslint-plugin-es-x/blob/master/lib/rules/no-escape-unescape.js)
18+
- [Test source](https://github.com/ota-meshi/eslint-plugin-es-x/blob/master/tests/lib/rules/no-escape-unescape.js)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# es-x/no-function-declarations-in-if-statement-clauses-without-block
2+
> disallow function declarations in if statement clauses without using blocks
3+
4+
- 🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
5+
6+
This rule reports Annex B feature [the function declarations in if statement clauses without using blocks](https://tc39.es/ecma262/multipage/additional-ecmascript-features-for-web-browsers.html#sec-functiondeclarations-in-ifstatement-statement-clauses) as errors.
7+
8+
## Examples
9+
10+
⛔ Examples of **incorrect** code for this rule:
11+
12+
<eslint-playground type="bad" source-type="script" code="/*eslint es-x/no-function-declarations-in-if-statement-clauses-without-block: error */
13+
if (a)
14+
function f1() {}
15+
else
16+
function f2() {}
17+
" />
18+
19+
## 📚 References
20+
21+
- [Rule source](https://github.com/ota-meshi/eslint-plugin-es-x/blob/master/lib/rules/no-function-declarations-in-if-statement-clauses-without-block.js)
22+
- [Test source](https://github.com/ota-meshi/eslint-plugin-es-x/blob/master/tests/lib/rules/no-function-declarations-in-if-statement-clauses-without-block.js)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# es-x/no-initializers-in-for-in
2+
> disallow initializers in for-in heads
3+
4+
This rule reports initializers in for-in statement heads as errors.
5+
6+
See [Annex B - Initializers in ForIn Statement Heads](https://tc39.es/ecma262/multipage/additional-ecmascript-features-for-web-browsers.html#sec-initializers-in-forin-statement-heads).
7+
8+
## Examples
9+
10+
⛔ Examples of **incorrect** code for this rule:
11+
12+
<eslint-playground type="bad" source-type="script" code="/*eslint es-x/no-initializers-in-for-in: error */
13+
for (var x = 42 in obj) { /**/ }
14+
" />
15+
16+
## 📚 References
17+
18+
- [Rule source](https://github.com/ota-meshi/eslint-plugin-es-x/blob/master/lib/rules/no-initializers-in-for-in.js)
19+
- [Test source](https://github.com/ota-meshi/eslint-plugin-es-x/blob/master/tests/lib/rules/no-initializers-in-for-in.js)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# es-x/no-labelled-function-declarations
2+
> disallow labelled function declarations
3+
4+
This rule reports Annex B feature [the labelled function declarations](https://tc39.es/ecma262/multipage/additional-ecmascript-features-for-web-browsers.html#sec-labelled-function-declarations) as errors.
5+
6+
## Examples
7+
8+
⛔ Examples of **incorrect** code for this rule:
9+
10+
<eslint-playground type="bad" source-type="script" code="/*eslint es-x/no-labelled-function-declarations: error */
11+
label: function f() {}
12+
" />
13+
14+
## 📚 References
15+
16+
- [Rule source](https://github.com/ota-meshi/eslint-plugin-es-x/blob/master/lib/rules/no-labelled-function-declarations.js)
17+
- [Test source](https://github.com/ota-meshi/eslint-plugin-es-x/blob/master/tests/lib/rules/no-labelled-function-declarations.js)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# es-x/no-regexp-prototype-compile
2+
> disallow the `RegExp.prototype.compile` method
3+
4+
This rule reports Annex B feature `RegExp.prototype.compile` method as errors.
5+
6+
This rule is silent by default because it's hard to know types. You need to configure [the aggressive mode](../#the-aggressive-mode) or TypeScript in order to enable this rule.
7+
8+
## 💡 Examples
9+
10+
⛔ Examples of **incorrect** code for this rule:
11+
12+
<eslint-playground type="bad" code="/*eslint es-x/no-regexp-prototype-compile: [error, { aggressive: true }] */
13+
foo.compile()
14+
" />
15+
16+
## 🔧 Options
17+
18+
This rule has an option.
19+
20+
```yml
21+
rules:
22+
es-x/no-regexp-prototype-compile: [error, { aggressive: false }]
23+
```
24+
25+
### aggressive: boolean
26+
27+
Configure the aggressive mode for only this rule.
28+
This is prior to the `settings['es-x'].aggressive` setting.
29+
30+
## 📚 References
31+
32+
- [Rule source](https://github.com/ota-meshi/eslint-plugin-es-x/blob/master/lib/rules/no-regexp-prototype-compile.js)
33+
- [Test source](https://github.com/ota-meshi/eslint-plugin-es-x/blob/master/tests/lib/rules/no-regexp-prototype-compile.js)

0 commit comments

Comments
 (0)