@putout/plugin-printer 1.0.0 → 1.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
@@ -19,7 +19,8 @@ npm i @putout/plugin-printer -D
19
19
  "printer/add-args": "on",
20
20
  "printer/apply-breakline": "on",
21
21
  "printer/apply-linebreak": "on",
22
- "printer/apply-computed-print": "on"
22
+ "printer/apply-computed-print": "on",
23
+ "printer/remove-args": "on"
23
24
  }
24
25
  }
25
26
  ```
@@ -80,6 +81,20 @@ print(path.get('block'));
80
81
  print('__block');
81
82
  ```
82
83
 
84
+ ## remove-args
85
+
86
+ ### ❌ Example of incorrect code
87
+
88
+ ```js
89
+ print.indent(is);
90
+ ```
91
+
92
+ ### ✅ Example of correct code
93
+
94
+ ```js
95
+ print.indent();
96
+ ```
97
+
83
98
  ## License
84
99
 
85
100
  MIT
@@ -7,6 +7,7 @@ const {
7
7
 
8
8
  const {
9
9
  compare,
10
+ compareAny,
10
11
  replaceWith,
11
12
  remove,
12
13
  } = operator;
@@ -16,14 +17,29 @@ module.exports.report = () => `breakline = newline + indent`;
16
17
  const next = (path) => path.parentPath.getNextSibling();
17
18
 
18
19
  module.exports.fix = (path) => {
19
- remove(next(path));
20
- replaceWith(path, template.ast('print.breakline()'));
20
+ const sibling = next(path);
21
+ const newNode = choose(path);
22
+
23
+ remove(sibling);
24
+ replaceWith(path, newNode);
21
25
  };
22
26
 
23
27
  module.exports.filter = (path) => {
24
- return compare(next(path), 'print.indent()');
28
+ return compareAny(next(path), [
29
+ 'indent()',
30
+ 'print.indent()',
31
+ 'write.indent()',
32
+ ]);
25
33
  };
26
34
 
27
35
  module.exports.include = () => [
28
36
  'print.newline()',
37
+ 'write.newline()',
29
38
  ];
39
+
40
+ function choose(path) {
41
+ if (compare(path, 'print.newline()'))
42
+ return template.ast('print.breakline()');
43
+
44
+ return template.ast('write.breakline()');
45
+ }
@@ -7,6 +7,7 @@ const {
7
7
 
8
8
  const {
9
9
  compare,
10
+ compareAny,
10
11
  replaceWith,
11
12
  remove,
12
13
  } = operator;
@@ -16,14 +17,29 @@ module.exports.report = () => `linebreak = indent + newline`;
16
17
  const prev = (path) => path.parentPath.getPrevSibling();
17
18
 
18
19
  module.exports.fix = (path) => {
19
- remove(prev(path));
20
- replaceWith(path, template.ast('print.linebreak()'));
20
+ const sibling = prev(path);
21
+ const newNode = choose(path);
22
+
23
+ remove(sibling);
24
+ replaceWith(path, newNode);
21
25
  };
22
26
 
23
27
  module.exports.include = () => [
24
28
  'print.newline()',
29
+ 'write.newline()',
25
30
  ];
26
31
 
27
32
  module.exports.filter = (path) => {
28
- return compare(prev(path), 'print.indent()');
33
+ return compareAny(prev(path), [
34
+ 'indent()',
35
+ 'print.indent()',
36
+ 'write.indent()',
37
+ ]);
29
38
  };
39
+
40
+ function choose(path) {
41
+ if (compare(path, 'print.newline()'))
42
+ return template.ast('print.linebreak()');
43
+
44
+ return template.ast('write.linebreak()');
45
+ }
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ module.exports.report = () => 'Remove useless argument';
4
+
5
+ module.exports.replace = () => ({
6
+ 'print.newline(__args)': 'print.newline()',
7
+ 'print.space(__args)': 'print.space()',
8
+
9
+ 'indent(__args)': 'indent()',
10
+ 'indent.inc(__args)': 'indent.inc()',
11
+ 'indent.dec(__args)': 'indent.dec()',
12
+
13
+ 'write.indent(__args)': 'write.indent()',
14
+ 'write.indent.inc(__args)': 'write.indent.inc()',
15
+ 'write.indent.dec(__args)': 'write.indent.dec()',
16
+
17
+ 'print.indent(__args)': 'print.indent()',
18
+ 'print(__a, __b)': 'print(__b)',
19
+ 'print.indent.inc(__args)': 'print.indent.inc()',
20
+ 'print.indent.dec(__args)': 'print.indent.dec()',
21
+
22
+ 'write(__a, __b)': 'write(__b)',
23
+
24
+ 'maybe.write.space(__a, __b)': 'maybe.write.space(__a)',
25
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-printer",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds support of transformations for @putout/printer",