Skip to content

Commit a5e022b

Browse files
committed
feature: @putout/plugin-putout: apply-exports-to-match-files: add
1 parent 0de86c5 commit a5e022b

11 files changed

+111
-2
lines changed

packages/plugin-putout/README.md

+32
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ npm i @putout/plugin-putout -D
2626
-[apply-create-nested-directory](#apply-create-nested-directory);
2727
-[apply-declare](#apply-declare);
2828
-[apply-exports-to-add-args](#apply-exports-to-add-args);
29+
-[apply-exports-to-match-files](#apply-exports-to-match-files);
2930
-[apply-for-of-to-track-file](#apply-for-of-to-track-file);
3031
-[apply-fixture-name-to-message](#apply-fixture-name-to-message);
3132
-[apply-insert-after](#apply-insert-after);
@@ -98,6 +99,7 @@ npm i @putout/plugin-putout -D
9899
"putout/apply-async-formatter": "on",
99100
"putout/apply-declare": "on",
100101
"putout/apply-exports-to-add-args": "on",
102+
"putout/apply-exports-to-match-files": "on",
101103
"putout/apply-report": "on",
102104
"putout/apply-processors-destructuring": "on",
103105
"putout/apply-rename": "on",
@@ -484,6 +486,36 @@ export {
484486
};
485487
```
486488
489+
## apply-exports-to-match-files
490+
491+
Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d40ac85b974249c51f9874919468fd30/4194c9b21d065bd1359ffc7298aaeb1835fbbb48).
492+
493+
### ❌ Example of incorrect code
494+
495+
```js
496+
export default matchFiles({
497+
'*.cjs': plugin,
498+
});
499+
```
500+
501+
### ✅ Example of correct code
502+
503+
```js
504+
const {
505+
report,
506+
fix,
507+
scan,
508+
} = matchFiles({
509+
'*.cjs': plugin,
510+
});
511+
512+
export {
513+
report,
514+
fix,
515+
scan,
516+
};
517+
```
518+
487519
## apply-async-formatter
488520
489521
### ❌ Example of incorrect code

packages/plugin-putout/lib/apply-exports-to-add-args/fixture/apply-exports-to-add-args-fix.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
report,
99
fix,
1010
traverse,
11-
};}
11+
};
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
const {
3+
report,
4+
fix,
5+
scan,
6+
} = matchFiles({
7+
'*.cjs': plugin,
8+
});
9+
export {
10+
report,
11+
fix,
12+
scan,
13+
};
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default matchFiles({
2+
'*.cjs': plugin,
3+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const report = () => `Apply 'exports' to 'matchFiles`;
2+
3+
export const replace = () => ({
4+
'export default matchFiles(__args)': `{
5+
const {report, fix, scan} = matchFiles(__args);
6+
export {
7+
report,
8+
fix,
9+
scan,
10+
};
11+
}`,
12+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
3+
4+
const test = createTest(import.meta.url, {
5+
plugins: [
6+
['apply-exports-to-match-files', plugin],
7+
],
8+
});
9+
10+
test('putout: apply-exports-to-match-files: report', (t) => {
11+
t.report('apply-exports-to-match-files', `Apply 'exports' to 'matchFiles`);
12+
t.end();
13+
});
14+
15+
test('putout: apply-exports-to-match-files: transform', (t) => {
16+
t.transform('apply-exports-to-match-files');
17+
t.end();
18+
});

packages/plugin-putout/lib/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as applyExportsToMatchFiles from './apply-exports-to-match-files/index.js';
12
import * as applyProcessorsDestructuring from './apply-processors-destructuring/index.js';
23
import * as applyAsyncFormatter from './apply-async-formatter/index.js';
34
import * as applyCreateTest from './apply-create-test/index.js';
@@ -132,4 +133,5 @@ export const rules = {
132133
'apply-lowercase-to-node-builders': applyLowercaseToNodeBuilders,
133134
'apply-create-nested-directory': applyCreateNestedDirectory,
134135
'apply-report': applyReport,
136+
'apply-exports-to-match-files': applyExportsToMatchFiles,
135137
};

packages/plugin-putout/test/fixture/apply-exports-to-add-args-fix.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ const {addArgs} = operator;
1111
report,
1212
fix,
1313
traverse,
14-
};}
14+
};
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {operator} from 'putout';
2+
3+
const {matchFiles} = operator;
4+
5+
{
6+
const {
7+
report,
8+
fix,
9+
scan,
10+
} = matchFiles({
11+
'*.cjs': plugin,
12+
});
13+
export {
14+
report,
15+
fix,
16+
scan,
17+
};
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default matchFiles({
2+
'*.cjs': plugin,
3+
});

packages/plugin-putout/test/putout.js

+5
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,8 @@ test('plugin-putout: transform: apply-exports-to-add-args', (t) => {
324324
t.transform('apply-exports-to-add-args');
325325
t.end();
326326
});
327+
328+
test('plugin-putout: transform: apply-exports-to-match-files', (t) => {
329+
t.transform('apply-exports-to-match-files');
330+
t.end();
331+
});

0 commit comments

Comments
 (0)