@putout/plugin-putout 25.0.1 → 25.2.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
@@ -493,7 +493,7 @@ export default createRenameProperty([
493
493
  ### ✅ Example of correct code
494
494
 
495
495
  ```js
496
- const {
496
+ export const {
497
497
  report,
498
498
  fix,
499
499
  scan,
@@ -501,12 +501,6 @@ const {
501
501
  ...v32,
502
502
  ...v29,
503
503
  ]);
504
-
505
- export {
506
- report,
507
- fix,
508
- scan,
509
- };
510
504
  ```
511
505
 
512
506
  ## apply-exports-to-add-args
@@ -522,17 +516,11 @@ export default addArgs(__args);
522
516
  ### ✅ Example of correct code
523
517
 
524
518
  ```js
525
- const {
519
+ export const {
526
520
  report,
527
521
  fix,
528
522
  traverse,
529
523
  } = addArgs(__args);
530
-
531
- export {
532
- report,
533
- fix,
534
- traverse,
535
- };
536
524
  ```
537
525
 
538
526
  ## apply-exports-to-match-files
@@ -550,19 +538,13 @@ export default matchFiles({
550
538
  ### ✅ Example of correct code
551
539
 
552
540
  ```js
553
- const {
541
+ export const {
554
542
  report,
555
543
  fix,
556
544
  scan,
557
545
  } = matchFiles({
558
546
  '*.cjs': plugin,
559
547
  });
560
-
561
- export {
562
- report,
563
- fix,
564
- scan,
565
- };
566
548
  ```
567
549
 
568
550
  ## apply-exports-to-rename-files
@@ -584,7 +566,7 @@ export default renameFiles({
584
566
  ### ✅ Example of correct code
585
567
 
586
568
  ```js
587
- const {
569
+ export const {
588
570
  report,
589
571
  fix,
590
572
  scan,
@@ -595,12 +577,6 @@ const {
595
577
  return name.replace(/mjs$/, 'js');
596
578
  },
597
579
  });
598
-
599
- export {
600
- report,
601
- fix,
602
- scan,
603
- };
604
580
  ```
605
581
 
606
582
  ## apply-async-formatter
@@ -660,6 +636,22 @@ const dirPath = createNestedDirectory(path, '/hello/world');
660
636
  const dirPath2 = createDirectory(path, 'world');
661
637
  ```
662
638
 
639
+ ## apply-namespace-specifier
640
+
641
+ Most likely what you need is [`esm/resolve-imported-file`](https://github.com/coderaiser/putout/tree/master/packages/plugin-esm#resolve-imported-file).
642
+
643
+ ### ❌ Example of incorrect code
644
+
645
+ ```js
646
+ import rmUnused from '@putout/plugin-remove-unused-variables';
647
+ ```
648
+
649
+ ### ✅ Example of correct code
650
+
651
+ ```js
652
+ import * as rmUnused from '@putout/plugin-remove-unused-variables';
653
+ ```
654
+
663
655
  ## apply-for-of-to-track-file
664
656
 
665
657
  > The **Generator** object is returned by a `generator function` and it conforms to both the iterable protocol and the `iterator` protocol.
@@ -1631,32 +1623,32 @@ module.exports.include = [
1631
1623
  module.exports.exclude = [
1632
1624
  'var __a = __b',
1633
1625
  ];
1634
- ```
1635
1626
 
1636
- ### Example of correct code
1637
-
1638
- ```js
1639
- module.exports.include = () => [
1627
+ export const include = [
1640
1628
  'cons __a = __b',
1641
1629
  ];
1642
1630
 
1643
- module.exports.exclude = () => [
1631
+ export const exclude = [
1644
1632
  'var __a = __b',
1645
1633
  ];
1634
+ ```
1646
1635
 
1636
+ ### ✅ Example of correct code
1637
+
1638
+ ```js
1647
1639
  module.exports.include = () => [
1648
- 'cons __a = __b',
1640
+ 'const __a = __b',
1649
1641
  ];
1650
1642
 
1651
1643
  module.exports.exclude = () => [
1652
1644
  'var __a = __b',
1653
1645
  ];
1654
1646
 
1655
- module.exports.include = () => [
1647
+ export const include = () => [
1656
1648
  'cons __a = __b',
1657
1649
  ];
1658
1650
 
1659
- module.exports.exclude = () => [
1651
+ export const exclude = () => [
1660
1652
  'var __a = __b',
1661
1653
  ];
1662
1654
  ```
@@ -2,7 +2,7 @@ import {operator} from 'putout';
2
2
 
3
3
  const {addArgs} = operator;
4
4
 
5
- const {
5
+ export const {
6
6
  report,
7
7
  fix,
8
8
  traverse,
@@ -28,9 +28,3 @@ const {
28
28
  'test.only("__a", async (__args) => __body)',
29
29
  ]],
30
30
  });
31
-
32
- export {
33
- report,
34
- fix,
35
- traverse,
36
- };
@@ -2,7 +2,7 @@ import {operator} from 'putout';
2
2
 
3
3
  const {addArgs} = operator;
4
4
 
5
- const {
5
+ export const {
6
6
  report,
7
7
  fix,
8
8
  traverse,
@@ -12,9 +12,3 @@ const {
12
12
  '(__a) => __body',
13
13
  ]],
14
14
  });
15
-
16
- export {
17
- report,
18
- fix,
19
- traverse,
20
- };
@@ -1,8 +1,3 @@
1
1
  import {createApplyExports} from '../create-apply-exports.js';
2
2
 
3
- const {report, replace} = createApplyExports();
4
-
5
- export {
6
- report,
7
- replace,
8
- };
3
+ export const {report, replace} = createApplyExports();
@@ -1,14 +1,9 @@
1
1
  import {createApplyExports} from '../create-apply-exports.js';
2
2
 
3
- const {report, replace} = createApplyExports({
3
+ export const {report, replace} = createApplyExports({
4
4
  addArgs: [
5
5
  'report',
6
6
  'fix',
7
7
  'traverse',
8
8
  ],
9
9
  });
10
-
11
- export {
12
- report,
13
- replace,
14
- };
@@ -1,14 +1,9 @@
1
1
  import {createApplyExports} from '../create-apply-exports.js';
2
2
 
3
- const {report, replace} = createApplyExports({
3
+ export const {report, replace} = createApplyExports({
4
4
  matchFiles: [
5
5
  'report',
6
6
  'fix',
7
7
  'scan',
8
8
  ],
9
9
  });
10
-
11
- export {
12
- report,
13
- replace,
14
- };
@@ -1,14 +1,9 @@
1
1
  import {createApplyExports} from '../create-apply-exports.js';
2
2
 
3
- const {report, replace} = createApplyExports({
3
+ export const {report, replace} = createApplyExports({
4
4
  renameFiles: [
5
5
  'report',
6
6
  'fix',
7
7
  'scan',
8
8
  ],
9
9
  });
10
-
11
- export {
12
- report,
13
- replace,
14
- };
@@ -19,8 +19,6 @@ export const traverse = ({push, listStore, pathStore}) => ({
19
19
  names: [
20
20
  '@putout/plugin-',
21
21
  './index.js',
22
- '../lib/index.js',
23
- '../',
24
22
  ],
25
23
  }),
26
24
  'Program': {
@@ -66,6 +64,10 @@ const createImportVisitor = ({push, names, pathStore = noop}) => ({
66
64
  return;
67
65
 
68
66
  for (const name of names) {
67
+ if (!value.replace('.js', '').replace('./', '')
68
+ .includes('/'))
69
+ continue;
70
+
69
71
  if (value === name || value.startsWith(name) || name === 'any') {
70
72
  push({
71
73
  path,
@@ -19,6 +19,9 @@ export const report = (path) => {
19
19
  return `Use 't.${TYPES[name]}()' instead of 't.${name}()'`;
20
20
  };
21
21
 
22
+ export const exclude = () => [
23
+ 't.noReport(__a, __array)',
24
+ ];
22
25
  export const replace = () => ({
23
26
  't.noReport(__a, __object)': 't.noReportWithOptions(__a, __object)',
24
27
  't.noReport(__a, __b)': 't.noReport(__a)',
@@ -1,68 +1,17 @@
1
- import {
2
- operator,
3
- template,
4
- types,
5
- } from 'putout';
1
+ import {operator} from 'putout';
6
2
  import fullstore from 'fullstore';
7
3
 
8
- const {objectProperty, identifier} = types;
9
-
10
- const {
11
- replaceWith,
12
- insertAfter,
13
- insertBefore,
14
- } = operator;
4
+ const {replaceWith} = operator;
15
5
 
16
6
  export const report = () => {
17
7
  return `Use 'operator.replaceWith()' instead of 'path.replaceWith()'`;
18
8
  };
19
9
 
20
- export const fix = ({path, calleePath, property, object, program, isInserted}) => {
10
+ export const fix = ({path, calleePath, property, object}) => {
21
11
  replaceWith(calleePath, property);
22
- const {bindings} = program.scope;
23
-
24
12
  path.node.arguments.unshift(object);
25
-
26
- if (bindings.replaceWith || isInserted())
27
- return;
28
-
29
- if (!bindings.replaceWithMultiple && !bindings.insertAfter && !isInserted()) {
30
- const replaceWithAST = template.ast.fresh(`
31
- const {replaceWith} = require('putout').operator;
32
- `);
33
-
34
- const {types} = bindings;
35
- const first = program.get('body.0');
36
- const pathToInsert = types ? types.path.parentPath : first;
37
-
38
- if (types)
39
- insertAfter(pathToInsert, replaceWithAST);
40
- else
41
- insertBefore(pathToInsert, replaceWithAST);
42
-
43
- isInserted(true);
44
-
45
- return;
46
- }
47
-
48
- const id = identifier('replaceWith');
49
- const varPath = getVarPath(bindings);
50
-
51
- varPath.node.id.properties.unshift(objectProperty(id, id, false, true));
52
13
  };
53
14
 
54
- function getVarPath(bindings) {
55
- const {
56
- replaceWithMultiple,
57
- insertAfter,
58
- } = bindings;
59
-
60
- if (replaceWithMultiple)
61
- return replaceWithMultiple.path;
62
-
63
- return insertAfter.path;
64
- }
65
-
66
15
  export const traverse = ({push}) => {
67
16
  const isInserted = fullstore();
68
17
 
@@ -6,5 +6,12 @@ export const replace = () => ({
6
6
  'module.exports.include = __array': 'module.exports.include = () => __array',
7
7
  'module.exports.exclude = __array': 'module.exports.exclude = () => __array',
8
8
  'module.exports.include = "__a"': 'module.exports.include = ["__a"]',
9
- 'module.exports.exclude = "__a"': 'module.exports.exclude= ["__a"]',
9
+ 'module.exports.exclude = "__a"': 'module.exports.exclude = ["__a"]',
10
+
11
+ 'export const include = () => "__a"': 'export const include = ["__a"]',
12
+ 'export const exclude = () => "__a"': 'export const exclude = ["__a"]',
13
+ 'export const include = __array': 'export const include = () => __array',
14
+ 'export const exclude = __array': 'export const exclude = () => __array',
15
+ 'export const include = "__a"': 'export const include = ["__a"]',
16
+ 'export const exclude = "__a"': 'export const exclude = ["__a"]',
10
17
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "25.0.1",
3
+ "version": "25.2.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",