Skip to content

Commit 9f8bd36

Browse files
committed
feature: @putout/plugin-putout: apply-exports-to-rename-files: add
1 parent 1bea006 commit 9f8bd36

File tree

13 files changed

+135
-4
lines changed

13 files changed

+135
-4
lines changed

packages/plugin-putout/README.md

+40
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ npm i @putout/plugin-putout -D
2727
-[apply-declare](#apply-declare);
2828
-[apply-exports-to-add-args](#apply-exports-to-add-args);
2929
-[apply-exports-to-match-files](#apply-exports-to-match-files);
30+
-[apply-exports-to-rename-files](#apply-exports-to-rename-files);
3031
-[apply-for-of-to-track-file](#apply-for-of-to-track-file);
3132
-[apply-fixture-name-to-message](#apply-fixture-name-to-message);
3233
-[apply-insert-after](#apply-insert-after);
@@ -100,6 +101,7 @@ npm i @putout/plugin-putout -D
100101
"putout/apply-declare": "on",
101102
"putout/apply-exports-to-add-args": "on",
102103
"putout/apply-exports-to-match-files": "on",
104+
"putout/apply-exports-to-rename-files": "on",
103105
"putout/apply-report": "on",
104106
"putout/apply-processors-destructuring": "on",
105107
"putout/apply-rename": "on",
@@ -516,6 +518,44 @@ export {
516518
};
517519
```
518520
521+
## apply-exports-to-rename-files
522+
523+
Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/999f7a582825fa88691ba87324365f3f/c679723b7ff2159d738ab7681f8c7c6460dd4326).
524+
525+
### ❌ Example of incorrect code
526+
527+
```js
528+
export default renameFiles({
529+
type: 'module',
530+
mask: '*.mjs',
531+
rename(name) {
532+
return name.replace(/mjs$/, 'js');
533+
},
534+
});
535+
```
536+
537+
### ✅ Example of correct code
538+
539+
```js
540+
const {
541+
report,
542+
fix,
543+
scan,
544+
} = renameFiles({
545+
type: 'module',
546+
mask: '*.mjs',
547+
rename(name) {
548+
return name.replace(/mjs$/, 'js');
549+
},
550+
});
551+
552+
export {
553+
report,
554+
fix,
555+
scan,
556+
};
557+
```
558+
519559
## apply-async-formatter
520560
521561
### ❌ Example of incorrect code

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const report = () => `Apply exports to 'addArgs'`;
1+
export const report = () => `Apply exports to 'addArgs()'`;
22

33
export const replace = () => ({
44
'export default addArgs(__args)': `{

packages/plugin-putout/lib/apply-exports-to-add-args/index.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const test = createTest(import.meta.url, {
88
});
99

1010
test('putout: apply-exports-to-add-args: report', (t) => {
11-
t.report('apply-exports-to-add-args', `Apply exports to 'addArgs'`);
11+
t.report('apply-exports-to-add-args', `Apply exports to 'addArgs()'`);
1212
t.end();
1313
});
1414

packages/plugin-putout/lib/apply-exports-to-match-files/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const report = () => `Apply 'exports' to 'matchFiles`;
1+
export const report = () => `Apply 'exports' to 'matchFiles()'`;
22

33
export const replace = () => ({
44
'export default matchFiles(__args)': `{

packages/plugin-putout/lib/apply-exports-to-match-files/index.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const test = createTest(import.meta.url, {
88
});
99

1010
test('putout: apply-exports-to-match-files: report', (t) => {
11-
t.report('apply-exports-to-match-files', `Apply 'exports' to 'matchFiles`);
11+
t.report('apply-exports-to-match-files', `Apply 'exports' to 'matchFiles()'`);
1212
t.end();
1313
});
1414

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
const {
3+
report,
4+
fix,
5+
scan,
6+
} = matchFiles({
7+
type: 'module',
8+
mask: '*.mjs',
9+
rename(name) {
10+
return name.replace(/mjs$/, 'js');
11+
},
12+
});
13+
export {
14+
report,
15+
fix,
16+
scan,
17+
};
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default renameFiles({
2+
type: 'module',
3+
mask: '*.mjs',
4+
rename(name) {
5+
return name.replace(/mjs$/, 'js');
6+
},
7+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const report = () => `Apply 'exports' to 'renameFiles()`;
2+
3+
export const replace = () => ({
4+
'export default renameFiles(__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-rename-files', plugin],
7+
],
8+
});
9+
10+
test('putout: apply-exports-to-rename-files: report', (t) => {
11+
t.report('apply-exports-to-rename-files', `Apply 'exports' to 'renameFiles()`);
12+
t.end();
13+
});
14+
15+
test('putout: apply-exports-to-rename-files: transform', (t) => {
16+
t.transform('apply-exports-to-rename-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 applyExportsToRenameFiles from './apply-exports-to-rename-files/index.js';
12
import * as applyExportsToMatchFiles from './apply-exports-to-match-files/index.js';
23
import * as applyProcessorsDestructuring from './apply-processors-destructuring/index.js';
34
import * as applyAsyncFormatter from './apply-async-formatter/index.js';
@@ -134,4 +135,5 @@ export const rules = {
134135
'apply-create-nested-directory': applyCreateNestedDirectory,
135136
'apply-report': applyReport,
136137
'apply-exports-to-match-files': applyExportsToMatchFiles,
138+
'apply-exports-to-rename-files': applyExportsToRenameFiles,
137139
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {operator} from 'putout';
2+
3+
const {matchFiles} = operator;
4+
5+
{
6+
const {
7+
report,
8+
fix,
9+
scan,
10+
} = matchFiles({
11+
type: 'module',
12+
mask: '*.mjs',
13+
rename(name) {
14+
return name.replace(/mjs$/, 'js');
15+
},
16+
});
17+
export {
18+
report,
19+
fix,
20+
scan,
21+
};
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default renameFiles({
2+
type: 'module',
3+
mask: '*.mjs',
4+
rename(name) {
5+
return name.replace(/mjs$/, 'js');
6+
},
7+
});

packages/plugin-putout/test/putout.js

+5
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,8 @@ test('plugin-putout: transform: apply-exports-to-match-files', (t) => {
329329
t.transform('apply-exports-to-match-files');
330330
t.end();
331331
});
332+
333+
test('plugin-putout: transform: apply-exports-to-rename-files', (t) => {
334+
t.transform('apply-exports-to-rename-files');
335+
t.end();
336+
});

0 commit comments

Comments
 (0)