@putout/plugin-putout 14.4.0 → 14.6.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.
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {parseImportSpecifiers} = require('parse-import-specifiers');
|
|
4
|
+
const noop = () => {};
|
|
5
|
+
|
|
3
6
|
module.exports.report = () => `Use 'import * as plugin' instead of 'import plugin'`;
|
|
4
7
|
|
|
5
8
|
module.exports.fix = ({first}) => {
|
|
6
9
|
first.node.type = 'ImportNamespaceSpecifier';
|
|
7
10
|
};
|
|
8
11
|
|
|
9
|
-
module.exports.traverse = ({push, listStore}) => ({
|
|
12
|
+
module.exports.traverse = ({push, listStore, pathStore}) => ({
|
|
10
13
|
'export const rules = __object': listStore,
|
|
14
|
+
'import {createTest} from "@putout/test"': listStore,
|
|
11
15
|
...createImportVisitor({
|
|
16
|
+
pathStore,
|
|
12
17
|
push,
|
|
13
18
|
names: [
|
|
14
19
|
'./index.js',
|
|
@@ -19,7 +24,10 @@ module.exports.traverse = ({push, listStore}) => ({
|
|
|
19
24
|
exit(path) {
|
|
20
25
|
const rules = listStore();
|
|
21
26
|
|
|
22
|
-
if (
|
|
27
|
+
if (rules.length !== 1)
|
|
28
|
+
return;
|
|
29
|
+
|
|
30
|
+
if (pathStore().length > 2)
|
|
23
31
|
return;
|
|
24
32
|
|
|
25
33
|
path.traverse(createImportVisitor({
|
|
@@ -30,10 +38,13 @@ module.exports.traverse = ({push, listStore}) => ({
|
|
|
30
38
|
},
|
|
31
39
|
});
|
|
32
40
|
|
|
33
|
-
const createImportVisitor = ({push, names}) => ({
|
|
41
|
+
const createImportVisitor = ({push, names, pathStore = noop}) => ({
|
|
34
42
|
ImportDeclaration(path) {
|
|
43
|
+
pathStore(path);
|
|
44
|
+
|
|
35
45
|
const {value} = path.node.source;
|
|
36
|
-
const
|
|
46
|
+
const specifiers = path.get('specifiers');
|
|
47
|
+
const [first] = specifiers;
|
|
37
48
|
|
|
38
49
|
if (!first)
|
|
39
50
|
return;
|
|
@@ -41,6 +52,15 @@ const createImportVisitor = ({push, names}) => ({
|
|
|
41
52
|
if (first.isImportNamespaceSpecifier())
|
|
42
53
|
return;
|
|
43
54
|
|
|
55
|
+
if (first.isImportSpecifier())
|
|
56
|
+
return;
|
|
57
|
+
|
|
58
|
+
const {defaults, imports} = parseImportSpecifiers(specifiers);
|
|
59
|
+
|
|
60
|
+
if (defaults.length && imports.length) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
44
64
|
for (const name of names) {
|
|
45
65
|
if (value === name || name === 'any') {
|
|
46
66
|
push({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-putout",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.6.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",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"fullstore": "^3.0.0",
|
|
29
29
|
"just-camel-case": "^6.0.1",
|
|
30
|
+
"parse-import-specifiers": "^1.0.2",
|
|
30
31
|
"try-catch": "^3.0.0"
|
|
31
32
|
},
|
|
32
33
|
"keywords": [
|