@kununu/eslint-config 5.2.2-beta-1 → 5.2.2-beta-2
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/index.js +34 -40
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -205,49 +205,43 @@ const baseRules = {
|
|
|
205
205
|
'react/require-default-props': 0,
|
|
206
206
|
// Enforce early return over nested return blocks
|
|
207
207
|
'prefer-early-return': {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
},
|
|
215
|
-
fixable: 'code',
|
|
208
|
+
meta: {
|
|
209
|
+
type: 'suggestion',
|
|
210
|
+
docs: {
|
|
211
|
+
description: 'Prefer early returns over nested returns with logical expressions',
|
|
212
|
+
category: 'Best Practices',
|
|
213
|
+
recommended: true,
|
|
216
214
|
},
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
return fixer.replaceText(node, fixes.join('\n'));
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
}
|
|
215
|
+
fixable: 'code',
|
|
216
|
+
},
|
|
217
|
+
create(context) {
|
|
218
|
+
return {
|
|
219
|
+
ReturnStatement(node) {
|
|
220
|
+
// Handle both direct LogicalExpression and ParenthesizedExpression
|
|
221
|
+
const argument = node.argument?.type === 'ParenthesizedExpression'
|
|
222
|
+
? node.argument.expression
|
|
223
|
+
: node.argument;
|
|
224
|
+
|
|
225
|
+
if (argument?.type === 'LogicalExpression') {
|
|
226
|
+
context.report({
|
|
227
|
+
node,
|
|
228
|
+
message: 'Prefer early returns over logical expressions in return statements',
|
|
229
|
+
fix(fixer) {
|
|
230
|
+
const sourceCode = context.getSourceCode();
|
|
231
|
+
const condition = sourceCode.getText(argument.left);
|
|
232
|
+
const returnValue = sourceCode.getText(argument.right);
|
|
233
|
+
|
|
234
|
+
return fixer.replaceText(
|
|
235
|
+
node,
|
|
236
|
+
`if (!${condition}) return null;\nreturn ${returnValue};`
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
247
240
|
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
241
|
+
}
|
|
242
|
+
};
|
|
250
243
|
}
|
|
244
|
+
}
|
|
251
245
|
};
|
|
252
246
|
|
|
253
247
|
module.exports = {
|