Skip to content

Commit 3573cef

Browse files
authored
Add new rules (#61)
* Add new rules - Add `jsonc/no-octal` rule that disallow legacy octal literals. - Add `jsonc/no-binary-numeric-literals` rule that disallow binary numeric literals. - Add `jsonc/no-octal-numeric-literals` rule that disallow octal numeric literals. - Add `jsonc/no-hexadecimal-numeric-literals` rule that disallow hexadecimal numeric literals. - Add `jsonc/no-unicode-codepoint-escapes` rule that disallow Unicode code point escape sequences. - Add `jsonc/no-escape-sequence-in-identifier` rule that disallow escape sequences in identifiers. * fix docs * Add new rules * Add jsonc/no-plus-sign rule * update
1 parent 4042939 commit 3573cef

Some content is hidden

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

44 files changed

+1241
-11
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,20 @@ The rules with the following star :star: are included in the config.
169169
| [jsonc/auto](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/auto.html) | apply jsonc rules similar to your configured ESLint core rules | :wrench: | | | |
170170
| [jsonc/key-name-casing](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/key-name-casing.html) | enforce naming convention to property key names | | | | |
171171
| [jsonc/no-bigint-literals](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-bigint-literals.html) | disallow BigInt literals | | :star: | :star: | :star: |
172+
| [jsonc/no-binary-numeric-literals](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-binary-numeric-literals.html) | disallow binary numeric literals | :wrench: | | | |
172173
| [jsonc/no-comments](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-comments.html) | disallow comments | | :star: | | |
174+
| [jsonc/no-escape-sequence-in-identifier](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-escape-sequence-in-identifier.html) | disallow escape sequences in identifiers. | :wrench: | | | |
175+
| [jsonc/no-hexadecimal-numeric-literals](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-hexadecimal-numeric-literals.html) | disallow hexadecimal numeric literals | :wrench: | | | |
176+
| [jsonc/no-infinity](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-infinity.html) | disallow Infinity | | | | |
177+
| [jsonc/no-nan](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-nan.html) | disallow NaN | | | | |
173178
| [jsonc/no-number-props](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-number-props.html) | disallow number property keys | :wrench: | :star: | :star: | :star: |
174179
| [jsonc/no-numeric-separators](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-numeric-separators.html) | disallow numeric separators | :wrench: | :star: | :star: | :star: |
180+
| [jsonc/no-octal-numeric-literals](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-octal-numeric-literals.html) | disallow octal numeric literals | :wrench: | | | |
181+
| [jsonc/no-plus-sign](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-plus-sign.html) | disallow plus sign | :wrench: | | | |
175182
| [jsonc/no-regexp-literals](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-regexp-literals.html) | disallow RegExp literals | | :star: | :star: | :star: |
176183
| [jsonc/no-template-literals](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-template-literals.html) | disallow template literals | :wrench: | :star: | :star: | :star: |
177184
| [jsonc/no-undefined-value](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-undefined-value.html) | disallow `undefined` | | :star: | :star: | :star: |
185+
| [jsonc/no-unicode-codepoint-escapes](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-unicode-codepoint-escapes.html) | disallow Unicode code point escape sequences. | :wrench: | | | |
178186
| [jsonc/valid-json-number](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/valid-json-number.html) | disallow invalid number for JSON | :wrench: | :star: | :star: | |
179187
| [jsonc/vue-custom-block/no-parsing-error](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/vue-custom-block/no-parsing-error.html) | disallow parsing errors in Vue custom blocks | | :star: | :star: | :star: |
180188

@@ -193,6 +201,7 @@ The rules with the following star :star: are included in the config.
193201
| [jsonc/no-floating-decimal](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-floating-decimal.html) | disallow leading or trailing decimal points in numeric literals | :wrench: | :star: | :star: | |
194202
| [jsonc/no-multi-str](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-multi-str.html) | disallow multiline strings | | :star: | :star: | |
195203
| [jsonc/no-octal-escape](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-octal-escape.html) | disallow octal escape sequences in string literals | | | | |
204+
| [jsonc/no-octal](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-octal.html) | disallow legacy octal literals | | | | |
196205
| [jsonc/no-sparse-arrays](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-sparse-arrays.html) | disallow sparse arrays | | :star: | :star: | :star: |
197206
| [jsonc/no-useless-escape](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-useless-escape.html) | disallow unnecessary escape usage | | :star: | :star: | :star: |
198207
| [jsonc/object-curly-newline](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/object-curly-newline.html) | enforce consistent line breaks inside braces | :wrench: | | | |

docs/rules/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,20 @@ The rules with the following star :star: are included in the `plugin:jsonc/recom
1616
| [jsonc/auto](./auto.md) | apply jsonc rules similar to your configured ESLint core rules | :wrench: | | | |
1717
| [jsonc/key-name-casing](./key-name-casing.md) | enforce naming convention to property key names | | | | |
1818
| [jsonc/no-bigint-literals](./no-bigint-literals.md) | disallow BigInt literals | | :star: | :star: | :star: |
19+
| [jsonc/no-binary-numeric-literals](./no-binary-numeric-literals.md) | disallow binary numeric literals | :wrench: | | | |
1920
| [jsonc/no-comments](./no-comments.md) | disallow comments | | :star: | | |
21+
| [jsonc/no-escape-sequence-in-identifier](./no-escape-sequence-in-identifier.md) | disallow escape sequences in identifiers. | :wrench: | | | |
22+
| [jsonc/no-hexadecimal-numeric-literals](./no-hexadecimal-numeric-literals.md) | disallow hexadecimal numeric literals | :wrench: | | | |
23+
| [jsonc/no-infinity](./no-infinity.md) | disallow Infinity | | | | |
24+
| [jsonc/no-nan](./no-nan.md) | disallow NaN | | | | |
2025
| [jsonc/no-number-props](./no-number-props.md) | disallow number property keys | :wrench: | :star: | :star: | :star: |
2126
| [jsonc/no-numeric-separators](./no-numeric-separators.md) | disallow numeric separators | :wrench: | :star: | :star: | :star: |
27+
| [jsonc/no-octal-numeric-literals](./no-octal-numeric-literals.md) | disallow octal numeric literals | :wrench: | | | |
28+
| [jsonc/no-plus-sign](./no-plus-sign.md) | disallow plus sign | :wrench: | | | |
2229
| [jsonc/no-regexp-literals](./no-regexp-literals.md) | disallow RegExp literals | | :star: | :star: | :star: |
2330
| [jsonc/no-template-literals](./no-template-literals.md) | disallow template literals | :wrench: | :star: | :star: | :star: |
2431
| [jsonc/no-undefined-value](./no-undefined-value.md) | disallow `undefined` | | :star: | :star: | :star: |
32+
| [jsonc/no-unicode-codepoint-escapes](./no-unicode-codepoint-escapes.md) | disallow Unicode code point escape sequences. | :wrench: | | | |
2533
| [jsonc/valid-json-number](./valid-json-number.md) | disallow invalid number for JSON | :wrench: | :star: | :star: | |
2634
| [jsonc/vue-custom-block/no-parsing-error](./vue-custom-block/no-parsing-error.md) | disallow parsing errors in Vue custom blocks | | :star: | :star: | :star: |
2735

@@ -40,6 +48,7 @@ The rules with the following star :star: are included in the `plugin:jsonc/recom
4048
| [jsonc/no-floating-decimal](./no-floating-decimal.md) | disallow leading or trailing decimal points in numeric literals | :wrench: | :star: | :star: | |
4149
| [jsonc/no-multi-str](./no-multi-str.md) | disallow multiline strings | | :star: | :star: | |
4250
| [jsonc/no-octal-escape](./no-octal-escape.md) | disallow octal escape sequences in string literals | | | | |
51+
| [jsonc/no-octal](./no-octal.md) | disallow legacy octal literals | | | | |
4352
| [jsonc/no-sparse-arrays](./no-sparse-arrays.md) | disallow sparse arrays | | :star: | :star: | :star: |
4453
| [jsonc/no-useless-escape](./no-useless-escape.md) | disallow unnecessary escape usage | | :star: | :star: | :star: |
4554
| [jsonc/object-curly-newline](./object-curly-newline.md) | enforce consistent line breaks inside braces | :wrench: | | | |
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
pageClass: "rule-details"
3+
sidebarDepth: 0
4+
title: "jsonc/no-binary-numeric-literals"
5+
description: "disallow binary numeric literals"
6+
---
7+
# jsonc/no-binary-numeric-literals
8+
9+
> disallow binary numeric literals
10+
11+
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
12+
- :wrench: 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.
13+
14+
## :book: Rule Details
15+
16+
This rule disallow binary numeric literals
17+
18+
<eslint-code-block fix>
19+
20+
<!-- eslint-skip -->
21+
22+
```json5
23+
/* eslint jsonc/no-binary-numeric-literals: 'error' */
24+
{
25+
/* ✓ GOOD */
26+
"GOOD": 10,
27+
28+
/* ✗ BAD */
29+
"BAD": 0b1010
30+
}
31+
```
32+
33+
</eslint-code-block>
34+
35+
## :wrench: Options
36+
37+
Nothing.
38+
39+
## :couple: Related rules
40+
41+
- [jsonc/valid-json-number]
42+
43+
[jsonc/valid-json-number]: ./valid-json-number.md
44+
45+
## :mag: Implementation
46+
47+
- [Rule source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/lib/rules/no-binary-numeric-literals.ts)
48+
- [Test source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/tests/lib/rules/no-binary-numeric-literals.ts)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
pageClass: "rule-details"
3+
sidebarDepth: 0
4+
title: "jsonc/no-escape-sequence-in-identifier"
5+
description: "disallow escape sequences in identifiers."
6+
---
7+
# jsonc/no-escape-sequence-in-identifier
8+
9+
> disallow escape sequences in identifiers.
10+
11+
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
12+
- :wrench: 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.
13+
14+
## :book: Rule Details
15+
16+
This rule reports disallow escape sequences in identifiers.
17+
18+
<eslint-code-block fix>
19+
20+
<!-- eslint-skip -->
21+
22+
```json5
23+
/* eslint jsonc/no-escape-sequence-in-identifier: 'error' */
24+
{
25+
/* ✓ GOOD */
26+
GOOD: "GOOD",
27+
28+
/* ✗ BAD */
29+
\u0042\u{41}\u{44}: "BAD"
30+
}
31+
```
32+
33+
</eslint-code-block>
34+
35+
## :wrench: Options
36+
37+
Nothing.
38+
39+
## :mag: Implementation
40+
41+
- [Rule source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/lib/rules/no-escape-sequence-in-identifier.ts)
42+
- [Test source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/tests/lib/rules/no-escape-sequence-in-identifier.ts)

docs/rules/no-floating-decimal.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ since: "v0.9.0"
1616

1717
This rule is aimed at eliminating floating decimal points and will warn whenever a numeric value has a decimal point but is missing a number either before or after it.
1818

19+
Cannot use floating decimal points when in JSON and JSONC.
20+
1921
<eslint-code-block fix>
2022

2123
<!-- eslint-skip -->
@@ -40,8 +42,10 @@ Nothing.
4042
## :couple: Related rules
4143

4244
- [no-floating-decimal]
45+
- [jsonc/valid-json-number]
4346

4447
[no-floating-decimal]: https://eslint.org/docs/rules/no-floating-decimal
48+
[jsonc/valid-json-number]: ./valid-json-number.md
4549

4650
## :rocket: Version
4751

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
pageClass: "rule-details"
3+
sidebarDepth: 0
4+
title: "jsonc/no-hexadecimal-numeric-literals"
5+
description: "disallow hexadecimal numeric literals"
6+
---
7+
# jsonc/no-hexadecimal-numeric-literals
8+
9+
> disallow hexadecimal numeric literals
10+
11+
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
12+
- :wrench: 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.
13+
14+
## :book: Rule Details
15+
16+
This rule disallow hexadecimal numeric literals.
17+
18+
Cannot use hexadecimal numeric literals when in JSON and JSONC.
19+
20+
<eslint-code-block fix>
21+
22+
<!-- eslint-skip -->
23+
24+
```json5
25+
/* eslint jsonc/no-hexadecimal-numeric-literals: 'error' */
26+
{
27+
/* ✓ GOOD */
28+
"GOOD": 65535,
29+
30+
/* ✗ BAD */
31+
"BAD": 0xFFFF
32+
}
33+
```
34+
35+
</eslint-code-block>
36+
37+
## :wrench: Options
38+
39+
Nothing.
40+
41+
## :couple: Related rules
42+
43+
- [jsonc/valid-json-number]
44+
45+
[jsonc/valid-json-number]: ./valid-json-number.md
46+
47+
## :mag: Implementation
48+
49+
- [Rule source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/lib/rules/no-hexadecimal-numeric-literals.ts)
50+
- [Test source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/tests/lib/rules/no-hexadecimal-numeric-literals.ts)

docs/rules/no-infinity.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
pageClass: "rule-details"
3+
sidebarDepth: 0
4+
title: "jsonc/no-infinity"
5+
description: "disallow Infinity"
6+
---
7+
# jsonc/no-infinity
8+
9+
> disallow Infinity
10+
11+
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
12+
13+
## :book: Rule Details
14+
15+
This rule reports the use of Infinity.
16+
17+
Cannot use Infinity when in JSON and JSONC.
18+
19+
<eslint-code-block>
20+
21+
<!-- eslint-skip -->
22+
23+
```json5
24+
/* eslint jsonc/no-infinity: 'error' */
25+
{
26+
/* ✓ GOOD */
27+
"GOOD": 42,
28+
29+
/* ✗ BAD */
30+
"BAD": Infinity
31+
}
32+
```
33+
34+
</eslint-code-block>
35+
36+
## :wrench: Options
37+
38+
Nothing.
39+
40+
## :couple: Related rules
41+
42+
- [jsonc/valid-json-number]
43+
44+
[jsonc/valid-json-number]: ./valid-json-number.md
45+
46+
## :mag: Implementation
47+
48+
- [Rule source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/lib/rules/no-infinity.ts)
49+
- [Test source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/tests/lib/rules/no-infinity.ts)

docs/rules/no-nan.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
pageClass: "rule-details"
3+
sidebarDepth: 0
4+
title: "jsonc/no-nan"
5+
description: "disallow NaN"
6+
---
7+
# jsonc/no-nan
8+
9+
> disallow NaN
10+
11+
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
12+
13+
## :book: Rule Details
14+
15+
This rule reports the use of NaN.
16+
17+
Cannot use NaN when in JSON and JSONC.
18+
19+
<eslint-code-block>
20+
21+
<!-- eslint-skip -->
22+
23+
```json5
24+
/* eslint jsonc/no-nan: 'error' */
25+
{
26+
/* ✓ GOOD */
27+
"GOOD": 42,
28+
29+
/* ✗ BAD */
30+
"BAD": NaN
31+
}
32+
```
33+
34+
</eslint-code-block>
35+
36+
## :wrench: Options
37+
38+
Nothing.
39+
40+
## :couple: Related rules
41+
42+
- [jsonc/valid-json-number]
43+
44+
[jsonc/valid-json-number]: ./valid-json-number.md
45+
46+
## :mag: Implementation
47+
48+
- [Rule source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/lib/rules/no-nan.ts)
49+
- [Test source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/tests/lib/rules/no-nan.ts)

docs/rules/no-numeric-separators.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ This rule reports the use of numeric separators.
3737

3838
Nothing.
3939

40+
## :couple: Related rules
41+
42+
- [jsonc/valid-json-number]
43+
44+
[jsonc/valid-json-number]: ./valid-json-number.md
45+
4046
## :rocket: Version
4147

4248
This rule was introduced in eslint-plugin-jsonc v0.6.0
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
pageClass: "rule-details"
3+
sidebarDepth: 0
4+
title: "jsonc/no-octal-numeric-literals"
5+
description: "disallow octal numeric literals"
6+
---
7+
# jsonc/no-octal-numeric-literals
8+
9+
> disallow octal numeric literals
10+
11+
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
12+
- :wrench: 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.
13+
14+
## :book: Rule Details
15+
16+
This rule disallow octal numeric literals.
17+
18+
<eslint-code-block fix>
19+
20+
<!-- eslint-skip -->
21+
22+
```json5
23+
/* eslint jsonc/no-octal-numeric-literals: 'error' */
24+
{
25+
/* ✓ GOOD */
26+
"GOOD": 511,
27+
28+
/* ✗ BAD */
29+
"BAD": 0o777
30+
}
31+
```
32+
33+
</eslint-code-block>
34+
35+
## :wrench: Options
36+
37+
Nothing.
38+
39+
## :couple: Related rules
40+
41+
- [jsonc/valid-json-number]
42+
43+
[jsonc/valid-json-number]: ./valid-json-number.md
44+
45+
## :mag: Implementation
46+
47+
- [Rule source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/lib/rules/no-octal-numeric-literals.ts)
48+
- [Test source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/tests/lib/rules/no-octal-numeric-literals.ts)

0 commit comments

Comments
 (0)