@putout/plugin-printer 7.1.0 → 8.0.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
@@ -21,6 +21,7 @@ npm i @putout/plugin-printer -D
21
21
  - ✅ [apply-types](#apply-types);
22
22
  - ✅ [declare](#declare);
23
23
  - ✅ [remove-args](#remove-args);
24
+ - ✅ [remove-useless-maybe](#remove-useless-maybe);
24
25
  - ✅ [remove-legacy-test-declaration](#remove-legacy-test-declaration);
25
26
 
26
27
  ## Config
@@ -35,7 +36,8 @@ npm i @putout/plugin-printer -D
35
36
  "printer/apply-create-test-url": "on",
36
37
  "printer/apply-types": "on",
37
38
  "printer/declare": "on",
38
- "printer/remove-args": "on"
39
+ "printer/remove-args": "on",
40
+ "printer/remove-useless-maybe": "on"
39
41
  }
40
42
  }
41
43
  ```
@@ -114,6 +116,7 @@ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/ddf1425ace
114
116
 
115
117
  ```js
116
118
  import {createTest} from '#test';
119
+
117
120
  const {test, fixture} = createTest(__dirname);
118
121
  ```
119
122
 
@@ -121,6 +124,7 @@ const {test, fixture} = createTest(__dirname);
121
124
 
122
125
  ```js
123
126
  import {createTest} from '#test';
127
+
124
128
  const {test, fixture} = createTest(import.meta.url);
125
129
  ```
126
130
 
@@ -138,6 +142,24 @@ print.indent(is);
138
142
  print.indent();
139
143
  ```
140
144
 
145
+ ## remove-useless-maybe
146
+
147
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d448a928400ff37043ae03510ce7c85c/db1a758809e8759f591533f9ef92bef1188d32b0).
148
+
149
+ ### ❌ Example of incorrect code
150
+
151
+ ```js
152
+ maybe.print.linebreak(wasNewline);
153
+ maybe.print.newline(!wasNewline);
154
+ ```
155
+
156
+ ### ✅ Example of correct code
157
+
158
+ ```js
159
+ maybe.indent(wasNewline);
160
+ print.newline();
161
+ ```
162
+
141
163
  ## declare
142
164
 
143
165
  ### ❌ Example of incorrect code
@@ -5,9 +5,9 @@ const {isESM} = operator;
5
5
  export const report = () => `Use 'import.meta.url' instead of '__dirname'`;
6
6
 
7
7
  export const match = () => ({
8
- 'const {test, fixture} = createTest(__dirname)': (vars, path) => isESM(path),
8
+ 'createTest(__dirname)': (vars, path) => isESM(path),
9
9
  });
10
10
 
11
11
  export const replace = () => ({
12
- 'const {test, fixture} = createTest(__dirname)': 'const {test, fixture} = createTest(import.meta.url)',
12
+ 'createTest(__dirname)': 'createTest(import.meta.url)',
13
13
  });
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import * as removeUselessMaybe from './remove-useless-maybe/index.js';
1
2
  import * as applyCreateTestUrl from './apply-create-test-url/index.js';
2
3
  import * as removeArgs from './remove-args/index.js';
3
4
  import * as applyBreakline from './apply-breakline/index.js';
@@ -18,4 +19,5 @@ export const rules = {
18
19
  'apply-types': applyTypes,
19
20
  'remove-legacy-test-declaration': removeLegacyTestDeclaration,
20
21
  'apply-create-test-url': applyCreateTestUrl,
22
+ 'remove-useless-maybe': removeUselessMaybe,
21
23
  };
@@ -0,0 +1,34 @@
1
+ import {operator} from 'putout';
2
+
3
+ const {
4
+ remove,
5
+ getTemplateValues,
6
+ compare,
7
+ } = operator;
8
+
9
+ export const report = () => `Use 'if condition' instead of 'ternary expression'`;
10
+
11
+ export const match = () => ({
12
+ 'maybe.print.linebreak(__a)': (vars, path) => {
13
+ const next = path.parentPath.getNextSibling();
14
+ const {expression} = next.node;
15
+
16
+ if (!compare(expression, 'maybe.print.newline(!__a)'))
17
+ return false;
18
+
19
+ const {__a} = getTemplateValues(next.node.expression, 'maybe.print.newline(!__a)');
20
+
21
+ return compare(__a, vars.__a);
22
+ },
23
+ });
24
+ export const replace = () => ({
25
+ 'maybe.print.linebreak(__a)': (vars, path) => {
26
+ const next = path.parentPath.getNextSibling();
27
+ remove(next);
28
+
29
+ return `{
30
+ maybe.indent(__a);
31
+ print.newline();
32
+ }`;
33
+ },
34
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-printer",
3
- "version": "7.1.0",
3
+ "version": "8.0.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds support of transformations for @putout/printer",
@@ -39,16 +39,16 @@
39
39
  "@putout/plugin-for-of": "*",
40
40
  "@putout/plugin-remove-nested-blocks": "*",
41
41
  "@putout/test": "^15.0.0",
42
- "c8": "^10.0.0",
43
- "eslint": "^10.0.0-alpha.0",
42
+ "eslint": "^10.0.0",
44
43
  "eslint-plugin-n": "^17.0.0",
45
- "eslint-plugin-putout": "^30.0.0",
46
- "madrun": "^12.0.0",
44
+ "eslint-plugin-putout": "^31.0.0",
45
+ "madrun": "^13.0.0",
47
46
  "montag": "^1.2.1",
48
- "nodemon": "^3.0.1"
47
+ "nodemon": "^3.0.1",
48
+ "superc8": "^12.0.0"
49
49
  },
50
50
  "peerDependencies": {
51
- "putout": ">=41"
51
+ "putout": ">=42"
52
52
  },
53
53
  "license": "MIT",
54
54
  "engines": {