-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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.
- Loading branch information
Showing
22 changed files
with
775 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
pageClass: "rule-details" | ||
sidebarDepth: 0 | ||
title: "jsonc/no-binary-numeric-literals" | ||
description: "disallow binary numeric literals" | ||
--- | ||
# jsonc/no-binary-numeric-literals | ||
|
||
> disallow binary numeric literals | ||
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge> | ||
- :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. | ||
|
||
## :book: Rule Details | ||
|
||
This rule disallow binary numeric literals | ||
|
||
<eslint-code-block fix> | ||
|
||
<!-- eslint-skip --> | ||
|
||
```json5 | ||
/* eslint jsonc/no-binary-numeric-literals: 'error' */ | ||
{ | ||
/* ✓ GOOD */ | ||
"GOOD": 10, | ||
|
||
/* ✗ BAD */ | ||
"BAD": 0b1010 | ||
} | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
## :wrench: Options | ||
|
||
Nothing. | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/lib/rules/no-binary-numeric-literals.ts) | ||
- [Test source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/tests/lib/rules/no-binary-numeric-literals.js) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
pageClass: "rule-details" | ||
sidebarDepth: 0 | ||
title: "jsonc/no-escape-sequence-in-identifier" | ||
description: "disallow escape sequences in identifiers." | ||
--- | ||
# jsonc/no-escape-sequence-in-identifier | ||
|
||
> disallow escape sequences in identifiers. | ||
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge> | ||
- :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. | ||
|
||
## :book: Rule Details | ||
|
||
This rule reports disallow escape sequences in identifiers. | ||
|
||
<eslint-code-block fix> | ||
|
||
<!-- eslint-skip --> | ||
|
||
```json5 | ||
/* eslint jsonc/no-escape-sequence-in-identifier: 'error' */ | ||
{ | ||
/* ✓ GOOD */ | ||
GOOD: "GOOD", | ||
|
||
/* ✗ BAD */ | ||
\u0042\u{41}\u{44}: "BAD" | ||
} | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
## :wrench: Options | ||
|
||
Nothing. | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/lib/rules/no-escape-sequence-in-identifier.ts) | ||
- [Test source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/tests/lib/rules/no-escape-sequence-in-identifier.js) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
pageClass: "rule-details" | ||
sidebarDepth: 0 | ||
title: "jsonc/no-hexadecimal-numeric-literals" | ||
description: "disallow hexadecimal numeric literals" | ||
--- | ||
# jsonc/no-hexadecimal-numeric-literals | ||
|
||
> disallow hexadecimal numeric literals | ||
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge> | ||
- :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. | ||
|
||
## :book: Rule Details | ||
|
||
This rule disallow hexadecimal numeric literals. | ||
|
||
<eslint-code-block fix> | ||
|
||
<!-- eslint-skip --> | ||
|
||
```json5 | ||
/* eslint jsonc/no-hexadecimal-numeric-literals: 'error' */ | ||
{ | ||
/* ✓ GOOD */ | ||
"GOOD": 65535, | ||
|
||
/* ✗ BAD */ | ||
"BAD": 0xFFFF | ||
} | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
## :wrench: Options | ||
|
||
Nothing. | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/lib/rules/no-hexadecimal-numeric-literals.ts) | ||
- [Test source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/tests/lib/rules/no-hexadecimal-numeric-literals.js) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
pageClass: "rule-details" | ||
sidebarDepth: 0 | ||
title: "jsonc/no-octal-numeric-literals" | ||
description: "disallow octal numeric literals" | ||
--- | ||
# jsonc/no-octal-numeric-literals | ||
|
||
> disallow octal numeric literals | ||
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge> | ||
- :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. | ||
|
||
## :book: Rule Details | ||
|
||
This rule disallow octal numeric literals. | ||
|
||
<eslint-code-block fix> | ||
|
||
<!-- eslint-skip --> | ||
|
||
```json5 | ||
/* eslint jsonc/no-octal-numeric-literals: 'error' */ | ||
{ | ||
/* ✓ GOOD */ | ||
"GOOD": 511, | ||
|
||
/* ✗ BAD */ | ||
"BAD": 0o777 | ||
} | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
## :wrench: Options | ||
|
||
Nothing. | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/lib/rules/no-octal-numeric-literals.ts) | ||
- [Test source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/tests/lib/rules/no-octal-numeric-literals.js) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
pageClass: "rule-details" | ||
sidebarDepth: 0 | ||
title: "jsonc/no-octal" | ||
description: "disallow legacy octal literals" | ||
--- | ||
# jsonc/no-octal | ||
|
||
> disallow legacy octal literals | ||
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge> | ||
|
||
## :book: Rule Details | ||
|
||
The rule disallows octal literals. | ||
|
||
<eslint-code-block> | ||
|
||
<!-- eslint-skip --> | ||
|
||
```json5 | ||
/* eslint jsonc/no-octal: 'error' */ | ||
{ | ||
/* ✓ GOOD */ | ||
"GOOD": 777, | ||
|
||
/* ✗ BAD */ | ||
"BAD": 0777 | ||
} | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
## :wrench: Options | ||
|
||
Nothing. | ||
|
||
## :couple: Related rules | ||
|
||
- [no-octal] | ||
|
||
[no-octal]: https://eslint.org/docs/rules/no-octal | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/lib/rules/no-octal.ts) | ||
- [Test source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/tests/lib/rules/no-octal.js) | ||
|
||
<sup>Taken with ❤️ [from ESLint core](https://eslint.org/docs/rules/no-octal)</sup> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
pageClass: "rule-details" | ||
sidebarDepth: 0 | ||
title: "jsonc/no-unicode-codepoint-escapes" | ||
description: "disallow Unicode code point escape sequences." | ||
--- | ||
# jsonc/no-unicode-codepoint-escapes | ||
|
||
> disallow Unicode code point escape sequences. | ||
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge> | ||
- :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. | ||
|
||
## :book: Rule Details | ||
|
||
This rule disallow Unicode code point escape sequences. | ||
|
||
<eslint-code-block fix> | ||
|
||
<!-- eslint-skip --> | ||
|
||
```json5 | ||
/* eslint jsonc/no-unicode-codepoint-escapes: 'error' */ | ||
{ | ||
/* ✓ GOOD */ | ||
"GOOD": "\u0041", | ||
|
||
/* ✗ BAD */ | ||
"BAD": "\u{41}" | ||
} | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
## :wrench: Options | ||
|
||
Nothing. | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/lib/rules/no-unicode-codepoint-escapes.ts) | ||
- [Test source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/tests/lib/rules/no-unicode-codepoint-escapes.js) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { AST } from "jsonc-eslint-parser" | ||
import { createRule } from "../utils" | ||
|
||
const binaryNumericLiteralPattern = /^0[bB]/u | ||
|
||
export default createRule("no-binary-numeric-literals", { | ||
meta: { | ||
docs: { | ||
description: "disallow binary numeric literals", | ||
// TODO major version recommended: ["json","jsonc","json5"], | ||
recommended: null, | ||
extensionRule: false, | ||
layout: false, | ||
}, | ||
fixable: "code", | ||
messages: { | ||
disallow: "Binary numeric literals should not be used.", | ||
}, | ||
schema: [], | ||
type: "problem", | ||
}, | ||
create(context) { | ||
return { | ||
JSONLiteral(node: AST.JSONLiteral) { | ||
if ( | ||
typeof node.value === "number" && | ||
binaryNumericLiteralPattern.test(node.raw) | ||
) { | ||
context.report({ | ||
loc: node.loc, | ||
messageId: "disallow", | ||
fix: (fixer) => { | ||
return fixer.replaceTextRange( | ||
node.range, | ||
`${node.value}`, | ||
) | ||
}, | ||
}) | ||
} | ||
}, | ||
} | ||
}, | ||
}) |
Oops, something went wrong.