@putout/plugin-return 2.0.0 → 4.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
@@ -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
  }
@@ -198,6 +200,27 @@ const traverse = ({push}) => ({
198
200
  });
199
201
  ```
200
202
 
203
+ ### remove-last-empty
204
+
205
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/111549a3e6d61f8637ea12217062ea80/10e7842f9fbbf7fb0712d3b41cdcc707ae410fe5).
206
+
207
+ ### ❌ Example of incorrect code
208
+
209
+ ```js
210
+ const exit = (vars, path, {push}) => {
211
+ push(path);
212
+ return;
213
+ };
214
+ ```
215
+
216
+ ### ✅ Example of correct code
217
+
218
+ ```js
219
+ const exit = (vars, path, {push}) => {
220
+ push(path);
221
+ };
222
+ ```
223
+
201
224
  ## simplify-boolean
202
225
 
203
226
  Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/304035b9529830cf20e76e9a1f35f14c/39c743921c6bfad3984a3989f25c2986ab51e8c8).
@@ -1,13 +1,7 @@
1
1
  import {convertFrom} from '../convert-from.js';
2
2
 
3
- const {
3
+ export const {
4
4
  report,
5
5
  traverse,
6
6
  fix,
7
7
  } = convertFrom('break');
8
-
9
- export {
10
- report,
11
- traverse,
12
- fix,
13
- };
@@ -1,13 +1,7 @@
1
1
  import {convertFrom} from '../convert-from.js';
2
2
 
3
- const {
3
+ export const {
4
4
  report,
5
5
  traverse,
6
6
  fix,
7
7
  } = convertFrom('continue');
8
-
9
- export {
10
- report,
11
- traverse,
12
- fix,
13
- };
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
+ });
@@ -5,6 +5,7 @@ const {
5
5
  isIdentifier,
6
6
  isLiteral,
7
7
  isAssignmentPattern,
8
+ isObjectExpression,
8
9
  } = types;
9
10
 
10
11
  export const report = () => `Avoid useless 'return'`;
@@ -26,9 +27,6 @@ export const filter = (path) => {
26
27
  if (!bodyPath.isBlockStatement())
27
28
  return false;
28
29
 
29
- if (hasComplexParams(path))
30
- return false;
31
-
32
30
  const first = bodyPath.get('body.0');
33
31
 
34
32
  if (!first)
@@ -45,6 +43,9 @@ export const filter = (path) => {
45
43
  if (!argPath.node)
46
44
  return false;
47
45
 
46
+ if (hasComplexParams(path) && !isObjectExpression(argPath))
47
+ return false;
48
+
48
49
  if (isChainCall(argPath))
49
50
  return false;
50
51
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-return",
3
- "version": "2.0.0",
3
+ "version": "4.0.0",
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",
@@ -31,28 +31,27 @@
31
31
  "return"
32
32
  ],
33
33
  "devDependencies": {
34
- "@putout/eslint-flat": "^3.0.0",
35
34
  "@putout/plugin-declare": "*",
36
35
  "@putout/plugin-declare-before-reference": "*",
37
36
  "@putout/plugin-putout": "*",
38
- "@putout/plugin-remove-unused-variables": "*",
39
37
  "@putout/plugin-reuse-duplicate-init": "*",
40
38
  "@putout/plugin-typescript": "*",
41
- "@putout/test": "^13.0.0",
42
- "c8": "^10.0.0",
43
- "eslint": "^9.0.0",
39
+ "@putout/plugin-variables": "*",
40
+ "@putout/test": "^15.0.0",
41
+ "eslint": "^10.0.0",
44
42
  "eslint-plugin-n": "^17.0.0",
45
- "eslint-plugin-putout": "^26.0.0",
46
- "madrun": "^11.0.0",
43
+ "eslint-plugin-putout": "^31.0.0",
44
+ "madrun": "^13.0.0",
47
45
  "montag": "^1.2.1",
48
- "nodemon": "^3.0.1"
46
+ "nodemon": "^3.0.1",
47
+ "superc8": "^12.0.0"
49
48
  },
50
49
  "peerDependencies": {
51
- "putout": ">=40"
50
+ "putout": ">=42"
52
51
  },
53
52
  "license": "MIT",
54
53
  "engines": {
55
- "node": ">=20"
54
+ "node": ">=22"
56
55
  },
57
56
  "publishConfig": {
58
57
  "access": "public"