@putout/plugin-putout 24.4.1 → 24.5.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 CHANGED
@@ -25,6 +25,7 @@ npm i @putout/plugin-putout -D
25
25
  - ✅ [apply-create-test](#apply-create-test);
26
26
  - ✅ [apply-create-nested-directory](#apply-create-nested-directory);
27
27
  - ✅ [apply-declare](#apply-declare);
28
+ - ✅ [apply-exports](#apply-exports);
28
29
  - ✅ [apply-exports-to-add-args](#apply-exports-to-add-args);
29
30
  - ✅ [apply-exports-to-match-files](#apply-exports-to-match-files);
30
31
  - ✅ [apply-exports-to-rename-files](#apply-exports-to-rename-files);
@@ -99,6 +100,7 @@ npm i @putout/plugin-putout -D
99
100
  "putout/apply-create-nested-directory": "on",
100
101
  "putout/apply-async-formatter": "on",
101
102
  "putout/apply-declare": "on",
103
+ "putout/apply-exports": "on",
102
104
  "putout/apply-exports-to-add-args": "on",
103
105
  "putout/apply-exports-to-match-files": "on",
104
106
  "putout/apply-exports-to-rename-files": "on",
@@ -462,6 +464,53 @@ module.exports.declare = () => ({
462
464
  });
463
465
  ```
464
466
 
467
+ ## apply-exports
468
+
469
+ Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/cf35de5e80e8f7aad866358a50c5eded/0af6142fc9c9e71ac2a2aa96cb85613dd95c9fbf).
470
+ Possible configuration:
471
+
472
+ ```json
473
+ {
474
+ "rules": {
475
+ "putout/apply-exports": {
476
+ "addArgs": [
477
+ "report",
478
+ "fix",
479
+ "scan"
480
+ ]
481
+ }
482
+ }
483
+ }
484
+ ```
485
+
486
+ ### ❌ Example of incorrect code
487
+
488
+ ```js
489
+ export default createRenameProperty([
490
+ ...v32,
491
+ ...v29,
492
+ ]);
493
+ ```
494
+
495
+ ### ✅ Example of correct code
496
+
497
+ ```js
498
+ const {
499
+ report,
500
+ fix,
501
+ scan,
502
+ } = createRenameProperty([
503
+ ...v32,
504
+ ...v29,
505
+ ]);
506
+
507
+ export {
508
+ report,
509
+ fix,
510
+ scan,
511
+ };
512
+ ```
513
+
465
514
  ## apply-exports-to-add-args
466
515
 
467
516
  Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/cf35de5e80e8f7aad866358a50c5eded/0af6142fc9c9e71ac2a2aa96cb85613dd95c9fbf).
@@ -0,0 +1,8 @@
1
+ import {createApplyExports} from '../create-apply-exports.js';
2
+
3
+ const {report, replace} = createApplyExports();
4
+
5
+ export {
6
+ report,
7
+ replace,
8
+ };
@@ -1,12 +1,14 @@
1
- export const report = () => `Apply exports to 'addArgs()'`;
1
+ import {createApplyExports} from '../create-apply-exports.js';
2
2
 
3
- export const replace = () => ({
4
- 'export default addArgs(__args)': `{
5
- const {report, fix, traverse} = addArgs(__args);
6
- export {
7
- report,
8
- fix,
9
- traverse,
10
- }
11
- }`,
3
+ const {report, replace} = createApplyExports({
4
+ addArgs: [
5
+ 'report',
6
+ 'fix',
7
+ 'traverse',
8
+ ],
12
9
  });
10
+
11
+ export {
12
+ report,
13
+ replace,
14
+ };
@@ -1,12 +1,14 @@
1
- export const report = () => `Apply 'exports' to 'matchFiles()'`;
1
+ import {createApplyExports} from '../create-apply-exports.js';
2
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
- }`,
3
+ const {report, replace} = createApplyExports({
4
+ matchFiles: [
5
+ 'report',
6
+ 'fix',
7
+ 'scan',
8
+ ],
12
9
  });
10
+
11
+ export {
12
+ report,
13
+ replace,
14
+ };
@@ -1,12 +1,14 @@
1
- export const report = () => `Apply 'exports' to 'renameFiles()`;
1
+ import {createApplyExports} from '../create-apply-exports.js';
2
2
 
3
- export const replace = () => ({
4
- 'export default renameFiles(__args)': `{
5
- const {report, fix, scan} = renameFiles(__args);
6
- export {
7
- report,
8
- fix,
9
- scan,
10
- };
11
- }`,
3
+ const {report, replace} = createApplyExports({
4
+ renameFiles: [
5
+ 'report',
6
+ 'fix',
7
+ 'scan',
8
+ ],
12
9
  });
10
+
11
+ export {
12
+ report,
13
+ replace,
14
+ };
@@ -0,0 +1,36 @@
1
+ const {entries} = Object;
2
+
3
+ const report = (path) => {
4
+ const namePath = path.get('declaration.callee');
5
+ const {name} = namePath.node;
6
+
7
+ return `Apply exports to '${name}()'`;
8
+ };
9
+
10
+ export const createApplyExports = (defaultOptions = {}) => {
11
+ return {
12
+ report,
13
+ replace: createReplace(defaultOptions),
14
+ };
15
+ };
16
+
17
+ export const createReplace = (defaultOptions) => ({options}) => {
18
+ const result = {};
19
+ const all = {
20
+ ...defaultOptions,
21
+ ...options,
22
+ };
23
+
24
+ for (const [name, exports] of entries(all)) {
25
+ const from = `export default ${name}(__args)`;
26
+
27
+ result[from] = `{
28
+ const {${exports.join(', ')}} = ${name}(__args);
29
+ export {
30
+ ${exports.join(',\n')}
31
+ }
32
+ }`;
33
+ }
34
+
35
+ return result;
36
+ };
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import * as applyExports from './apply-exports/index.js';
1
2
  import * as applyExportsToRenameFiles from './apply-exports-to-rename-files/index.js';
2
3
  import * as applyExportsToMatchFiles from './apply-exports-to-match-files/index.js';
3
4
  import * as applyProcessorsDestructuring from './apply-processors-destructuring/index.js';
@@ -136,4 +137,5 @@ export const rules = {
136
137
  'apply-report': applyReport,
137
138
  'apply-exports-to-match-files': applyExportsToMatchFiles,
138
139
  'apply-exports-to-rename-files': applyExportsToRenameFiles,
140
+ 'apply-exports': applyExports,
139
141
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "24.4.1",
3
+ "version": "24.5.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin helps with plugins development",