@putout/plugin-putout 14.6.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/index.js +2 -0
- package/package.json +1 -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
|
+
};
|
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