@putout/plugin-putout 22.2.0 → 22.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
@@ -25,6 +25,7 @@ npm i @putout/plugin-putout -D
25
25
  - ✅ [apply-create-test](#apply-create-test);
26
26
  - ✅ [apply-declare](#apply-declare);
27
27
  - ✅ [apply-for-of-to-track-file](#apply-for-of-to-track-file);
28
+ - ✅ [apply-fixture-name-to-message](#apply-fixture-name-to-message);
28
29
  - ✅ [apply-insert-after](#apply-insert-after);
29
30
  - ✅ [apply-insert-before](#apply-insert-before);
30
31
  - ✅ [apply-namespace-specifier](#apply-namespace-specifier);
@@ -84,9 +85,9 @@ npm i @putout/plugin-putout -D
84
85
  "putout/add-await-to-progress": "on",
85
86
  "putout/add-index-to-import": "on",
86
87
  "putout/apply-create-test": "on",
87
- "putout/apply-processors-destructuring": "on",
88
88
  "putout/apply-async-formatter": "on",
89
89
  "putout/apply-declare": "on",
90
+ "putout/apply-processors-destructuring": "on",
90
91
  "putout/apply-rename": "on",
91
92
  "putout/apply-remove": "on",
92
93
  "putout/apply-insert-before": "on",
@@ -94,6 +95,7 @@ npm i @putout/plugin-putout -D
94
95
  "putout/apply-short-processors": "on",
95
96
  "putout/apply-namespace-specifier": "on",
96
97
  "putout/apply-for-of-to-track-file": "on",
98
+ "putout/apply-fixture-name-to-message": "on",
97
99
  "putout/check-match": "on",
98
100
  "putout/check-replace-code": ["on", {
99
101
  "once": true
@@ -1419,6 +1421,26 @@ module.exports.replace = () => ({
1419
1421
  });
1420
1422
  ```
1421
1423
 
1424
+ ## apply-fixture-name-to-message"
1425
+
1426
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/66eb493ee966c2465a9fc783cd3ca362/f42ec60e393181b6d6aaf6df81640e93fabe8783).
1427
+
1428
+ ```js
1429
+ test('flatlint: convert-comma-to-semicolon: no report: xxx', (t) => {
1430
+ t.noReport('array');
1431
+ t.end();
1432
+ });
1433
+ ```
1434
+
1435
+ ### ✅ Example of correct code
1436
+
1437
+ ```js
1438
+ test('flatlint: convert-comma-to-semicolon: no report: array', (t) => {
1439
+ t.noReport('array');
1440
+ t.end();
1441
+ });
1442
+ ```
1443
+
1422
1444
  ## License
1423
1445
 
1424
1446
  MIT
@@ -107,10 +107,6 @@ function parseFn(path) {
107
107
  return path.get('declaration.declarations.0.init').node;
108
108
  }
109
109
 
110
- function isCallee(name, {parentPath}) {
111
- return parentPath
112
- .get('callee')
113
- .isIdentifier({
114
- name,
115
- });
116
- }
110
+ const isCallee = (name, {parentPath}) => parentPath.get('callee').isIdentifier({
111
+ name,
112
+ });
@@ -0,0 +1,70 @@
1
+ 'use strict';
2
+
3
+ const {operator} = require('putout');
4
+ const {
5
+ setLiteralValue,
6
+ compare,
7
+ } = operator;
8
+
9
+ const FIXTURE = [
10
+ 'report',
11
+ 'transform',
12
+ ];
13
+
14
+ const NAMES = [
15
+ ...FIXTURE,
16
+ 'no report',
17
+ 'no transform',
18
+ ];
19
+
20
+ module.exports.report = () => `Apply 'fixture' name to 'message'`;
21
+
22
+ module.exports.match = () => ({
23
+ 't.noReport(__a)': check,
24
+ 't.report(__a, __b)': check,
25
+ 't.transform(__a)': check,
26
+ 't.noTransform(__a)': check,
27
+ });
28
+
29
+ module.exports.replace = () => ({
30
+ 't.noReport(__a)': transform,
31
+ 't.report(__a, __b)': transform,
32
+ 't.transform(__a)': transform,
33
+ 't.noTransform(__a)': transform,
34
+ });
35
+
36
+ const isTest = (path) => compare(path, 'test(__a, (t) => __body)');
37
+
38
+ const check = ({__a}, path) => {
39
+ const name = __a.value;
40
+
41
+ if (FIXTURE.includes(name))
42
+ return false;
43
+
44
+ const testPath = path.find(isTest);
45
+
46
+ if (!testPath)
47
+ return false;
48
+
49
+ const [str] = testPath.parentPath.parentPath.node.arguments;
50
+
51
+ return !str.value.includes(name);
52
+ };
53
+
54
+ const transform = ({__a}, path) => {
55
+ const name = __a.value;
56
+ const testPath = path.find(isTest);
57
+ const [str] = testPath.parentPath.parentPath.node.arguments;
58
+
59
+ const values = str.value.split(':');
60
+ const last = values
61
+ .at(-1)
62
+ .trim();
63
+
64
+ if (!NAMES.includes(last))
65
+ values.pop();
66
+
67
+ setLiteralValue(str, `${values.join(':')}: ${name}`);
68
+
69
+ return path;
70
+ };
@@ -12,21 +12,13 @@ module.exports.report = () => {
12
12
  return `"putout.types" should be used instead of "@babel/types"`;
13
13
  };
14
14
 
15
- function isRequire(path) {
16
- return path
17
- .get('callee')
18
- .isIdentifier({
19
- name: 'require',
20
- });
21
- }
22
-
23
- function isBabelTypes(path) {
24
- return path
25
- .get('arguments.0')
26
- .isStringLiteral({
27
- value: '@babel/types',
28
- });
29
- }
15
+ const isRequire = (path) => path.get('callee').isIdentifier({
16
+ name: 'require',
17
+ });
18
+
19
+ const isBabelTypes = (path) => path.get('arguments.0').isStringLiteral({
20
+ value: '@babel/types',
21
+ });
30
22
 
31
23
  module.exports.traverse = ({push}) => ({
32
24
  CallExpression(path) {
@@ -29,11 +29,7 @@ module.exports.traverse = ({push}) => ({
29
29
  if (!statement)
30
30
  return;
31
31
 
32
- const forOfCount = statement
33
- .parentPath
34
- .get('body')
35
- .filter(isForOfStatement)
36
- .length;
32
+ const forOfCount = statement.parentPath.get('body').filter(isForOfStatement).length;
37
33
 
38
34
  if (forOfCount > 1)
39
35
  return;
package/lib/index.js CHANGED
@@ -56,6 +56,7 @@ const addPathArgToFix = require('./add-path-arg-to-fix');
56
56
  const convertIncludeToTraverse = require('./convert-include-to-traverse');
57
57
  const removeUselessPrinterOption = require('./remove-useless-printer-option');
58
58
  const addPathArgToVisitors = require('./add-path-arg-to-visitors');
59
+ const applyFixtureNameToMessage = require('./apply-fixture-name-to-message');
59
60
 
60
61
  module.exports.rules = {
61
62
  'apply-processors-destructuring': applyProcessorsDestructuring,
@@ -114,4 +115,5 @@ module.exports.rules = {
114
115
  'convert-include-to-traverse': convertIncludeToTraverse,
115
116
  'remove-useless-printer-option': removeUselessPrinterOption,
116
117
  'add-path-arg-to-visitors': addPathArgToVisitors,
118
+ 'apply-fixture-name-to-message': applyFixtureNameToMessage,
117
119
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "22.2.0",
3
+ "version": "22.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",