@putout/plugin-putout 11.1.1 → 11.4.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
@@ -38,11 +38,13 @@ npm i @putout/plugin-putout -D
38
38
  "putout/convert-add-argument-to-add-args": "on",
39
39
  "putout/convert-dirname-to-url": "on",
40
40
  "putout/convert-url-to-dirname": "on",
41
+ "putout/convert-report-to-function": "on",
41
42
  "putout/shorten-imports": "on",
42
43
  "putout/check-replace-code": "on",
43
44
  "putout/declare": "on",
44
45
  "putout/includer": "on",
45
- "putout/move-require-on-top-level": "on"
46
+ "putout/move-require-on-top-level": "on",
47
+ "putout/replace-test-message": "on"
46
48
  }
47
49
  }
48
50
  ```
@@ -417,7 +419,7 @@ module.exports.replace = () => ({
417
419
  });
418
420
  ```
419
421
 
420
- There is no `fix` for this rule, it used internally to be more confident about `test coverage`, because of declaration form, transforms cannon be checked by `nyc` and `c8`, and uncovered lines can find unfixable false possitives when running on code.
422
+ There is no `fix` for this rule, it used internally to be more confident about `test coverage`, because of declaration form, transforms cannon be checked by `nyc` and `c8`, and uncovered lines can find unfixable false positives when running on code.
421
423
  This is additional tests, if you forget to test some case (from a big list of rules that is supported) it will be checked with this `rule` and make transforms more stable.
422
424
 
423
425
  ## declare
@@ -557,6 +559,20 @@ const test = createTest(import.meta.url, {
557
559
  });
558
560
  ```
559
561
 
562
+ ## convert-report-to-function
563
+
564
+ ### ❌ Example of incorrect code
565
+
566
+ ```js
567
+ module.exports.report = `'report' should be a 'function'`;
568
+ ```
569
+
570
+ ### ✅ Example of correct code
571
+
572
+ ```js
573
+ module.exports.report = () => `'report' should be a 'function'`;
574
+ ```
575
+
560
576
  ## move-require-on-top-level
561
577
 
562
578
  ### ❌ Example of incorrect code
@@ -618,6 +634,39 @@ module.exports.include = () => ['cons __a = __b'];
618
634
  module.exports.exclude = () => ['var __a = __b'];
619
635
  ```
620
636
 
637
+ ## replace-test-message
638
+
639
+ Checks that `test message` and used `operator` are synchronized.
640
+ Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d9c6972ea848ba8e7e745d2479727b65/199c30b986ce7d544397c344ebfc5031c4b53181).
641
+
642
+ ### ❌ Example of incorrect code
643
+
644
+ ```js
645
+ test('plugin-putout: rename-operate-to-operator: transform: operator exist', (t) => {
646
+ t.noTransform('operator');
647
+ t.end();
648
+ });
649
+
650
+ test('plugin-putout: rename-operate-to-operator: report: operator exist', (t) => {
651
+ t.noReport('operator');
652
+ t.end();
653
+ });
654
+ ```
655
+
656
+ ### ✅ Example of correct code
657
+
658
+ ```js
659
+ test('plugin-putout: rename-operate-to-operator: no transform: operator exist', (t) => {
660
+ t.noTransform('operator');
661
+ t.end();
662
+ });
663
+
664
+ test('plugin-putout: rename-operate-to-operator: no report: operator exist', (t) => {
665
+ t.noReport('operator');
666
+ t.end();
667
+ });
668
+ ```
669
+
621
670
  ## License
622
671
 
623
672
  MIT
@@ -4,7 +4,17 @@ const {operator} = require('putout');
4
4
  const {addArgs} = operator;
5
5
 
6
6
  module.exports = addArgs({
7
- comparePlaces: ['{comparePlaces}', 'test("__a", (__args) => __body)'],
8
- compare: ['{compare}', 'test("__a", (__args) => __body)'],
7
+ comparePlaces: ['{comparePlaces}', [
8
+ 'test("__a", async (__args) => __body)',
9
+ 'test.skip("__a", async (__args) => __body)',
10
+ 'test.only("__a", async (__args) => __body)',
11
+ ],
12
+ ],
13
+ process: ['{process}', [
14
+ 'test("__a", async (__args) => __body)',
15
+ 'test.skip("__a", async (__args) => __body)',
16
+ 'test.only("__a", async (__args) => __body)',
17
+ ],
18
+ ],
9
19
  });
10
20
 
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ const {types} = require('putout');
4
+ const {
5
+ isStringLiteral,
6
+ isTemplateLiteral,
7
+ } = types;
8
+
9
+ module.exports.report = () => `Typeof 'report' should be a 'function'`;
10
+
11
+ module.exports.match = () => ({
12
+ 'module.exports.report = __a': ({__a}) => isStringLiteral(__a) || isTemplateLiteral(__a),
13
+ });
14
+
15
+ module.exports.replace = () => ({
16
+ 'module.exports.report = __a': 'module.exports.report = () => __a',
17
+ });
package/lib/index.js CHANGED
@@ -26,6 +26,8 @@ module.exports.rules = {
26
26
  ...getRule('convert-add-argument-to-add-args'),
27
27
  ...getRule('convert-dirname-to-url'),
28
28
  ...getRule('convert-url-to-dirname'),
29
+ ...getRule('convert-report-to-function'),
30
+ ...getRule('replace-test-message'),
29
31
  ...getRule('rename-operate-to-operator'),
30
32
  ...getRule('replace-operate-with-operator'),
31
33
  ...getRule('shorten-imports'),
@@ -0,0 +1,74 @@
1
+ 'use strict';
2
+
3
+ const {types} = require('putout');
4
+
5
+ const {isCallExpression} = types;
6
+
7
+ module.exports.report = ({correct, operatorPath}) => {
8
+ const calleePath = operatorPath.get('callee');
9
+ return `Use '${correct}' in test message when using '${calleePath}()'`;
10
+ };
11
+
12
+ module.exports.fix = ({path, incorrect, correct}) => {
13
+ path.node.value = path.node.value.replace(incorrect, correct);
14
+ };
15
+
16
+ module.exports.traverse = ({push}) => ({
17
+ 't.transform(__a)': convert({
18
+ push,
19
+ incorrect: /: no transform/,
20
+ correct: ': transform',
21
+ }),
22
+ 't.noTransform(__a)': convert({
23
+ push,
24
+ incorrect: /: transform/,
25
+ correct: ': no transform',
26
+ }),
27
+ 't.report(__a)': convert({
28
+ push,
29
+ incorrect: /: no report/,
30
+ correct: ': report',
31
+ }),
32
+ 't.noReport(__a)': convert({
33
+ push,
34
+ incorrect: /: (report|transform|no transform)/,
35
+ correct: ': no report',
36
+ }),
37
+ });
38
+
39
+ const convert = ({push, correct, incorrect}) => (path) => {
40
+ const [is, messagePath] = isCorrect({
41
+ incorrect,
42
+ path,
43
+ });
44
+
45
+ if (is)
46
+ return;
47
+
48
+ push({
49
+ path: messagePath,
50
+ operatorPath: path,
51
+ incorrect,
52
+ correct,
53
+ });
54
+ };
55
+
56
+ const CORRECT = true;
57
+
58
+ function isCorrect({path, incorrect}) {
59
+ const calleePath = path.findParent(isCallExpression);
60
+
61
+ if (!calleePath)
62
+ return [CORRECT];
63
+
64
+ const messagePath = calleePath.get('arguments.0');
65
+
66
+ if (!messagePath.isStringLiteral())
67
+ return [CORRECT];
68
+
69
+ const {value} = messagePath.node;
70
+ const is = !incorrect.test(value);
71
+
72
+ return [is, messagePath];
73
+ }
74
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "11.1.1",
3
+ "version": "11.4.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",
@@ -41,7 +41,7 @@
41
41
  "eslint": "^8.0.1",
42
42
  "eslint-plugin-node": "^11.0.0",
43
43
  "eslint-plugin-putout": "^15.0.0",
44
- "lerna": "^4.0.0",
44
+ "lerna": "^5.0.0",
45
45
  "madrun": "^9.0.0",
46
46
  "montag": "^1.2.1",
47
47
  "nodemon": "^2.0.1"