Skip to content

Commit 14257a2

Browse files
committed
fix: @putout/plugin-arguments: json-parse -> apply-json-parse
1 parent 6868805 commit 14257a2

File tree

10 files changed

+73
-73
lines changed

10 files changed

+73
-73
lines changed

packages/plugin-arguments/README.md

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,76 @@ npm i @putout/plugin-arguments
1313

1414
## Rules
1515

16+
-[apply-json-parse](#apply-json-parse);
1617
-[apply-rest](#apply-rest);
1718
-[remove-useless](#remove-useless);
1819
-[remove-useless-from-method](#remove-useless-from-method);
1920
-[destructuring](#destructring);
2021
-[remove-unused](#remove-unused);
21-
-[json-parse](#json-parse);
2222

2323
## Config
2424

2525
```json
2626
{
2727
"rules": {
28+
"arguments/apply-json-parse": "on",
2829
"arguments/apply-rest": "on",
2930
"arguments/remove-useless": "on",
3031
"arguments/remove-useless-from-method": "on",
3132
"arguments/destructuring": "on",
32-
"arguments/remove-unused": "on",
33-
"arguments/json-parse": "on"
33+
"arguments/remove-unused": "on"
3434
}
3535
}
3636
```
3737

38+
### apply-json-parse
39+
40+
> The `JSON.parse()` static method parses a JSON string, constructing the JavaScript value or object described by the string. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.
41+
>
42+
> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
43+
44+
Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/efdb0e3d0ab937f7901ce3047626b5fd/580aa27e4fb61fbfe3eead0cd21971a6ff084174).
45+
46+
### ❌ Example of incorrect code
47+
48+
```js
49+
import {operator} from 'putout';
50+
51+
const {fromJS} = operator;
52+
JSON.parse(fromJS(print(ast)), null, 4);
53+
```
54+
55+
### ✅ Example of correct code
56+
57+
```js
58+
import {operator} from 'putout';
59+
60+
const {fromJS} = operator;
61+
JSON.parse(fromJS(print(ast)));
62+
```
63+
64+
## apply-rest
65+
66+
> The rest parameter syntax allows a function to accept an indefinite number of arguments as an `array`, providing a way to represent variadic functions in JavaScript.
67+
>
68+
> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters)
69+
70+
### ❌ Example of incorrect code
71+
72+
```js
73+
function hello() {
74+
console.log(arguments);
75+
}
76+
```
77+
78+
### ✅ Example of correct code
79+
80+
```js
81+
function hello(...args) {
82+
console.log(args);
83+
}
84+
```
85+
3886
## remove-useless
3987

4088
### ❌ Example of incorrect code
@@ -103,54 +151,6 @@ function compute(current) {
103151
}
104152
```
105153

106-
### json-parse
107-
108-
> The `JSON.parse()` static method parses a JSON string, constructing the JavaScript value or object described by the string. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.
109-
>
110-
> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
111-
112-
Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/efdb0e3d0ab937f7901ce3047626b5fd/580aa27e4fb61fbfe3eead0cd21971a6ff084174).
113-
114-
### ❌ Example of incorrect code
115-
116-
```js
117-
import {operator} from 'putout';
118-
119-
const {fromJS} = operator;
120-
JSON.parse(fromJS(print(ast)), null, 4);
121-
```
122-
123-
### ✅ Example of correct code
124-
125-
```js
126-
import {operator} from 'putout';
127-
128-
const {fromJS} = operator;
129-
JSON.parse(fromJS(print(ast)));
130-
```
131-
132-
## apply-rest
133-
134-
> The rest parameter syntax allows a function to accept an indefinite number of arguments as an `array`, providing a way to represent variadic functions in JavaScript.
135-
>
136-
> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters)
137-
138-
### ❌ Example of incorrect code
139-
140-
```js
141-
function hello() {
142-
console.log(arguments);
143-
}
144-
```
145-
146-
### ✅ Example of correct code
147-
148-
```js
149-
function hello(...args) {
150-
console.log(args);
151-
}
152-
```
153-
154154
## License
155155

156156
MIT

packages/plugin-arguments/lib/json-parse/fixture/json-parse-fix.js renamed to packages/plugin-arguments/lib/apply-json-parse/fixture/apply-json-parse-fix.js

File renamed without changes.

packages/plugin-arguments/lib/json-parse/fixture/json-parse.js renamed to packages/plugin-arguments/lib/apply-json-parse/fixture/apply-json-parse.js

File renamed without changes.
File renamed without changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
3+
4+
const test = createTest(import.meta.url, {
5+
plugins: [
6+
['arguments/apply-json-parse', plugin],
7+
],
8+
});
9+
10+
test('putout: plugin-arguments: apply-json-parse: report', (t) => {
11+
t.report('apply-json-parse', `Avoid useless arguments in 'JSON.parse()'`);
12+
t.end();
13+
});
14+
15+
test('putout: plugin-arguments: apply-json-parse: transform', (t) => {
16+
t.transform('apply-json-parse');
17+
t.end();
18+
});

packages/plugin-arguments/lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import * as applyRest from './apply-rest/index.js';
22
import * as removeUseless from './remove-useless/index.js';
33
import * as removeUselessFromMethod from './remove-useless-from-method/index.js';
44
import * as removeUnused from './remove-unused/index.js';
5-
import * as jsonParse from './json-parse/index.js';
5+
import * as applyJsonParse from './apply-json-parse/index.js';
66

77
export const rules = {
88
'apply-rest': applyRest,
99
'remove-useless': removeUseless,
1010
'remove-useless-form-method': removeUselessFromMethod,
1111
'remove-unused': removeUnused,
12-
'json-parse': jsonParse,
12+
'apply-json-parse': applyJsonParse,
1313
};

packages/plugin-arguments/lib/json-parse/index.spec.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/plugin-arguments/test/arguments.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ test('plugin-remove-useless-arguments: transform: unused', (t) => {
3737
t.end();
3838
});
3939

40-
test('plugin-remove-useless-arguments: transform: json-parse', (t) => {
41-
t.transform('json-parse');
40+
test('plugin-remove-useless-arguments: transform: apply-json-parse', (t) => {
41+
t.transform('apply-json-parse');
4242
t.end();
4343
});
4444

packages/plugin-arguments/test/fixture/json-parse-fix.js renamed to packages/plugin-arguments/test/fixture/apply-json-parse-fix.js

File renamed without changes.

packages/plugin-arguments/test/fixture/json-parse.js renamed to packages/plugin-arguments/test/fixture/apply-json-parse.js

File renamed without changes.

0 commit comments

Comments
 (0)