Skip to content

Commit 2703122

Browse files
committed
Add rules for JSON.parse source text access
1 parent fa90765 commit 2703122

23 files changed

+424
-2
lines changed

.changeset/no-json-israwjson.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-es-x": minor
3+
---
4+
5+
Add `es-x/no-json-israwjson` rule
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-es-x": minor
3+
---
4+
5+
Add `es-x/no-json-parse-reviver-context-parameter` rule
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-es-x": minor
3+
---
4+
5+
Add `no-json-parse-with-source` config

.changeset/no-json-rawjson.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-es-x": minor
3+
---
4+
5+
Add `es-x/no-json-rawjson` rule

docs/configs/index.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,32 @@ export default [
10671067

10681068
</details>
10691069

1070+
## no-json-parse-with-source
1071+
1072+
disallow proposal ES2026 [JSON.parse source text access](https://github.com/tc39/proposal-json-parse-with-source)\
1073+
⚠️ This config will be changed in the minor versions of this plugin.
1074+
1075+
This configs includes rules for [es-x/no-json-israwjson](../rules/no-json-israwjson.md), [es-x/no-json-parse-reviver-context-parameter](../rules/no-json-parse-reviver-context-parameter.md), and [es-x/no-json-rawjson](../rules/no-json-rawjson.md).
1076+
1077+
```js
1078+
import pluginESx from "eslint-plugin-es-x"
1079+
export default [
1080+
pluginESx.configs['flat/no-json-parse-with-source']
1081+
]
1082+
```
1083+
1084+
<details><summary> Legacy Config </summary>
1085+
1086+
.eslintrc.*:
1087+
1088+
```json
1089+
{
1090+
"extends": ["plugin:es-x/no-json-parse-with-source"],
1091+
}
1092+
```
1093+
1094+
</details>
1095+
10701096
## no-float16array
10711097

10721098
disallow proposal ES2025 [Float16Array](https://github.com/tc39/proposal-float16array)

docs/rules/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ There is a config that enables the rules in this category: [`no-new-in-esnext`]
1414
| [es-x/no-asyncdisposablestack](./no-asyncdisposablestack.md) | disallow the `AsyncDisposableStack` class. | |
1515
| [es-x/no-disposablestack](./no-disposablestack.md) | disallow the `DisposableStack` class. | |
1616
| [es-x/no-error-iserror](./no-error-iserror.md) | disallow the `Error.isError` method. | |
17+
| [es-x/no-json-israwjson](./no-json-israwjson.md) | disallow the `JSON.isRawJSON` method. | |
18+
| [es-x/no-json-parse-reviver-context-parameter](./no-json-parse-reviver-context-parameter.md) | disallow the `context` parameter in `JSON.parse` reviver function. | |
19+
| [es-x/no-json-rawjson](./no-json-rawjson.md) | disallow the `JSON.rawJSON` method. | |
1720
| [es-x/no-math-sumprecise](./no-math-sumprecise.md) | disallow the `Math.sumPrecise` method. | |
1821
| [es-x/no-suppressederror](./no-suppressederror.md) | disallow the `SuppressedError` class. | |
1922
| [es-x/no-symbol-asyncdispose](./no-symbol-asyncdispose.md) | disallow the `Symbol.asyncDispose` property. | |

docs/rules/no-json-israwjson.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: "es-x/no-json-israwjson"
3+
description: "disallow the `JSON.isRawJSON` method"
4+
---
5+
6+
# es-x/no-json-israwjson
7+
> disallow the `JSON.isRawJSON` method
8+
9+
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
10+
- ✅ The following configurations enable this rule: [no-json-parse-with-source] and [no-new-in-esnext]
11+
12+
This rule reports ES2026 [`JSON.isRawJSON` method](https://github.com/tc39/proposal-json-parse-with-source) as errors.
13+
14+
## 💡 Examples
15+
16+
⛔ Examples of **incorrect** code for this rule:
17+
18+
<eslint-playground type="bad">
19+
20+
```js
21+
/*eslint es-x/no-json-israwjson: error */
22+
JSON.isRawJSON(object);
23+
```
24+
25+
</eslint-playground>
26+
27+
## 🔧 Options
28+
29+
This rule has an option.
30+
31+
```jsonc
32+
{
33+
"rules": {
34+
"es-x/no-json-israwjson": [
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+
49+
## 📚 References
50+
51+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-json-israwjson.js)
52+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-json-israwjson.js)
53+
54+
[no-json-parse-with-source]: ../configs/index.md#no-json-parse-with-source
55+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: "es-x/no-json-parse-reviver-context-parameter"
3+
description: "disallow the `context` parameter in `JSON.parse` reviver function"
4+
---
5+
6+
# es-x/no-json-parse-reviver-context-parameter
7+
> disallow the `context` parameter in `JSON.parse` reviver function
8+
9+
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
10+
- ✅ The following configurations enable this rule: [no-json-parse-with-source] and [no-new-in-esnext]
11+
12+
This rule reports ES2026 [`JSON.parse` resolver `context` parameter](https://github.com/tc39/proposal-json-parse-with-source) as errors.
13+
14+
## 💡 Examples
15+
16+
⛔ Examples of **incorrect** code for this rule:
17+
18+
<eslint-playground type="bad">
19+
20+
```js
21+
/*eslint es-x/no-json-parse-reviver-context-parameter: error */
22+
JSON.parse(
23+
'{"key": "value"}',
24+
(
25+
key,
26+
value,
27+
context // This is the context parameter
28+
) => {
29+
return value;
30+
});
31+
```
32+
33+
</eslint-playground>
34+
35+
## 📚 References
36+
37+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-json-parse-reviver-context-parameter.js)
38+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-json-parse-reviver-context-parameter.js)
39+
40+
[no-json-parse-with-source]: ../configs/index.md#no-json-parse-with-source
41+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext

docs/rules/no-json-rawjson.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: "es-x/no-json-rawjson"
3+
description: "disallow the `JSON.rawJSON` method"
4+
---
5+
6+
# es-x/no-json-rawjson
7+
> disallow the `JSON.rawJSON` method
8+
9+
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
10+
- ✅ The following configurations enable this rule: [no-json-parse-with-source] and [no-new-in-esnext]
11+
12+
This rule reports ES2026 [`JSON.rawJSON` method](https://github.com/tc39/proposal-json-parse-with-source) as errors.
13+
14+
## 💡 Examples
15+
16+
⛔ Examples of **incorrect** code for this rule:
17+
18+
<eslint-playground type="bad">
19+
20+
```js
21+
/*eslint es-x/no-json-rawjson: error */
22+
JSON.rawJSON('123');
23+
```
24+
25+
</eslint-playground>
26+
27+
## 🔧 Options
28+
29+
This rule has an option.
30+
31+
```jsonc
32+
{
33+
"rules": {
34+
"es-x/no-json-rawjson": [
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+
49+
## 📚 References
50+
51+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-json-rawjson.js)
52+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-json-rawjson.js)
53+
54+
[no-json-parse-with-source]: ../configs/index.md#no-json-parse-with-source
55+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* DON'T EDIT THIS FILE.
3+
* This file was generated by "scripts/update-lib-flat-configs.js" script.
4+
*/
5+
"use strict"
6+
7+
module.exports = {
8+
plugins: {
9+
get "es-x"() {
10+
return require("../../index.js")
11+
},
12+
},
13+
rules: {
14+
"es-x/no-json-israwjson": "error",
15+
"es-x/no-json-parse-reviver-context-parameter": "error",
16+
"es-x/no-json-rawjson": "error",
17+
},
18+
}

0 commit comments

Comments
 (0)