@putout/plugin-putout 23.0.1 → 23.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/lib/apply-parens/index.js +25 -0
- package/lib/declare/operator/index.js +2 -0
- package/lib/declare/operator/parens.js +7 -0
- package/lib/index.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,6 +33,7 @@ npm i @putout/plugin-putout -D
|
|
|
33
33
|
- ✅ [apply-processors-destructuring](#apply-processors-destructuring);
|
|
34
34
|
- ✅ [apply-remove](#apply-remove);
|
|
35
35
|
- ✅ [apply-rename](#apply-rename);
|
|
36
|
+
- ✅ [apply-parens](#apply-parens);
|
|
36
37
|
- ✅ [apply-short-processors](#apply-short-processors);
|
|
37
38
|
- ✅ [check-match](#check-match);
|
|
38
39
|
- ✅ [check-replace-code](#check-replace-code);
|
|
@@ -92,6 +93,7 @@ npm i @putout/plugin-putout -D
|
|
|
92
93
|
"putout/apply-declare": "on",
|
|
93
94
|
"putout/apply-processors-destructuring": "on",
|
|
94
95
|
"putout/apply-rename": "on",
|
|
96
|
+
"putout/apply-parens": "on",
|
|
95
97
|
"putout/apply-remove": "on",
|
|
96
98
|
"putout/apply-insert-before": "on",
|
|
97
99
|
"putout/apply-insert-after": "on",
|
|
@@ -215,6 +217,35 @@ export const fix = ({path, from, to}) => {
|
|
|
215
217
|
};
|
|
216
218
|
```
|
|
217
219
|
|
|
220
|
+
## apply-parens
|
|
221
|
+
|
|
222
|
+
Better use [`addParens(path)`](https://github.com/coderaiser/putout/tree/master/packages/operate#addparenspath-path) method of `operator` instead of using `path.node.extra` to have support of both printers:
|
|
223
|
+
|
|
224
|
+
- ✅ `@putout/printer`;
|
|
225
|
+
- ✅ `babel`;
|
|
226
|
+
|
|
227
|
+
Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d325a84e26807d46b5ec14db179c38f4/8bcd22d6dbe880c0fd70992a1a36b9c609b53b22).
|
|
228
|
+
|
|
229
|
+
### ❌ Example of incorrect code
|
|
230
|
+
|
|
231
|
+
```js
|
|
232
|
+
path.node.extra.parenthesized = false;
|
|
233
|
+
path.node.extra.parenthesized = true;
|
|
234
|
+
|
|
235
|
+
if (!path.node.extra?.parenthesized)
|
|
236
|
+
return;
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### ✅ Example of correct code
|
|
240
|
+
|
|
241
|
+
```js
|
|
242
|
+
removeParens(path);
|
|
243
|
+
addParens(path);
|
|
244
|
+
|
|
245
|
+
if (!hasParens(path))
|
|
246
|
+
return;
|
|
247
|
+
```
|
|
248
|
+
|
|
218
249
|
## apply-remove
|
|
219
250
|
|
|
220
251
|
Better to use [`remove(path)`](https://github.com/coderaiser/putout/tree/master/packages/operate#removepath) method of `operator`.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.report = (path) => {
|
|
4
|
+
if (path.isOptionalMemberExpression())
|
|
5
|
+
return `Use 'hasParens(path)' instead of 'path.node.extra'`;
|
|
6
|
+
|
|
7
|
+
const rightPath = path.get('right');
|
|
8
|
+
const {value} = rightPath.node;
|
|
9
|
+
const methodName = value ? 'add' : 'remove';
|
|
10
|
+
|
|
11
|
+
return `Use '${methodName}Parens(path)' instead of 'path.node.extra'`;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const ASSIGN_OBJECT = `
|
|
15
|
+
__a.node.extra = {
|
|
16
|
+
parenthesized: true,
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
module.exports.replace = () => ({
|
|
21
|
+
'__a.node.extra.parenthesized = false': 'removeParens(__a)',
|
|
22
|
+
'__a.node.extra.parenthesized = true': 'addParens(__a)',
|
|
23
|
+
'__a.node.extra?.parenthesized': 'hasParens(__a)',
|
|
24
|
+
[ASSIGN_OBJECT]: 'addParens(__a)',
|
|
25
|
+
});
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
const filesystem = require('./filesystem');
|
|
4
4
|
const json = require('./json');
|
|
5
5
|
const keyword = require('./keyword');
|
|
6
|
+
const parens = require('./parens');
|
|
6
7
|
|
|
7
8
|
module.exports = {
|
|
8
9
|
...filesystem,
|
|
9
10
|
...json,
|
|
10
11
|
...keyword,
|
|
12
|
+
...parens,
|
|
11
13
|
operator: `import {operator} from 'putout'`,
|
|
12
14
|
compare: 'const {compare} = operator',
|
|
13
15
|
compareAll: 'const {compareAll} = operator',
|
package/lib/index.js
CHANGED
|
@@ -60,6 +60,7 @@ const applyFixtureNameToMessage = require('./apply-fixture-name-to-message');
|
|
|
60
60
|
const applyVars = require('./apply-vars');
|
|
61
61
|
const declareTemplateVariables = require('./declare-template-variables');
|
|
62
62
|
const declarePathVariable = require('./declare-path-variable');
|
|
63
|
+
const applyParens = require('./apply-parens');
|
|
63
64
|
|
|
64
65
|
module.exports.rules = {
|
|
65
66
|
'apply-processors-destructuring': applyProcessorsDestructuring,
|
|
@@ -122,4 +123,5 @@ module.exports.rules = {
|
|
|
122
123
|
'apply-vars': applyVars,
|
|
123
124
|
'declare-template-variables': declareTemplateVariables,
|
|
124
125
|
'declare-path-variable': declarePathVariable,
|
|
126
|
+
'apply-parens': applyParens,
|
|
125
127
|
};
|
package/package.json
CHANGED