@so1ve/eslint-plugin 0.122.0 → 1.0.0-alpha.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/dist/index.cjs +15 -9
- package/dist/index.mjs +15 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -47,15 +47,21 @@ const functionStyle = createEslintRule({
|
|
|
47
47
|
const getRawStatement = (statement) => `(${text.slice(statement.range[0], statement.range[1]).replace(START_RETURN, "").replace(END_SEMICOLON, "")})`;
|
|
48
48
|
function getLoneReturnStatement(node) {
|
|
49
49
|
const { body } = node;
|
|
50
|
-
if (body.type
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
if (body.type !== types.AST_NODE_TYPES.BlockStatement) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const { body: blockBody } = body;
|
|
54
|
+
const allComments = sourceCode.getCommentsInside(node);
|
|
55
|
+
if (blockBody.length !== 1) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const [statement] = blockBody;
|
|
59
|
+
const statementComments = sourceCode.getCommentsInside(statement);
|
|
60
|
+
if (allComments.length !== statementComments.length) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (statement?.type === types.AST_NODE_TYPES.ReturnStatement) {
|
|
64
|
+
return statement;
|
|
59
65
|
}
|
|
60
66
|
}
|
|
61
67
|
function generateFunction(type, name, node, rawStatement, asVariable = true) {
|
package/dist/index.mjs
CHANGED
|
@@ -45,15 +45,21 @@ const functionStyle = createEslintRule({
|
|
|
45
45
|
const getRawStatement = (statement) => `(${text.slice(statement.range[0], statement.range[1]).replace(START_RETURN, "").replace(END_SEMICOLON, "")})`;
|
|
46
46
|
function getLoneReturnStatement(node) {
|
|
47
47
|
const { body } = node;
|
|
48
|
-
if (body.type
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
48
|
+
if (body.type !== AST_NODE_TYPES.BlockStatement) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const { body: blockBody } = body;
|
|
52
|
+
const allComments = sourceCode.getCommentsInside(node);
|
|
53
|
+
if (blockBody.length !== 1) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const [statement] = blockBody;
|
|
57
|
+
const statementComments = sourceCode.getCommentsInside(statement);
|
|
58
|
+
if (allComments.length !== statementComments.length) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (statement?.type === AST_NODE_TYPES.ReturnStatement) {
|
|
62
|
+
return statement;
|
|
57
63
|
}
|
|
58
64
|
}
|
|
59
65
|
function generateFunction(type, name, node, rawStatement, asVariable = true) {
|