@putout/plugin-putout 22.8.0 → 22.10.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 CHANGED
@@ -62,6 +62,7 @@ npm i @putout/plugin-putout -D
62
62
  - ✅ [create-test](#create-test);
63
63
  - ✅ [declare](#declare);
64
64
  - ✅ [declare-template-variables](#declare-template-variables);
65
+ - ✅ [declare-path-variable](#declare-path-variable);
65
66
  - ✅ [includer](#includer);
66
67
  - ✅ [move-require-on-top-level](#move-require-on-top-level);
67
68
  - ✅ [remove-empty-array-from-process](#remove-empty-array-from-process);
@@ -129,6 +130,7 @@ npm i @putout/plugin-putout -D
129
130
  "putout/shorten-imports": "on",
130
131
  "putout/declare": "on",
131
132
  "putout/declare-template-variables": "on",
133
+ "putout/declare-path-variable": "on",
132
134
  "putout/includer": "on",
133
135
  "putout/move-require-on-top-level": "on",
134
136
  "putout/replace-test-message": "on",
@@ -900,6 +902,36 @@ export const match = () => ({
900
902
  });
901
903
  ```
902
904
 
905
+ ## declare-path-variable
906
+
907
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b485bf55785ea836408d0d45c492c3e4/2a0b465076242ebf6a0d8015a90ccf7b0b660a42).
908
+
909
+ ### ❌ Example of incorrect code
910
+
911
+ ```js
912
+ export const match = () => ({
913
+ '__x __a __expr': ({__x}) => {
914
+ if (path.isNextPunctuator(assign))
915
+ return false;
916
+
917
+ return isOneOfKeywords(__x, ['const', 'let', 'var']);
918
+ },
919
+ });
920
+ ```
921
+
922
+ ### ✅ Example of correct code
923
+
924
+ ```js
925
+ export const match = () => ({
926
+ '__x __a __expr': ({__x}) => {
927
+ if (path.isNextPunctuator(assign))
928
+ return false;
929
+
930
+ return isOneOfKeywords(__x, ['const', 'let', 'var']);
931
+ },
932
+ });
933
+ ```
934
+
903
935
  ## add-places-to-compare-places"
904
936
 
905
937
  ### ❌ Example of incorrect code
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ const {operator} = require('putout');
4
+ const {getBindingPath} = operator;
5
+
6
+ module.exports.report = () => `Declare 'path' variable`;
7
+
8
+ module.exports.match = () => ({
9
+ '(__a) => __body': (vars, path) => {
10
+ let is = false;
11
+
12
+ path.traverse({
13
+ ReferencedIdentifier(refPath) {
14
+ if (refPath.node.name !== 'path')
15
+ return;
16
+
17
+ if (getBindingPath(refPath, 'path'))
18
+ return;
19
+
20
+ is = true;
21
+ path.stop();
22
+ },
23
+ });
24
+
25
+ return is;
26
+ },
27
+ });
28
+
29
+ module.exports.replace = () => ({
30
+ '(__a) => __body': '(__a, path) => __body',
31
+ });
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
- const {types} = require('putout');
3
+ const {types, operator} = require('putout');
4
+ const {getBindingPath} = operator;
4
5
  const {
5
6
  ObjectPattern,
6
7
  isIdentifier,
@@ -28,23 +29,29 @@ module.exports.fix = ({path, node}) => {
28
29
  };
29
30
 
30
31
  module.exports.traverse = ({push}) => ({
31
- '(vars, path) => __body': (path) => {
32
- path.traverse({
33
- ReferencedIdentifier(refPath) {
34
- const {node} = refPath;
35
- const {name} = node;
36
-
37
- if (!name.startsWith('__'))
38
- return;
39
-
40
- if (refPath.scope.bindings[name])
41
- return;
42
-
43
- push({
44
- path,
45
- node,
46
- });
47
- },
48
- });
49
- },
32
+ '(__a, path) => __body': process(push),
33
+ '(__a) => __body': process(push),
50
34
  });
35
+
36
+ const process = (push) => (path) => {
37
+ if (!path.parentPath.isObjectProperty())
38
+ return;
39
+
40
+ path.traverse({
41
+ ReferencedIdentifier(refPath) {
42
+ const {node} = refPath;
43
+ const {name} = node;
44
+
45
+ if (!name.startsWith('__'))
46
+ return;
47
+
48
+ if (getBindingPath(refPath, name))
49
+ return;
50
+
51
+ push({
52
+ path,
53
+ node,
54
+ });
55
+ },
56
+ });
57
+ };
package/lib/index.js CHANGED
@@ -59,6 +59,7 @@ const addPathArgToVisitors = require('./add-path-arg-to-visitors');
59
59
  const applyFixtureNameToMessage = require('./apply-fixture-name-to-message');
60
60
  const applyVars = require('./apply-vars');
61
61
  const declareTemplateVariables = require('./declare-template-variables');
62
+ const declarePathVariable = require('./declare-path-variable');
62
63
 
63
64
  module.exports.rules = {
64
65
  'apply-processors-destructuring': applyProcessorsDestructuring,
@@ -120,4 +121,5 @@ module.exports.rules = {
120
121
  'apply-fixture-name-to-message': applyFixtureNameToMessage,
121
122
  'apply-vars': applyVars,
122
123
  'declare-template-variables': declareTemplateVariables,
124
+ 'declare-path-variable': declarePathVariable,
123
125
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "22.8.0",
3
+ "version": "22.10.0",
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",