@putout/plugin-putout 23.6.0 → 23.7.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 +19 -1
- package/lib/check-declare/index.js +62 -0
- package/lib/index.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,6 +37,7 @@ npm i @putout/plugin-putout -D
|
|
|
37
37
|
- ✅ [apply-parens](#apply-parens);
|
|
38
38
|
- ✅ [apply-short-processors](#apply-short-processors);
|
|
39
39
|
- ✅ [check-match](#check-match);
|
|
40
|
+
- ✅ [check-declare](#check-declare);
|
|
40
41
|
- ✅ [check-replace-code](#check-replace-code);
|
|
41
42
|
- ✅ [convert-add-argument-to-add-args](#convert-add-argument-to-add-test-args);
|
|
42
43
|
- ✅ [convert-babel-types](#convert-babel-types);
|
|
@@ -105,6 +106,7 @@ npm i @putout/plugin-putout -D
|
|
|
105
106
|
"putout/apply-for-of-to-track-file": "on",
|
|
106
107
|
"putout/apply-fixture-name-to-message": "on",
|
|
107
108
|
"putout/check-match": "on",
|
|
109
|
+
"putout/check-declare": "on",
|
|
108
110
|
"putout/check-replace-code": ["on", {
|
|
109
111
|
"once": true
|
|
110
112
|
}],
|
|
@@ -162,7 +164,6 @@ path.node = Identifier('x');
|
|
|
162
164
|
path.node = identifier('x');
|
|
163
165
|
```
|
|
164
166
|
|
|
165
|
-
|
|
166
167
|
## apply-processors-destructuring
|
|
167
168
|
|
|
168
169
|
### ❌ Example of incorrect code
|
|
@@ -864,6 +865,23 @@ module.exports.match = () => ({
|
|
|
864
865
|
});
|
|
865
866
|
```
|
|
866
867
|
|
|
868
|
+
## check-declare
|
|
869
|
+
|
|
870
|
+
Checks that [Declarator](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#declarator) transform is possible.
|
|
871
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/9fccb187bb8933afff0dc0db57b3cea8/25cb812978fadb4efb5f0cb44058a61f70f8b78e):
|
|
872
|
+
|
|
873
|
+
### ❌ Example of incorrect code
|
|
874
|
+
|
|
875
|
+
```js
|
|
876
|
+
module.exports.declare = () => ({
|
|
877
|
+
isNumber: 'const isNumber = () => {}',
|
|
878
|
+
isString: 'const isNumber = () => {}',
|
|
879
|
+
});
|
|
880
|
+
```
|
|
881
|
+
|
|
882
|
+
☝️ *There is no `fix` for this rule, it used internally to be more confident about `test coverage`, because of declaration form, transforms cannon be checked by `nyc` and `c8`, and uncovered lines can find unfixable false positives when running on code.
|
|
883
|
+
This is additional tests, if you forget to test some case (from a big list of rules that is supported) it will be checked with this `rule` and make transforms more stable.*
|
|
884
|
+
|
|
867
885
|
## check-replace-code
|
|
868
886
|
|
|
869
887
|
Checks that [Replacer](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#replacer) transform is possible.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const tryCatch = require('try-catch');
|
|
4
|
+
const putout = require('putout');
|
|
5
|
+
|
|
6
|
+
const {types, operator} = putout;
|
|
7
|
+
|
|
8
|
+
const noop = () => {};
|
|
9
|
+
const {getTemplateValues} = operator;
|
|
10
|
+
|
|
11
|
+
const DECLARE_ESM = 'export const declare = () => __object';
|
|
12
|
+
const DECLARE_COMMONJS = 'module.exports.declare = () => __object';
|
|
13
|
+
const COMMONJS = 'module.exports = __object';
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
isTemplateLiteral,
|
|
17
|
+
isStringLiteral,
|
|
18
|
+
} = types;
|
|
19
|
+
|
|
20
|
+
module.exports.report = ({message}) => message;
|
|
21
|
+
|
|
22
|
+
module.exports.fix = noop;
|
|
23
|
+
module.exports.traverse = ({push}) => ({
|
|
24
|
+
[DECLARE_ESM]: createCheck(push, DECLARE_ESM),
|
|
25
|
+
[DECLARE_COMMONJS]: createCheck(push, DECLARE_COMMONJS),
|
|
26
|
+
[COMMONJS]: createCheck(push, COMMONJS),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const createCheck = (push, template) => (path) => {
|
|
30
|
+
const {__object} = getTemplateValues(path, template);
|
|
31
|
+
|
|
32
|
+
const lines = [];
|
|
33
|
+
|
|
34
|
+
for (const {value} of __object.properties) {
|
|
35
|
+
let current = '';
|
|
36
|
+
|
|
37
|
+
if (isStringLiteral(value)) {
|
|
38
|
+
current = value.value;
|
|
39
|
+
} else if (isTemplateLiteral(value)) {
|
|
40
|
+
if (value.quasis.length > 1)
|
|
41
|
+
continue;
|
|
42
|
+
|
|
43
|
+
current = value.quasis[0].value.cooked;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (/^(const|import)/.test(current))
|
|
47
|
+
lines.push(current);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const source = lines.join(';\n');
|
|
51
|
+
const [error] = tryCatch(putout.parse, source);
|
|
52
|
+
|
|
53
|
+
if (!error)
|
|
54
|
+
return;
|
|
55
|
+
|
|
56
|
+
const {message} = error;
|
|
57
|
+
|
|
58
|
+
push({
|
|
59
|
+
path,
|
|
60
|
+
message,
|
|
61
|
+
});
|
|
62
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const applyRemove = require('./apply-remove');
|
|
|
7
7
|
const applyInsertBefore = require('./apply-insert-before');
|
|
8
8
|
const applyInsertAfter = require('./apply-insert-after');
|
|
9
9
|
const applyDeclare = require('./apply-declare');
|
|
10
|
+
const checkDeclare = require('./check-declare');
|
|
10
11
|
const checkReplaceCode = require('./check-replace-code');
|
|
11
12
|
const checkMatch = require('./check-match');
|
|
12
13
|
const convertPutoutTestToCreateTest = require('./convert-putout-test-to-create-test');
|
|
@@ -71,6 +72,7 @@ module.exports.rules = {
|
|
|
71
72
|
'apply-insert-before': applyInsertBefore,
|
|
72
73
|
'apply-insert-after': applyInsertAfter,
|
|
73
74
|
'apply-declare': applyDeclare,
|
|
75
|
+
'check-declare': checkDeclare,
|
|
74
76
|
'check-replace-code': checkReplaceCode,
|
|
75
77
|
'check-match': checkMatch,
|
|
76
78
|
'convert-putout-test-to-create-test': convertPutoutTestToCreateTest,
|
package/package.json
CHANGED