@so1ve/eslint-plugin 0.93.3 → 0.93.4
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 +10 -3
- package/dist/index.mjs +10 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -23,6 +23,7 @@ function getPreviousNode(node) {
|
|
|
23
23
|
|
|
24
24
|
const RULE_NAME$6 = "function-style";
|
|
25
25
|
const START_RETURN = /^return /;
|
|
26
|
+
const RETURN_ONLY = /^return\s*(?:;\s*)?$/;
|
|
26
27
|
const END_SEMICOLON = /;$/;
|
|
27
28
|
const functionStyle = createEslintRule({
|
|
28
29
|
name: RULE_NAME$6,
|
|
@@ -43,7 +44,7 @@ const functionStyle = createEslintRule({
|
|
|
43
44
|
create: (context) => {
|
|
44
45
|
const sourceCode = context.getSourceCode();
|
|
45
46
|
const text = sourceCode.getText();
|
|
46
|
-
const
|
|
47
|
+
const getRawStatement = (statement) => `(${text.slice(statement.range[0], statement.range[1]).replace(START_RETURN, "").replace(END_SEMICOLON, "")})`;
|
|
47
48
|
function getLoneReturnStatement(node) {
|
|
48
49
|
const { body } = node;
|
|
49
50
|
if (body.type === types.AST_NODE_TYPES.BlockStatement) {
|
|
@@ -111,6 +112,12 @@ const functionStyle = createEslintRule({
|
|
|
111
112
|
clearThisAccess();
|
|
112
113
|
return;
|
|
113
114
|
}
|
|
115
|
+
const rawStatement = getRawStatement(statement);
|
|
116
|
+
const statementWithoutBrackets = rawStatement.slice(1, -1);
|
|
117
|
+
if (RETURN_ONLY.test(statementWithoutBrackets)) {
|
|
118
|
+
clearThisAccess();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
114
121
|
context.report({
|
|
115
122
|
node,
|
|
116
123
|
messageId: "arrow",
|
|
@@ -120,7 +127,7 @@ const functionStyle = createEslintRule({
|
|
|
120
127
|
"arrow",
|
|
121
128
|
node.id?.name ?? null,
|
|
122
129
|
node,
|
|
123
|
-
|
|
130
|
+
getRawStatement(statement),
|
|
124
131
|
!isExportDefault
|
|
125
132
|
)
|
|
126
133
|
)
|
|
@@ -142,7 +149,7 @@ const functionStyle = createEslintRule({
|
|
|
142
149
|
messageId: "arrow",
|
|
143
150
|
fix: (fixer) => fixer.replaceTextRange(
|
|
144
151
|
node.body.range,
|
|
145
|
-
|
|
152
|
+
getRawStatement(statement)
|
|
146
153
|
)
|
|
147
154
|
});
|
|
148
155
|
clearThisAccess();
|
package/dist/index.mjs
CHANGED
|
@@ -21,6 +21,7 @@ function getPreviousNode(node) {
|
|
|
21
21
|
|
|
22
22
|
const RULE_NAME$6 = "function-style";
|
|
23
23
|
const START_RETURN = /^return /;
|
|
24
|
+
const RETURN_ONLY = /^return\s*(?:;\s*)?$/;
|
|
24
25
|
const END_SEMICOLON = /;$/;
|
|
25
26
|
const functionStyle = createEslintRule({
|
|
26
27
|
name: RULE_NAME$6,
|
|
@@ -41,7 +42,7 @@ const functionStyle = createEslintRule({
|
|
|
41
42
|
create: (context) => {
|
|
42
43
|
const sourceCode = context.getSourceCode();
|
|
43
44
|
const text = sourceCode.getText();
|
|
44
|
-
const
|
|
45
|
+
const getRawStatement = (statement) => `(${text.slice(statement.range[0], statement.range[1]).replace(START_RETURN, "").replace(END_SEMICOLON, "")})`;
|
|
45
46
|
function getLoneReturnStatement(node) {
|
|
46
47
|
const { body } = node;
|
|
47
48
|
if (body.type === AST_NODE_TYPES.BlockStatement) {
|
|
@@ -109,6 +110,12 @@ const functionStyle = createEslintRule({
|
|
|
109
110
|
clearThisAccess();
|
|
110
111
|
return;
|
|
111
112
|
}
|
|
113
|
+
const rawStatement = getRawStatement(statement);
|
|
114
|
+
const statementWithoutBrackets = rawStatement.slice(1, -1);
|
|
115
|
+
if (RETURN_ONLY.test(statementWithoutBrackets)) {
|
|
116
|
+
clearThisAccess();
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
112
119
|
context.report({
|
|
113
120
|
node,
|
|
114
121
|
messageId: "arrow",
|
|
@@ -118,7 +125,7 @@ const functionStyle = createEslintRule({
|
|
|
118
125
|
"arrow",
|
|
119
126
|
node.id?.name ?? null,
|
|
120
127
|
node,
|
|
121
|
-
|
|
128
|
+
getRawStatement(statement),
|
|
122
129
|
!isExportDefault
|
|
123
130
|
)
|
|
124
131
|
)
|
|
@@ -140,7 +147,7 @@ const functionStyle = createEslintRule({
|
|
|
140
147
|
messageId: "arrow",
|
|
141
148
|
fix: (fixer) => fixer.replaceTextRange(
|
|
142
149
|
node.body.range,
|
|
143
|
-
|
|
150
|
+
getRawStatement(statement)
|
|
144
151
|
)
|
|
145
152
|
});
|
|
146
153
|
clearThisAccess();
|