@kununu/eslint-config 5.2.3-beta-6 → 5.2.3-beta-8

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 CHANGED
@@ -1,3 +1,6 @@
1
+ // Import the plugin directly
2
+ const kununuPlugin = require('./plugins/kununu');
3
+
1
4
  // we need to have the baseRules to have the same on the typescript override
2
5
  // because it has extends the eslint does not take into consideration the ones from the base
3
6
  const baseRules = {
@@ -204,13 +207,11 @@ const baseRules = {
204
207
  // https://react.dev/blog/2024/04/25/react-19-upgrade-guide#removed-proptypes-and-defaultprops
205
208
  'react/require-default-props': 0,
206
209
 
207
- 'no-restricted-syntax': ['error', {
208
- selector: 'ReturnStatement > LogicalExpression[operator="&&"]',
209
- message: 'Prefer early returns over logical expressions in return statements. Use if (condition) return value; instead.'
210
- }],
210
+ 'prefer-early-return': 'error',
211
211
  };
212
212
 
213
- module.exports = {
213
+ // Create the ESLint config
214
+ const config = {
214
215
  extends: [
215
216
  'airbnb', // Many strict rules for ECMAScript and React
216
217
  'airbnb/hooks',
@@ -236,7 +237,10 @@ module.exports = {
236
237
  es6: true,
237
238
  },
238
239
 
239
- rules: baseRules,
240
+ rules: {
241
+ ...baseRules,
242
+ [`${pluginPrefix}/prefer-early-return`]: 'error'
243
+ },
240
244
 
241
245
  overrides: [{
242
246
  files: [
@@ -299,3 +303,10 @@ module.exports = {
299
303
  }
300
304
  }],
301
305
  };
306
+
307
+ // Export the config
308
+ module.exports = config;
309
+
310
+ module.exports.plugins = {
311
+ 'local': kununuPlugin
312
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kununu/eslint-config",
3
- "version": "5.2.3-beta-6",
3
+ "version": "5.2.3-beta-8",
4
4
  "description": "kununu's ESLint config",
5
5
  "main": "index.js",
6
6
  "repository": "kununu/eslint-config",
@@ -0,0 +1,51 @@
1
+ module.exports = {
2
+ rules: {
3
+ 'prefer-early-return': {
4
+ meta: {
5
+ type: 'suggestion',
6
+ docs: {
7
+ description: 'Prefer early returns over logical expressions in return statements',
8
+ category: 'Best Practices',
9
+ recommended: true,
10
+ },
11
+ fixable: 'code',
12
+ schema: [] // No options
13
+ },
14
+ create: function(context) {
15
+ return {
16
+ ReturnStatement: function(node) {
17
+ // Handle parenthesized expressions in a way compatible with ESLint 5+
18
+ let argument = node.argument;
19
+ if (argument && argument.type === 'ParenthesizedExpression') {
20
+ argument = argument.expression;
21
+ }
22
+
23
+ // Only handle && operators
24
+ if (argument &&
25
+ argument.type === 'LogicalExpression' &&
26
+ argument.operator === '&&') {
27
+ context.report({
28
+ node: node,
29
+ message: 'Prefer early returns over logical expressions in return statements. Use if (condition) return value; instead.',
30
+ fix: function(fixer) {
31
+ // Get source code in a way that works in ESLint 5+
32
+ const sourceCode = context.getSourceCode ?
33
+ context.getSourceCode() :
34
+ context.getSource;
35
+
36
+ const condition = sourceCode.getText(argument.left);
37
+ const returnValue = sourceCode.getText(argument.right);
38
+
39
+ return fixer.replaceText(
40
+ node,
41
+ "if (" + condition + ") return " + returnValue + ";"
42
+ );
43
+ }
44
+ });
45
+ }
46
+ }
47
+ };
48
+ }
49
+ }
50
+ }
51
+ };