@putout/plugin-putout 14.5.0 β 14.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 +24 -0
- package/lib/add-index-to-import/index.js +46 -0
- package/lib/apply-namaspace-specifier/index.js +20 -4
- package/lib/index.js +2 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ npm i @putout/plugin-putout -D
|
|
|
26
26
|
"putout/apply-namaspace-specifier": "on",
|
|
27
27
|
"putout/add-args": "on",
|
|
28
28
|
"putout/add-push": "on",
|
|
29
|
+
"putout/add-index-to-import": "on",
|
|
29
30
|
"putout/check-match": "on",
|
|
30
31
|
"putout/check-replace-code": "on",
|
|
31
32
|
"putout/convert-putout-test-to-create-test": "on",
|
|
@@ -661,6 +662,29 @@ module.exports.traverse = ({push}) => ({
|
|
|
661
662
|
});
|
|
662
663
|
```
|
|
663
664
|
|
|
665
|
+
## add-index-to-import
|
|
666
|
+
|
|
667
|
+
ESM doesn't add `index.js`, so it can be left after [`@putout/plugin-convert-esm-to-commonjs`](https://github.com/coderaiser/putout/blob/master/packages/plugin-convert-esm-to-commonjs#readme).
|
|
668
|
+
Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b7c489710767efee95ecf3dd16e232a2/9f974f0a345ef4d0cb39b011097dff82e6c32b75).
|
|
669
|
+
|
|
670
|
+
### β Example of incorrect code
|
|
671
|
+
|
|
672
|
+
```js
|
|
673
|
+
import insertRust from './insert-rust.js';
|
|
674
|
+
import addAction from './add-action.js';
|
|
675
|
+
|
|
676
|
+
export const rules = {};
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
### β
Example of correct code
|
|
680
|
+
|
|
681
|
+
```js
|
|
682
|
+
import insertRust from './insert-rust/index.js';
|
|
683
|
+
import addAction from './add-action/index.js';
|
|
684
|
+
|
|
685
|
+
export const rules = {};
|
|
686
|
+
```
|
|
687
|
+
|
|
664
688
|
## convert-add-argument-to-add-args
|
|
665
689
|
|
|
666
690
|
### β Example of incorrect code
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {operator} = require('putout');
|
|
4
|
+
const {
|
|
5
|
+
traverse,
|
|
6
|
+
setLiteralValue,
|
|
7
|
+
} = operator;
|
|
8
|
+
|
|
9
|
+
module.exports.report = () => `Add 'index.js' to nested import`;
|
|
10
|
+
|
|
11
|
+
module.exports.fix = (path) => {
|
|
12
|
+
const {source} = path.node;
|
|
13
|
+
const {value} = source;
|
|
14
|
+
|
|
15
|
+
if (value.endsWith('js')) {
|
|
16
|
+
setLiteralValue(source, value.replace('.js', '/index.js'));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
setLiteralValue(source, `${value}/index.js`);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
module.exports.traverse = ({push, listStore}) => ({
|
|
24
|
+
'export const rules = __object': listStore,
|
|
25
|
+
'Program': {
|
|
26
|
+
exit: (path) => {
|
|
27
|
+
const rules = listStore();
|
|
28
|
+
|
|
29
|
+
if (!rules.length)
|
|
30
|
+
return;
|
|
31
|
+
|
|
32
|
+
traverse(path, {
|
|
33
|
+
ImportDeclaration: createImportVisitor(push),
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const createImportVisitor = (push) => (path) => {
|
|
40
|
+
const {value} = path.node.source;
|
|
41
|
+
|
|
42
|
+
if (value.endsWith('index.js'))
|
|
43
|
+
return;
|
|
44
|
+
|
|
45
|
+
push(path);
|
|
46
|
+
};
|
|
@@ -1,15 +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,
|
|
11
14
|
'import {createTest} from "@putout/test"': listStore,
|
|
12
15
|
...createImportVisitor({
|
|
16
|
+
pathStore,
|
|
13
17
|
push,
|
|
14
18
|
names: [
|
|
15
19
|
'./index.js',
|
|
@@ -20,7 +24,10 @@ module.exports.traverse = ({push, listStore}) => ({
|
|
|
20
24
|
exit(path) {
|
|
21
25
|
const rules = listStore();
|
|
22
26
|
|
|
23
|
-
if (
|
|
27
|
+
if (rules.length !== 1)
|
|
28
|
+
return;
|
|
29
|
+
|
|
30
|
+
if (pathStore().length > 2)
|
|
24
31
|
return;
|
|
25
32
|
|
|
26
33
|
path.traverse(createImportVisitor({
|
|
@@ -31,10 +38,13 @@ module.exports.traverse = ({push, listStore}) => ({
|
|
|
31
38
|
},
|
|
32
39
|
});
|
|
33
40
|
|
|
34
|
-
const createImportVisitor = ({push, names}) => ({
|
|
41
|
+
const createImportVisitor = ({push, names, pathStore = noop}) => ({
|
|
35
42
|
ImportDeclaration(path) {
|
|
43
|
+
pathStore(path);
|
|
44
|
+
|
|
36
45
|
const {value} = path.node.source;
|
|
37
|
-
const
|
|
46
|
+
const specifiers = path.get('specifiers');
|
|
47
|
+
const [first] = specifiers;
|
|
38
48
|
|
|
39
49
|
if (!first)
|
|
40
50
|
return;
|
|
@@ -45,6 +55,12 @@ const createImportVisitor = ({push, names}) => ({
|
|
|
45
55
|
if (first.isImportSpecifier())
|
|
46
56
|
return;
|
|
47
57
|
|
|
58
|
+
const {defaults, imports} = parseImportSpecifiers(specifiers);
|
|
59
|
+
|
|
60
|
+
if (defaults.length && imports.length) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
48
64
|
for (const name of names) {
|
|
49
65
|
if (value === name || name === 'any') {
|
|
50
66
|
push({
|
package/lib/index.js
CHANGED
|
@@ -40,6 +40,7 @@ const includer = require('./includer');
|
|
|
40
40
|
const createTest = require('./create-test');
|
|
41
41
|
const applyNamaspaceSpecifier = require('./apply-namaspace-specifier');
|
|
42
42
|
const convertGetRuleToRequire = require('./convert-get-rule-to-require');
|
|
43
|
+
const addIndexToImport = require('./add-index-to-import');
|
|
43
44
|
|
|
44
45
|
module.exports.rules = {
|
|
45
46
|
'apply-processors-destructuring': applyProcessorsDestructuring,
|
|
@@ -82,4 +83,5 @@ module.exports.rules = {
|
|
|
82
83
|
'create-test': createTest,
|
|
83
84
|
'apply-namaspace-specifier': applyNamaspaceSpecifier,
|
|
84
85
|
'convert-get-rule-to-require': convertGetRuleToRequire,
|
|
86
|
+
'add-index-to-import': addIndexToImport,
|
|
85
87
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-putout",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.7.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": [
|