@putout/plugin-putout 14.1.2 β†’ 14.3.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
@@ -46,6 +46,7 @@ npm i @putout/plugin-putout -D
46
46
  "putout/convert-dirname-to-url": "on",
47
47
  "putout/convert-url-to-dirname": "on",
48
48
  "putout/convert-report-to-function": "on",
49
+ "putout/convert-get-rule-to-require": "on",
49
50
  "putout/create-test": "on",
50
51
  "putout/shorten-imports": "on",
51
52
  "putout/declare": "on",
@@ -749,6 +750,28 @@ module.exports.report = `'report' should be a 'function'`;
749
750
  module.exports.report = () => `'report' should be a 'function'`;
750
751
  ```
751
752
 
753
+ ## convert-get-rule-to-require
754
+
755
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/38336fcc5b5ae6e441697e098067319c/dd98578c9554b7bd5dceee0499118f7d8216e1da).
756
+
757
+ ### ❌ Example of incorrect code
758
+
759
+ ```js
760
+ module.exports.rules = {
761
+ ...getRule('remove-unused-variables'),
762
+ };
763
+ ```
764
+
765
+ ### βœ… Example of correct code
766
+
767
+ ```js
768
+ const removeUnusedVariables = require('./remove-unused-variables');
769
+
770
+ module.exports.rules = {
771
+ 'remove-unused-variables': removeUnusedVariables,
772
+ };
773
+ ```
774
+
752
775
  ## move-require-on-top-level
753
776
 
754
777
  ### ❌ Example of incorrect code
@@ -0,0 +1,78 @@
1
+ 'use strict';
2
+
3
+ const camel = require('just-camel-case');
4
+ const {
5
+ types,
6
+ operator,
7
+ template,
8
+ } = require('putout');
9
+
10
+ const {
11
+ replaceWith,
12
+ insertBefore,
13
+ compare,
14
+ } = operator;
15
+
16
+ const {
17
+ ObjectProperty,
18
+ Identifier,
19
+ StringLiteral,
20
+ } = types;
21
+
22
+ module.exports.report = () => `Use top-level 'require()' instead of '...getRule()'`;
23
+
24
+ const REQUIRE = `const __a = require(__b)`;
25
+ const createRequire = template(REQUIRE, {
26
+ placeholderPattern: /__/,
27
+ });
28
+
29
+ module.exports.match = () => ({
30
+ 'getRule(__a)': ({__a}, path) => {
31
+ const name = __a.value;
32
+
33
+ if (!path.parentPath.isSpreadElement())
34
+ return false;
35
+
36
+ return !path.scope.getAllBindings()[name];
37
+ },
38
+ });
39
+
40
+ module.exports.replace = () => ({
41
+ 'getRule(__a)': ({__a}, path) => {
42
+ const name = camel(__a.value);
43
+ const id = Identifier(name);
44
+ const node = ObjectProperty(__a, id);
45
+
46
+ replaceWith(path.parentPath, node);
47
+
48
+ const programPath = path.scope.getProgramParent().path;
49
+ const body = programPath.get('body');
50
+ const [first] = body;
51
+
52
+ const nodeRequire = createRequire({
53
+ __a: id,
54
+ __b: StringLiteral(`./${__a.value}`),
55
+ });
56
+
57
+ if (compare(first, REQUIRE)) {
58
+ const latest = getLatest(body.slice(1));
59
+ insertBefore(latest, nodeRequire);
60
+
61
+ return path;
62
+ }
63
+
64
+ programPath.node.body.unshift(nodeRequire);
65
+
66
+ return path;
67
+ },
68
+ });
69
+
70
+ function getLatest(body) {
71
+ let path;
72
+
73
+ for (path of body)
74
+ if (!compare(path, REQUIRE))
75
+ break;
76
+
77
+ return path;
78
+ }
@@ -3,9 +3,14 @@
3
3
  const types = require('./types');
4
4
  const operator = require('./operator');
5
5
 
6
+ const getRule = (a) => ({
7
+ [a]: require(`./${a}`),
8
+ });
9
+
6
10
  module.exports.declare = () => ({
7
11
  template: `import {template} from 'putout'`,
8
12
  createTest: `import {createTest} from '@putout/test'`,
9
13
  ...operator,
10
14
  ...types,
15
+ getRule: `const getRule = ${getRule.toString()};`,
11
16
  });
package/lib/index.js CHANGED
@@ -1,47 +1,85 @@
1
1
  'use strict';
2
2
 
3
- const getRule = (a) => ({
4
- [a]: require(`./${a}`),
5
- });
3
+ const applyProcessorsDestructuring = require('./apply-processors-destructuring');
4
+ const applyAsyncFormatter = require('./apply-async-formatter');
5
+ const applyCreateTest = require('./apply-create-test');
6
+ const applyRemove = require('./apply-remove');
7
+ const applyInsertBefore = require('./apply-insert-before');
8
+ const applyInsertAfter = require('./apply-insert-after');
9
+ const applyDeclare = require('./apply-declare');
10
+ const checkReplaceCode = require('./check-replace-code');
11
+ const checkMatch = require('./check-match');
12
+ const convertPutoutTestToCreateTest = require('./convert-putout-test-to-create-test');
13
+ const convertToNoTransformCode = require('./convert-to-no-transform-code');
14
+ const convertFindToTraverse = require('./convert-find-to-traverse');
15
+ const convertDestructuringToIdentifier = require('./convert-destructuring-to-identifier');
16
+ const convertNumberToNumeric = require('./convert-number-to-numeric');
17
+ const convertReplaceWith = require('./convert-replace-with');
18
+ const convertReplaceWithMultiple = require('./convert-replace-with-multiple');
19
+ const convertReplaceToFunction = require('./convert-replace-to-function');
20
+ const convertMatchToFunction = require('./convert-match-to-function');
21
+ const convertBabelTypes = require('./convert-babel-types');
22
+ const convertNodeToPathInGetTemplateValues = require('./convert-node-to-path-in-get-template-values');
23
+ const convertTraverseToInclude = require('./convert-traverse-to-include');
24
+ const convertTraverseToReplace = require('./convert-traverse-to-replace');
25
+ const convertProcessToFind = require('./convert-process-to-find');
26
+ const convertMethodToProperty = require('./convert-method-to-property');
27
+ const convertAddArgumentToAddArgs = require('./convert-add-argument-to-add-args');
28
+ const convertDirnameToUrl = require('./convert-dirname-to-url');
29
+ const convertUrlToDirname = require('./convert-url-to-dirname');
30
+ const convertReportToFunction = require('./convert-report-to-function');
31
+ const replaceTestMessage = require('./replace-test-message');
32
+ const renameOperateToOperator = require('./rename-operate-to-operator');
33
+ const replaceOperateWithOperator = require('./replace-operate-with-operator');
34
+ const shortenImports = require('./shorten-imports');
35
+ const declare = require('./declare');
36
+ const addArgs = require('./add-args');
37
+ const addPush = require('./add-push');
38
+ const moveRequireOnTopLevel = require('./move-require-on-top-level');
39
+ const includer = require('./includer');
40
+ const createTest = require('./create-test');
41
+ const applyNamaspaceSpecifier = require('./apply-namaspace-specifier');
42
+ const convertGetRuleToRequire = require('./convert-get-rule-to-require');
6
43
 
7
44
  module.exports.rules = {
8
- ...getRule('apply-processors-destructuring'),
9
- ...getRule('apply-async-formatter'),
10
- ...getRule('apply-create-test'),
11
- ...getRule('apply-remove'),
12
- ...getRule('apply-insert-before'),
13
- ...getRule('apply-insert-after'),
14
- ...getRule('apply-declare'),
15
- ...getRule('check-replace-code'),
16
- ...getRule('check-match'),
17
- ...getRule('convert-putout-test-to-create-test'),
18
- ...getRule('convert-to-no-transform-code'),
19
- ...getRule('convert-find-to-traverse'),
20
- ...getRule('convert-destructuring-to-identifier'),
21
- ...getRule('convert-number-to-numeric'),
22
- ...getRule('convert-replace-with'),
23
- ...getRule('convert-replace-with-multiple'),
24
- ...getRule('convert-replace-to-function'),
25
- ...getRule('convert-match-to-function'),
26
- ...getRule('convert-babel-types'),
27
- ...getRule('convert-node-to-path-in-get-template-values'),
28
- ...getRule('convert-traverse-to-include'),
29
- ...getRule('convert-traverse-to-replace'),
30
- ...getRule('convert-process-to-find'),
31
- ...getRule('convert-method-to-property'),
32
- ...getRule('convert-add-argument-to-add-args'),
33
- ...getRule('convert-dirname-to-url'),
34
- ...getRule('convert-url-to-dirname'),
35
- ...getRule('convert-report-to-function'),
36
- ...getRule('replace-test-message'),
37
- ...getRule('rename-operate-to-operator'),
38
- ...getRule('replace-operate-with-operator'),
39
- ...getRule('shorten-imports'),
40
- ...getRule('declare'),
41
- ...getRule('add-args'),
42
- ...getRule('add-push'),
43
- ...getRule('move-require-on-top-level'),
44
- ...getRule('includer'),
45
- ...getRule('create-test'),
46
- ...getRule('apply-namaspace-specifier'),
45
+ 'apply-processors-destructuring': applyProcessorsDestructuring,
46
+ 'apply-async-formatter': applyAsyncFormatter,
47
+ 'apply-create-test': applyCreateTest,
48
+ 'apply-remove': applyRemove,
49
+ 'apply-insert-before': applyInsertBefore,
50
+ 'apply-insert-after': applyInsertAfter,
51
+ 'apply-declare': applyDeclare,
52
+ 'check-replace-code': checkReplaceCode,
53
+ 'check-match': checkMatch,
54
+ 'convert-putout-test-to-create-test': convertPutoutTestToCreateTest,
55
+ 'convert-to-no-transform-code': convertToNoTransformCode,
56
+ 'convert-find-to-traverse': convertFindToTraverse,
57
+ 'convert-destructuring-to-identifier': convertDestructuringToIdentifier,
58
+ 'convert-number-to-numeric': convertNumberToNumeric,
59
+ 'convert-replace-with': convertReplaceWith,
60
+ 'convert-replace-with-multiple': convertReplaceWithMultiple,
61
+ 'convert-replace-to-function': convertReplaceToFunction,
62
+ 'convert-match-to-function': convertMatchToFunction,
63
+ 'convert-babel-types': convertBabelTypes,
64
+ 'convert-node-to-path-in-get-template-values': convertNodeToPathInGetTemplateValues,
65
+ 'convert-traverse-to-include': convertTraverseToInclude,
66
+ 'convert-traverse-to-replace': convertTraverseToReplace,
67
+ 'convert-process-to-find': convertProcessToFind,
68
+ 'convert-method-to-property': convertMethodToProperty,
69
+ 'convert-add-argument-to-add-args': convertAddArgumentToAddArgs,
70
+ 'convert-dirname-to-url': convertDirnameToUrl,
71
+ 'convert-url-to-dirname': convertUrlToDirname,
72
+ 'convert-report-to-function': convertReportToFunction,
73
+ 'replace-test-message': replaceTestMessage,
74
+ 'rename-operate-to-operator': renameOperateToOperator,
75
+ 'replace-operate-with-operator': replaceOperateWithOperator,
76
+ 'shorten-imports': shortenImports,
77
+ declare,
78
+ 'add-args': addArgs,
79
+ 'add-push': addPush,
80
+ 'move-require-on-top-level': moveRequireOnTopLevel,
81
+ includer,
82
+ 'create-test': createTest,
83
+ 'apply-namaspace-specifier': applyNamaspaceSpecifier,
84
+ 'convert-get-rule-to-require': convertGetRuleToRequire,
47
85
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "14.1.2",
3
+ "version": "14.3.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin helps with plugins development",