Skip to content

Commit e4dc53e

Browse files
ota-meshiCopilotCopilot
authored
Add rules for JSON.parse source text access (#277)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: ota-meshi <16508807+ota-meshi@users.noreply.github.com>
1 parent 0593d98 commit e4dc53e

22 files changed

+474
-0
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
@@ -1117,6 +1117,32 @@ export default [
11171117

11181118
</details>
11191119

1120+
## no-json-parse-with-source
1121+
1122+
disallow proposal ES2026 [JSON.parse source text access](https://github.com/tc39/proposal-json-parse-with-source)\
1123+
⚠️ This config will be changed in the minor versions of this plugin.
1124+
1125+
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).
1126+
1127+
```js
1128+
import pluginESx from "eslint-plugin-es-x"
1129+
export default [
1130+
pluginESx.configs['flat/no-json-parse-with-source']
1131+
]
1132+
```
1133+
1134+
<details><summary> Legacy Config </summary>
1135+
1136+
.eslintrc.*:
1137+
1138+
```json
1139+
{
1140+
"extends": ["plugin:es-x/no-json-parse-with-source"],
1141+
}
1142+
```
1143+
1144+
</details>
1145+
11201146
## no-float16array
11211147

11221148
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
@@ -15,6 +15,9 @@ There is a config that enables the rules in this category: [`no-new-in-esnext`]
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. | |
1717
| [es-x/no-iterator-concat](./no-iterator-concat.md) | disallow the `Iterator.concat` method. | |
18+
| [es-x/no-json-israwjson](./no-json-israwjson.md) | disallow the `JSON.isRawJSON` method. | |
19+
| [es-x/no-json-parse-reviver-context-parameter](./no-json-parse-reviver-context-parameter.md) | disallow the `context` parameter in `JSON.parse` reviver function. | |
20+
| [es-x/no-json-rawjson](./no-json-rawjson.md) | disallow the `JSON.rawJSON` method. | |
1821
| [es-x/no-math-sumprecise](./no-math-sumprecise.md) | disallow the `Math.sumPrecise` method. | |
1922
| [es-x/no-suppressederror](./no-suppressederror.md) | disallow the `SuppressedError` class. | |
2023
| [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` reviver `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)