@putout/plugin-return 3.0.0 → 4.0.1

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
@@ -22,6 +22,7 @@ npm i putout @putout/plugin-return -D
22
22
  - ✅ [convert-from-break](#convert-from-continue);
23
23
  - ✅ [merge-with-next-sibling](#merge-with-next-sibling);
24
24
  - ✅ [remove-useless](#remove-useless);
25
+ - ✅ [remove-last-empty](#remove-last-empty);
25
26
  - ✅ [simplify-boolean](#simplify-boolean);
26
27
 
27
28
  ## Config
@@ -34,6 +35,7 @@ npm i putout @putout/plugin-return -D
34
35
  "return/convert-from-break": "on",
35
36
  "return/merge-with-next-sibling": "on",
36
37
  "return/remove-useless": "on",
38
+ "return/remove-last-empty": "on",
37
39
  "return/simplify-boolean": "on"
38
40
  }
39
41
  }
@@ -51,12 +53,10 @@ npm i putout @putout/plugin-return -D
51
53
  function get(a) {
52
54
  const b = 0;
53
55
 
54
- {
55
- if (a > 0)
56
- return 5;
57
-
58
- return 7;
59
- }
56
+ if (a > 0)
57
+ return 5;
58
+
59
+ return 7;
60
60
  }
61
61
  ```
62
62
 
@@ -198,6 +198,27 @@ const traverse = ({push}) => ({
198
198
  });
199
199
  ```
200
200
 
201
+ ### remove-last-empty
202
+
203
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/111549a3e6d61f8637ea12217062ea80/10e7842f9fbbf7fb0712d3b41cdcc707ae410fe5).
204
+
205
+ ### ❌ Example of incorrect code
206
+
207
+ ```js
208
+ const exit = (vars, path, {push}) => {
209
+ push(path);
210
+ return;
211
+ };
212
+ ```
213
+
214
+ ### ✅ Example of correct code
215
+
216
+ ```js
217
+ const exit = (vars, path, {push}) => {
218
+ push(path);
219
+ };
220
+ ```
221
+
201
222
  ## simplify-boolean
202
223
 
203
224
  Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/304035b9529830cf20e76e9a1f35f14c/39c743921c6bfad3984a3989f25c2986ab51e8c8).
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import * as removeLastEmpty from './remove-last-empty/index.js';
1
2
  import * as applyEarly from './apply-early/index.js';
2
3
  import * as convertFromContinue from './convert-from-continue/index.js';
3
4
  import * as convertFromBreak from './convert-from-break/index.js';
@@ -12,4 +13,5 @@ export const rules = {
12
13
  'merge-with-next-sibling': mergeWithNextSibling,
13
14
  'simplify-boolean': simplifyBoolean,
14
15
  'remove-useless': removeUseless,
16
+ 'remove-last-empty': removeLastEmpty,
15
17
  };
@@ -0,0 +1,28 @@
1
+ import {types} from 'putout';
2
+
3
+ const {
4
+ isFunction,
5
+ isBlockStatement,
6
+ } = types;
7
+
8
+ export const report = () => `Avoid empty 'return' in function body`;
9
+
10
+ export const match = () => ({
11
+ return: (vars, path) => {
12
+ const {parentPath} = path;
13
+
14
+ if (!isBlockStatement(parentPath))
15
+ return false;
16
+
17
+ const next = path.getNextSibling();
18
+
19
+ if (next.node)
20
+ return false;
21
+
22
+ return isFunction(parentPath.parentPath);
23
+ },
24
+ });
25
+
26
+ export const replace = () => ({
27
+ return: '',
28
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-return",
3
- "version": "3.0.0",
3
+ "version": "4.0.1",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds ability to transform code related to return",
@@ -37,21 +37,21 @@
37
37
  "@putout/plugin-reuse-duplicate-init": "*",
38
38
  "@putout/plugin-typescript": "*",
39
39
  "@putout/plugin-variables": "*",
40
- "@putout/test": "^14.0.0",
41
- "c8": "^10.0.0",
42
- "eslint": "^10.0.0-alpha.0",
40
+ "@putout/test": "^15.0.0",
41
+ "eslint": "^10.0.0",
43
42
  "eslint-plugin-n": "^17.0.0",
44
- "eslint-plugin-putout": "^29.0.0",
45
- "madrun": "^11.0.0",
43
+ "eslint-plugin-putout": "^31.0.0",
44
+ "madrun": "^13.0.0",
46
45
  "montag": "^1.2.1",
47
- "nodemon": "^3.0.1"
46
+ "nodemon": "^3.0.1",
47
+ "superc8": "^12.0.0"
48
48
  },
49
49
  "peerDependencies": {
50
- "putout": ">=41"
50
+ "putout": ">=42"
51
51
  },
52
52
  "license": "MIT",
53
53
  "engines": {
54
- "node": ">=20"
54
+ "node": ">=22"
55
55
  },
56
56
  "publishConfig": {
57
57
  "access": "public"