@putout/plugin-putout 25.2.0 → 25.4.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.
|
@@ -14,12 +14,14 @@ const NAMES = [
|
|
|
14
14
|
...FIXTURE,
|
|
15
15
|
'no report',
|
|
16
16
|
'no transform',
|
|
17
|
+
'no report after transform',
|
|
17
18
|
];
|
|
18
19
|
|
|
19
20
|
export const report = () => `Apply 'fixture' name to 'message'`;
|
|
20
21
|
|
|
21
22
|
export const match = () => ({
|
|
22
23
|
't.noReport(__a)': check,
|
|
24
|
+
't.noReportAfterTransform(__a)': check,
|
|
23
25
|
't.report(__a, __b)': check,
|
|
24
26
|
't.transform(__a)': check,
|
|
25
27
|
't.transform(__a, __b)': check,
|
|
@@ -32,6 +34,7 @@ export const replace = () => ({
|
|
|
32
34
|
't.transform(__a)': transform,
|
|
33
35
|
't.transform(__a, __b)': transform,
|
|
34
36
|
't.noTransform(__a)': transform,
|
|
37
|
+
't.noReportAfterTransform(__a)': transform,
|
|
35
38
|
});
|
|
36
39
|
|
|
37
40
|
const isTest = (path) => compare(path, 'test(__a, (t) => __body)', {
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import {types} from 'putout';
|
|
2
|
-
import {parseImportSpecifiers} from 'parse-import-specifiers';
|
|
3
|
-
|
|
4
|
-
const {isImportDeclaration} = types;
|
|
5
1
|
const noop = () => {};
|
|
6
2
|
|
|
7
3
|
export const report = () => `Use 'import * as plugin' instead of 'import plugin'`;
|
|
@@ -28,11 +24,6 @@ export const traverse = ({push, listStore, pathStore}) => ({
|
|
|
28
24
|
if (rules.length !== 1)
|
|
29
25
|
return;
|
|
30
26
|
|
|
31
|
-
const [first] = rules;
|
|
32
|
-
|
|
33
|
-
if (isImportDeclaration(first) && pathStore().length > 2)
|
|
34
|
-
return;
|
|
35
|
-
|
|
36
27
|
path.traverse(createImportVisitor({
|
|
37
28
|
push,
|
|
38
29
|
names: ['any'],
|
|
@@ -46,8 +37,11 @@ const createImportVisitor = ({push, names, pathStore = noop}) => ({
|
|
|
46
37
|
pathStore(path);
|
|
47
38
|
|
|
48
39
|
const {value} = path.node.source;
|
|
49
|
-
|
|
50
|
-
|
|
40
|
+
|
|
41
|
+
if (value.endsWith('.js'))
|
|
42
|
+
return;
|
|
43
|
+
|
|
44
|
+
const [first] = path.get('specifiers');
|
|
51
45
|
|
|
52
46
|
if (!first)
|
|
53
47
|
return;
|
|
@@ -58,14 +52,8 @@ const createImportVisitor = ({push, names, pathStore = noop}) => ({
|
|
|
58
52
|
if (first.isImportSpecifier())
|
|
59
53
|
return;
|
|
60
54
|
|
|
61
|
-
const {defaults, imports} = parseImportSpecifiers(specifiers);
|
|
62
|
-
|
|
63
|
-
if (defaults.length && imports.length)
|
|
64
|
-
return;
|
|
65
|
-
|
|
66
55
|
for (const name of names) {
|
|
67
|
-
if (!value.replace('
|
|
68
|
-
.includes('/'))
|
|
56
|
+
if (!value.replace('./', '').includes('/'))
|
|
69
57
|
continue;
|
|
70
58
|
|
|
71
59
|
if (value === name || value.startsWith(name) || name === 'any') {
|
|
@@ -13,10 +13,11 @@ export const fix = ({path, incorrect, correct}) => {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
const INCORRECT = {
|
|
16
|
-
TRANSFORM: /: (no transform|report|no report)/,
|
|
17
|
-
NO_TRANSFORM: /: (transform|report|no report)/,
|
|
18
|
-
REPORT: /: (no report|transform|no transform)/,
|
|
19
|
-
NO_REPORT: /: (report|transform|no transform)/,
|
|
16
|
+
TRANSFORM: /: (no report after transform|no transform|report|no report)/,
|
|
17
|
+
NO_TRANSFORM: /: (no report after transform|transform|report|no report)/,
|
|
18
|
+
REPORT: /: (no report after transform|no report|transform|no transform)/,
|
|
19
|
+
NO_REPORT: /: (no report after transform|report|transform|no transform)/,
|
|
20
|
+
NO_REPORT_AFTER_TRANSFORM: /: (report|transform|no transform|no report)/,
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
export const traverse = ({push}) => ({
|
|
@@ -45,12 +46,18 @@ export const traverse = ({push}) => ({
|
|
|
45
46
|
incorrect: INCORRECT.NO_REPORT,
|
|
46
47
|
correct: ': no report',
|
|
47
48
|
}),
|
|
49
|
+
't.noReportAfterTransform(__a)': convert({
|
|
50
|
+
push,
|
|
51
|
+
incorrect: INCORRECT.NO_REPORT_AFTER_TRANSFORM,
|
|
52
|
+
correct: ': no report after transform',
|
|
53
|
+
}),
|
|
48
54
|
});
|
|
49
55
|
|
|
50
56
|
const convert = ({push, correct, incorrect}) => (path) => {
|
|
51
57
|
const [is, messagePath] = isCorrect({
|
|
52
58
|
incorrect,
|
|
53
59
|
path,
|
|
60
|
+
correct,
|
|
54
61
|
});
|
|
55
62
|
|
|
56
63
|
if (is)
|
|
@@ -66,7 +73,7 @@ const convert = ({push, correct, incorrect}) => (path) => {
|
|
|
66
73
|
|
|
67
74
|
const CORRECT = true;
|
|
68
75
|
|
|
69
|
-
function isCorrect({path, incorrect}) {
|
|
76
|
+
function isCorrect({path, correct, incorrect}) {
|
|
70
77
|
const calleePath = path.findParent(isCallExpression);
|
|
71
78
|
|
|
72
79
|
if (!calleePath)
|
|
@@ -78,6 +85,10 @@ function isCorrect({path, incorrect}) {
|
|
|
78
85
|
return [CORRECT];
|
|
79
86
|
|
|
80
87
|
const {value} = messagePath.node;
|
|
88
|
+
|
|
89
|
+
if (value.includes(correct))
|
|
90
|
+
return [CORRECT];
|
|
91
|
+
|
|
81
92
|
const is = !incorrect.test(value);
|
|
82
93
|
|
|
83
94
|
return [is, messagePath];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-putout",
|
|
3
|
-
"version": "25.
|
|
3
|
+
"version": "25.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout plugin helps with plugins development",
|
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"fullstore": "^3.0.0",
|
|
35
35
|
"just-camel-case": "^6.2.0",
|
|
36
|
-
"parse-import-specifiers": "^1.0.2",
|
|
37
36
|
"try-catch": "^3.0.0"
|
|
38
37
|
},
|
|
39
38
|
"keywords": [
|