@putout/plugin-putout 23.1.0 → 23.2.1

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 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`.
@@ -57,7 +57,7 @@ const check = ({__a}, path) => {
57
57
  const regEnd = RegExp(`: ${name}$`);
58
58
  const regMiddle = RegExp(`: ${name}: .*`);
59
59
 
60
- return !(regEnd.test(value) || regMiddle.test(value));
60
+ return !regEnd.test(value) && !regMiddle.test(value);
61
61
  };
62
62
 
63
63
  const transform = ({__a}, path) => {
@@ -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',
@@ -40,6 +42,4 @@ module.exports = {
40
42
  setLiteralValue: 'const {setLiteralValue} = operator',
41
43
  matchFiles: 'const {matchFiles} = operator',
42
44
  ignore: 'const {ignore} = operator',
43
- addParens: 'const {addParens} = operator',
44
- removeParens: 'const {removeParens} = operator',
45
45
  };
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ addParens: 'const {addParens} = operator',
5
+ removeParens: 'const {removeParens} = operator',
6
+ hasParens: 'const {hasParens} = operator',
7
+ };
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
  };
@@ -8,7 +8,7 @@ const parentNodesList = [
8
8
  'export const replace = __',
9
9
  ];
10
10
 
11
- module.exports.report = () => `Simplify replce template`;
11
+ module.exports.report = () => `Simplify replace template`;
12
12
 
13
13
  module.exports.fix = (path) => {
14
14
  const {body} = path.node;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "23.1.0",
3
+ "version": "23.2.1",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin helps with plugins development",