@bigbinary/eslint-plugin-neeto 1.0.58 → 1.0.59
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.js +115 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -117,7 +117,8 @@
|
|
|
117
117
|
}],
|
|
118
118
|
"@bigbinary/neeto/zustand-recommend-comparator-function-usage": "warn",
|
|
119
119
|
"@bigbinary/neeto/zustand-use-prop-to-pick-single-item": "error",
|
|
120
|
-
"@bigbinary/neeto/use-functions-and-hooks-from-neeto-commons-frontend": "warn"
|
|
120
|
+
"@bigbinary/neeto/use-functions-and-hooks-from-neeto-commons-frontend": "warn",
|
|
121
|
+
"@bigbinary/neeto/no-unnecessary-if-condition": "error"
|
|
121
122
|
};
|
|
122
123
|
|
|
123
124
|
var recommended = {
|
|
@@ -1202,8 +1203,8 @@
|
|
|
1202
1203
|
return node === ((_node$parent2 = node.parent) === null || _node$parent2 === void 0 ? void 0 : _node$parent2.key);
|
|
1203
1204
|
};
|
|
1204
1205
|
|
|
1205
|
-
function ownKeys$
|
|
1206
|
-
function _objectSpread$
|
|
1206
|
+
function ownKeys$5(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; }
|
|
1207
|
+
function _objectSpread$5(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$5(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$5(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
1207
1208
|
var areAwaitsSubsequent = function areAwaitsSubsequent(awaitParent, subsequentAwaits, functionBody) {
|
|
1208
1209
|
var _last, _last2;
|
|
1209
1210
|
if (subsequentAwaits.length === 0) return false;
|
|
@@ -1218,7 +1219,7 @@
|
|
|
1218
1219
|
};
|
|
1219
1220
|
var identifiersUsed = function identifiersUsed(node, identifiers) {
|
|
1220
1221
|
return identifiers.length > 0 && identifiers.some(function (identifier) {
|
|
1221
|
-
return findMatchingNodesDeep(node, _objectSpread$
|
|
1222
|
+
return findMatchingNodesDeep(node, _objectSpread$5(_objectSpread$5({}, IDENTIFIER_PATTERN$1), {}, {
|
|
1222
1223
|
name: identifier.name
|
|
1223
1224
|
})).some(function (node) {
|
|
1224
1225
|
return !isKeyNode(node);
|
|
@@ -3600,8 +3601,8 @@
|
|
|
3600
3601
|
}
|
|
3601
3602
|
};
|
|
3602
3603
|
|
|
3603
|
-
function ownKeys$
|
|
3604
|
-
function _objectSpread$
|
|
3604
|
+
function ownKeys$4(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; }
|
|
3605
|
+
function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$4(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3605
3606
|
var LOCALIZATION_CALL_PATTERNS = [{
|
|
3606
3607
|
callee: {
|
|
3607
3608
|
type: TYPES.IDENTIFIER,
|
|
@@ -3679,7 +3680,7 @@
|
|
|
3679
3680
|
};
|
|
3680
3681
|
|
|
3681
3682
|
// '<Trans i18nKey="important">This is the <strong>important part</strong></Trans>'
|
|
3682
|
-
var TRANS_WITH_CHILDREN_PATTERN = _objectSpread$
|
|
3683
|
+
var TRANS_WITH_CHILDREN_PATTERN = _objectSpread$4(_objectSpread$4({}, TRANS_COMPONENT_PATTERN), {}, {
|
|
3683
3684
|
children: isNotEmpty$1
|
|
3684
3685
|
});
|
|
3685
3686
|
|
|
@@ -4013,8 +4014,8 @@
|
|
|
4013
4014
|
return null;
|
|
4014
4015
|
};
|
|
4015
4016
|
|
|
4016
|
-
function ownKeys$
|
|
4017
|
-
function _objectSpread$
|
|
4017
|
+
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; }
|
|
4018
|
+
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; }
|
|
4018
4019
|
var translationFiles = [];
|
|
4019
4020
|
var previousOptions = null;
|
|
4020
4021
|
var watcher$1 = null;
|
|
@@ -4053,7 +4054,7 @@
|
|
|
4053
4054
|
var lng = _ref2.lng,
|
|
4054
4055
|
content = _ref2.content;
|
|
4055
4056
|
return isKeyMissing({
|
|
4056
|
-
config: _objectSpread$
|
|
4057
|
+
config: _objectSpread$3(_objectSpread$3({}, config), {}, {
|
|
4057
4058
|
lng: lng
|
|
4058
4059
|
}),
|
|
4059
4060
|
content: content,
|
|
@@ -5153,8 +5154,8 @@
|
|
|
5153
5154
|
}
|
|
5154
5155
|
};
|
|
5155
5156
|
|
|
5156
|
-
function ownKeys$
|
|
5157
|
-
function _objectSpread$
|
|
5157
|
+
function ownKeys$2(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; }
|
|
5158
|
+
function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$2(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
5158
5159
|
|
|
5159
5160
|
// matches property onClick:
|
|
5160
5161
|
var ONCLICK_PROPERTY_PATTERN = {
|
|
@@ -5233,7 +5234,7 @@
|
|
|
5233
5234
|
//() => { single line; }, () => functionCall()
|
|
5234
5235
|
//(event) => { single line;}, e => { single line; }
|
|
5235
5236
|
// functionCall()
|
|
5236
|
-
var CURRIED_HANDLE_METACLICK_REPLACABLE_PATTERNS = [_objectSpread$
|
|
5237
|
+
var CURRIED_HANDLE_METACLICK_REPLACABLE_PATTERNS = [_objectSpread$2(_objectSpread$2({}, SINGLE_EXPRESSION_ARROW_FUNCTION_PATTERN), {}, {
|
|
5237
5238
|
params: function params(_params) {
|
|
5238
5239
|
return _params.length <= 1;
|
|
5239
5240
|
}
|
|
@@ -6044,6 +6045,105 @@
|
|
|
6044
6045
|
}
|
|
6045
6046
|
};
|
|
6046
6047
|
|
|
6048
|
+
// if (condition) statement;
|
|
6049
|
+
var SINGLE_LINE_IF_CONDITION_PATTERN = {
|
|
6050
|
+
parent: {
|
|
6051
|
+
type: TYPES.IF_STATEMENT
|
|
6052
|
+
}
|
|
6053
|
+
};
|
|
6054
|
+
|
|
6055
|
+
/**
|
|
6056
|
+
* if (condition) {
|
|
6057
|
+
* // single line of code
|
|
6058
|
+
* }
|
|
6059
|
+
*/
|
|
6060
|
+
var SINGLE_LINE_BLOCK_IF_CONDITION_PATTERN = {
|
|
6061
|
+
parent: {
|
|
6062
|
+
type: TYPES.BLOCK_STATEMENT,
|
|
6063
|
+
body: {
|
|
6064
|
+
length: 1
|
|
6065
|
+
},
|
|
6066
|
+
parent: {
|
|
6067
|
+
type: TYPES.IF_STATEMENT
|
|
6068
|
+
}
|
|
6069
|
+
}
|
|
6070
|
+
};
|
|
6071
|
+
|
|
6072
|
+
var isInsideAnIfCondition = ramda.either(matches(SINGLE_LINE_IF_CONDITION_PATTERN), matches(SINGLE_LINE_BLOCK_IF_CONDITION_PATTERN));
|
|
6073
|
+
var getIfCondition = function getIfCondition(node) {
|
|
6074
|
+
var _node$parent, _node$parent2;
|
|
6075
|
+
return ((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) === TYPES.IF_STATEMENT ? node.parent : (_node$parent2 = node.parent) === null || _node$parent2 === void 0 ? void 0 : _node$parent2.parent;
|
|
6076
|
+
};
|
|
6077
|
+
var findLastStatementInBlock = function findLastStatementInBlock(block) {
|
|
6078
|
+
var _block$body;
|
|
6079
|
+
return ramda.last((_block$body = block === null || block === void 0 ? void 0 : block.body) !== null && _block$body !== void 0 ? _block$body : []);
|
|
6080
|
+
};
|
|
6081
|
+
var isBoolean = function isBoolean(value) {
|
|
6082
|
+
return typeof value === "boolean";
|
|
6083
|
+
};
|
|
6084
|
+
|
|
6085
|
+
// return value;
|
|
6086
|
+
var isReturnStatementWithValue = function isReturnStatementWithValue(node, value) {
|
|
6087
|
+
return matches({
|
|
6088
|
+
type: TYPES.RETURN_STATEMENT,
|
|
6089
|
+
argument: {
|
|
6090
|
+
value: value
|
|
6091
|
+
}
|
|
6092
|
+
}, node);
|
|
6093
|
+
};
|
|
6094
|
+
var isFinalIfBeforeBooleanReturn = function isFinalIfBeforeBooleanReturn(ifNode, lastStatement, argumentValue) {
|
|
6095
|
+
var _ifNode$parent;
|
|
6096
|
+
if ((ifNode === null || ifNode === void 0 ? void 0 : (_ifNode$parent = ifNode.parent) === null || _ifNode$parent === void 0 ? void 0 : _ifNode$parent.type) !== TYPES.BLOCK_STATEMENT) {
|
|
6097
|
+
return false;
|
|
6098
|
+
}
|
|
6099
|
+
var isFinalIf = ifNode === ifNode.parent.body.at(-2);
|
|
6100
|
+
return isReturnStatementWithValue(lastStatement, argumentValue) && isFinalIf;
|
|
6101
|
+
};
|
|
6102
|
+
|
|
6103
|
+
function ownKeys$1(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; }
|
|
6104
|
+
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6105
|
+
var noUnnecessaryIfCondition = {
|
|
6106
|
+
meta: {
|
|
6107
|
+
type: "suggestion",
|
|
6108
|
+
docs: {
|
|
6109
|
+
url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/no-unnecessary-if-condition.md",
|
|
6110
|
+
description: "Prevents unnecessary if condition"
|
|
6111
|
+
},
|
|
6112
|
+
fixable: "code"
|
|
6113
|
+
},
|
|
6114
|
+
create: function create(context) {
|
|
6115
|
+
return {
|
|
6116
|
+
ReturnStatement: function ReturnStatement(node) {
|
|
6117
|
+
var _ref = node.argument || {},
|
|
6118
|
+
value = _ref.value;
|
|
6119
|
+
if (!isBoolean(value)) return;
|
|
6120
|
+
if (!isInsideAnIfCondition(node)) return;
|
|
6121
|
+
var ifConditionNode = getIfCondition(node);
|
|
6122
|
+
var lastStatement = findLastStatementInBlock(ifConditionNode.parent);
|
|
6123
|
+
if (!isFinalIfBeforeBooleanReturn(ifConditionNode, lastStatement, !value)) {
|
|
6124
|
+
return;
|
|
6125
|
+
}
|
|
6126
|
+
var condition = context.getSourceCode().getText(ifConditionNode.test);
|
|
6127
|
+
var returnStatementWithCondition = value ? "return ".concat(condition, ";") : "return !(".concat(condition, ");");
|
|
6128
|
+
var commonDescriptor = {
|
|
6129
|
+
message: canBeReplacedWith(returnStatementWithCondition),
|
|
6130
|
+
fix: function fix(fixer) {
|
|
6131
|
+
var removeIfConditions = fixer.replaceText(ifConditionNode, returnStatementWithCondition);
|
|
6132
|
+
var removeReturnStatement = fixer.remove(lastStatement);
|
|
6133
|
+
return [removeIfConditions, removeReturnStatement];
|
|
6134
|
+
}
|
|
6135
|
+
};
|
|
6136
|
+
context.report(_objectSpread$1({
|
|
6137
|
+
node: lastStatement
|
|
6138
|
+
}, commonDescriptor));
|
|
6139
|
+
context.report(_objectSpread$1({
|
|
6140
|
+
node: ifConditionNode
|
|
6141
|
+
}, commonDescriptor));
|
|
6142
|
+
}
|
|
6143
|
+
};
|
|
6144
|
+
}
|
|
6145
|
+
};
|
|
6146
|
+
|
|
6047
6147
|
var NEETO_PACKAGES = ["@bigbinary/neetoui", "@bigbinary/neeto-icons"];
|
|
6048
6148
|
|
|
6049
6149
|
var importedFromNeeto = function importedFromNeeto(context, node) {
|
|
@@ -25563,7 +25663,8 @@
|
|
|
25563
25663
|
"merge-spread-attributes": mergeSpreadAttributes,
|
|
25564
25664
|
"props-with-different-key-value-should-be-outside-spread-attribute": propsWithDifferentKeyValueShouldBeOutsideSpreadAttribute,
|
|
25565
25665
|
"no-repetition-in-prop-key-value-names": noRepetitionInPropKeyAndValueName,
|
|
25566
|
-
"use-functions-and-hooks-from-neeto-commons-frontend": useFunctionsAndHooksFromNeetoCommonsFrontend
|
|
25666
|
+
"use-functions-and-hooks-from-neeto-commons-frontend": useFunctionsAndHooksFromNeetoCommonsFrontend,
|
|
25667
|
+
"no-unnecessary-if-condition": noUnnecessaryIfCondition
|
|
25567
25668
|
},
|
|
25568
25669
|
configs: {
|
|
25569
25670
|
recommended: recommended
|