@bigbinary/eslint-plugin-neeto 1.1.38 → 1.1.39
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 +1 -0
- package/dist/index.js +55 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -122,6 +122,7 @@ module.exports = {
|
|
|
122
122
|
- [add-required-peer-dependencies](./docs/src/rules/add-required-peer-dependencies.md)
|
|
123
123
|
- [move-spread-attributes-to-top-position](./docs/src/rules/move-spread-attributes-to-top-position.md)
|
|
124
124
|
- [prefer-function-reference.md](./docs/src/rules/prefer-function-reference.md)
|
|
125
|
+
- [jsx-prefer-guard-clause.md](./docs/src/rules/jsx-prefer-guard-clause.md)
|
|
125
126
|
|
|
126
127
|
## Other references
|
|
127
128
|
|
package/dist/index.js
CHANGED
|
@@ -162,7 +162,8 @@
|
|
|
162
162
|
"@bigbinary/neeto/props-with-different-key-value-should-be-outside-spread-attribute": "error",
|
|
163
163
|
"@bigbinary/neeto/use-common-constants": "warn",
|
|
164
164
|
"@bigbinary/neeto/move-spread-attributes-to-top-position": "error",
|
|
165
|
-
"@bigbinary/neeto/prefer-function-reference": "warn"
|
|
165
|
+
"@bigbinary/neeto/prefer-function-reference": "warn",
|
|
166
|
+
"@bigbinary/neeto/jsx-prefer-guard-clause": "warn"
|
|
166
167
|
};
|
|
167
168
|
|
|
168
169
|
var recommended = {
|
|
@@ -564,6 +565,7 @@
|
|
|
564
565
|
var NO_TRANSLATION_LOWERCASE = "No need to lowercase i18next translations";
|
|
565
566
|
var AVOID_SNAKE_CASE_DESTRUCTURING_USEQUERYPARAMS_OR_GETQUERYPARAMS = "Avoid destructuring snake-cased values from getQueryParams or useQueryParams";
|
|
566
567
|
var PREFER_FUNCTION_REFERENCE = "Prefer passing function reference instead of creating a new function as the parameters and arguments are the same.";
|
|
568
|
+
var JSX_PREFER_GUARD_CLAUSE = "Prefer adding a guard clause for conditional statements left of JSX statments in the last return statement of the function.";
|
|
567
569
|
|
|
568
570
|
var PACKAGES_TO_CHECK = ["@bigbinary/neeto-molecules", "@bigbinary/neetoui", "@bigbinary/neeto-commons-frontend"];
|
|
569
571
|
|
|
@@ -1315,7 +1317,7 @@
|
|
|
1315
1317
|
}
|
|
1316
1318
|
};
|
|
1317
1319
|
|
|
1318
|
-
var checkAndReport$
|
|
1320
|
+
var checkAndReport$8 = function checkAndReport(context, node) {
|
|
1319
1321
|
if (!isInsideApisDirectory(context)) return;
|
|
1320
1322
|
context.report({
|
|
1321
1323
|
node: node,
|
|
@@ -1333,11 +1335,11 @@
|
|
|
1333
1335
|
create: function create(context) {
|
|
1334
1336
|
return {
|
|
1335
1337
|
ExportNamedDeclaration: function ExportNamedDeclaration(node) {
|
|
1336
|
-
checkAndReport$
|
|
1338
|
+
checkAndReport$8(context, node);
|
|
1337
1339
|
},
|
|
1338
1340
|
ExportDefaultDeclaration: function ExportDefaultDeclaration(node) {
|
|
1339
1341
|
if (node.declaration.type !== TYPES.OBJECT_EXPRESSION) return;
|
|
1340
|
-
checkAndReport$
|
|
1342
|
+
checkAndReport$8(context, node);
|
|
1341
1343
|
}
|
|
1342
1344
|
};
|
|
1343
1345
|
}
|
|
@@ -1439,7 +1441,7 @@
|
|
|
1439
1441
|
}
|
|
1440
1442
|
});
|
|
1441
1443
|
};
|
|
1442
|
-
var checkAndReport$
|
|
1444
|
+
var checkAndReport$7 = function checkAndReport(context, node) {
|
|
1443
1445
|
if (!node.async) return;
|
|
1444
1446
|
var subsequentAwaits = getIndependentAwaits(node);
|
|
1445
1447
|
if (subsequentAwaits.length === 0) return;
|
|
@@ -1460,15 +1462,15 @@
|
|
|
1460
1462
|
return {
|
|
1461
1463
|
// const sum = (a, b) => a + b;
|
|
1462
1464
|
ArrowFunctionExpression: function ArrowFunctionExpression(node) {
|
|
1463
|
-
checkAndReport$
|
|
1465
|
+
checkAndReport$7(context, node);
|
|
1464
1466
|
},
|
|
1465
1467
|
// const sum = function (a, b) { return a + b };
|
|
1466
1468
|
FunctionExpression: function FunctionExpression(node) {
|
|
1467
|
-
checkAndReport$
|
|
1469
|
+
checkAndReport$7(context, node);
|
|
1468
1470
|
},
|
|
1469
1471
|
// function sum (a, b) { return a + b };
|
|
1470
1472
|
FunctionDeclaration: function FunctionDeclaration(node) {
|
|
1471
|
-
checkAndReport$
|
|
1473
|
+
checkAndReport$7(context, node);
|
|
1472
1474
|
}
|
|
1473
1475
|
};
|
|
1474
1476
|
}
|
|
@@ -3773,6 +3775,49 @@
|
|
|
3773
3775
|
}
|
|
3774
3776
|
};
|
|
3775
3777
|
|
|
3778
|
+
var checkAndReport$6 = function checkAndReport(context, node) {
|
|
3779
|
+
var _lastStatement$argume;
|
|
3780
|
+
if (node.body.type !== TYPES.BLOCK_STATEMENT) return;
|
|
3781
|
+
var statements = node.body.body;
|
|
3782
|
+
if (statements.length <= 0) return;
|
|
3783
|
+
var lastStatement = ramda.last(statements);
|
|
3784
|
+
if (lastStatement.type !== TYPES.RETURN_STATEMENT) return;
|
|
3785
|
+
if (lastStatement.argument.type !== TYPES.LOGICAL_EXPRESSION || ((_lastStatement$argume = lastStatement.argument) === null || _lastStatement$argume === void 0 ? void 0 : _lastStatement$argume.operator) !== "&&") {
|
|
3786
|
+
return;
|
|
3787
|
+
}
|
|
3788
|
+
var _lastStatement$argume2 = lastStatement.argument,
|
|
3789
|
+
left = _lastStatement$argume2.left,
|
|
3790
|
+
right = _lastStatement$argume2.right;
|
|
3791
|
+
var isJsxStatement = [TYPES.JSX_ELEMENT, TYPES.JSX_EXPRESSION_CONTAINER, TYPES.JSX_IDENTIFIER, TYPES.JSX_OPENING_ELEMENT].includes(right.type);
|
|
3792
|
+
|
|
3793
|
+
// If it's a logical expression and if the right side arg is JSX
|
|
3794
|
+
// then we can suggest using guard clause
|
|
3795
|
+
if (isJsxStatement) {
|
|
3796
|
+
context.report({
|
|
3797
|
+
node: left,
|
|
3798
|
+
message: JSX_PREFER_GUARD_CLAUSE
|
|
3799
|
+
});
|
|
3800
|
+
}
|
|
3801
|
+
};
|
|
3802
|
+
var jsxPreferGuardClause = {
|
|
3803
|
+
meta: {
|
|
3804
|
+
type: "suggestion",
|
|
3805
|
+
docs: {
|
|
3806
|
+
url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/jsx-prefer-guard-clause.md",
|
|
3807
|
+
description: "Encourage using a guard clause for the last conditional return statement of a JSX component.",
|
|
3808
|
+
category: "Best Practices",
|
|
3809
|
+
recommended: true
|
|
3810
|
+
}
|
|
3811
|
+
},
|
|
3812
|
+
create: function create(context) {
|
|
3813
|
+
return {
|
|
3814
|
+
ArrowFunctionExpression: function ArrowFunctionExpression(node) {
|
|
3815
|
+
checkAndReport$6(context, node);
|
|
3816
|
+
}
|
|
3817
|
+
};
|
|
3818
|
+
}
|
|
3819
|
+
};
|
|
3820
|
+
|
|
3776
3821
|
function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3777
3822
|
function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$3(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3778
3823
|
var LOCALIZATION_CALL_PATTERNS = [{
|
|
@@ -10482,7 +10527,8 @@
|
|
|
10482
10527
|
"add-required-peer-dependencies": addRequiredPeerDependencies,
|
|
10483
10528
|
"use-common-constants": useCommonConstants,
|
|
10484
10529
|
"move-spread-attributes-to-top-position": moveSpreadAttributesToTopPosition,
|
|
10485
|
-
"prefer-function-reference": preferFunctionReference
|
|
10530
|
+
"prefer-function-reference": preferFunctionReference,
|
|
10531
|
+
"jsx-prefer-guard-clause": jsxPreferGuardClause
|
|
10486
10532
|
},
|
|
10487
10533
|
configs: {
|
|
10488
10534
|
recommended: recommended,
|