@bigbinary/eslint-plugin-neeto 1.1.34 → 1.1.36
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 +2 -0
- package/dist/index.js +122 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,6 +46,7 @@ module.exports = {
|
|
|
46
46
|
|
|
47
47
|
## Exported rules
|
|
48
48
|
|
|
49
|
+
- [no-snake-case-destructuring-for-use-query-params-and-get-query-params](./docs/src/rules/no-snake-case-destructuring-for-use-query-params-and-get-query-params.md)
|
|
49
50
|
- [no-local-storage](./docs/src/rules/no-local-storage.md)
|
|
50
51
|
- [no-lowercase-on-translation](./docs/src/rules/no-lowercase-on-translation.md)
|
|
51
52
|
- [use-use-query-client-hook](./docs/src/rules/use-use-query-client-hook.md)
|
|
@@ -120,6 +121,7 @@ module.exports = {
|
|
|
120
121
|
- [zustand-use-with-immutable-actions-wrapper-inside-create](./docs/src/rules/zustand-use-with-immutable-actions-wrapper-inside-create.md)
|
|
121
122
|
- [add-required-peer-dependencies](./docs/src/rules/add-required-peer-dependencies.md)
|
|
122
123
|
- [move-spread-attributes-to-top-position](./docs/src/rules/move-spread-attributes-to-top-position.md)
|
|
124
|
+
- [prefer-function-reference.md](./docs/src/rules/prefer-function-reference.md)
|
|
123
125
|
|
|
124
126
|
## Other references
|
|
125
127
|
|
package/dist/index.js
CHANGED
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
var commonResolve$2 = loadJS$2("node_modules/@bigbinary/neeto-commons-frontend/configs/webpack/resolve.js");
|
|
43
43
|
var resolve$2 = ramda.mergeDeepLeft(projectResolve$2, commonResolve$2);
|
|
44
44
|
var rules = {
|
|
45
|
+
"@bigbinary/neeto/no-snake-case-destructuring-for-use-query-params-and-get-query-params": "warn",
|
|
45
46
|
"@bigbinary/neeto/no-local-storage": "error",
|
|
46
47
|
"@bigbinary/neeto/no-lowercase-on-translation": "warn",
|
|
47
48
|
"@bigbinary/neeto/use-use-query-client-hook": "error",
|
|
@@ -160,7 +161,8 @@
|
|
|
160
161
|
"@bigbinary/neeto/props-inside-spread-attributes-should-be-sorted": "error",
|
|
161
162
|
"@bigbinary/neeto/props-with-different-key-value-should-be-outside-spread-attribute": "error",
|
|
162
163
|
"@bigbinary/neeto/use-common-constants": "warn",
|
|
163
|
-
"@bigbinary/neeto/move-spread-attributes-to-top-position": "error"
|
|
164
|
+
"@bigbinary/neeto/move-spread-attributes-to-top-position": "error",
|
|
165
|
+
"@bigbinary/neeto/prefer-function-reference": "warn"
|
|
164
166
|
};
|
|
165
167
|
|
|
166
168
|
var recommended = {
|
|
@@ -560,6 +562,8 @@
|
|
|
560
562
|
var USE_EARLY_RETURN = "Use early return to avoid nested statement";
|
|
561
563
|
var NO_LOCAL_STORAGE = "Do not use localStorage directly. Use 'getFromLocalStorage()', 'setToLocalStorage()', 'removeFromLocalStorage()' or 'useLocalStorage()' from neeto-commons-frontend instead.";
|
|
562
564
|
var NO_TRANSLATION_LOWERCASE = "No need to lowercase i18next translations";
|
|
565
|
+
var AVOID_SNAKE_CASE_DESTRUCTURING_USEQUERYPARAMS_OR_GETQUERYPARAMS = "Avoid destructuring snake-cased values from getQueryParams or useQueryParams";
|
|
566
|
+
var PREFER_FUNCTION_REFERENCE = "Prefer passing function reference instead of creating a new function as the parameters and arguments are the same.";
|
|
563
567
|
|
|
564
568
|
var PACKAGES_TO_CHECK = ["@bigbinary/neeto-molecules", "@bigbinary/neetoui", "@bigbinary/neeto-commons-frontend"];
|
|
565
569
|
|
|
@@ -1311,7 +1315,7 @@
|
|
|
1311
1315
|
}
|
|
1312
1316
|
};
|
|
1313
1317
|
|
|
1314
|
-
var checkAndReport$
|
|
1318
|
+
var checkAndReport$7 = function checkAndReport(context, node) {
|
|
1315
1319
|
if (!isInsideApisDirectory(context)) return;
|
|
1316
1320
|
context.report({
|
|
1317
1321
|
node: node,
|
|
@@ -1329,11 +1333,11 @@
|
|
|
1329
1333
|
create: function create(context) {
|
|
1330
1334
|
return {
|
|
1331
1335
|
ExportNamedDeclaration: function ExportNamedDeclaration(node) {
|
|
1332
|
-
checkAndReport$
|
|
1336
|
+
checkAndReport$7(context, node);
|
|
1333
1337
|
},
|
|
1334
1338
|
ExportDefaultDeclaration: function ExportDefaultDeclaration(node) {
|
|
1335
1339
|
if (node.declaration.type !== TYPES.OBJECT_EXPRESSION) return;
|
|
1336
|
-
checkAndReport$
|
|
1340
|
+
checkAndReport$7(context, node);
|
|
1337
1341
|
}
|
|
1338
1342
|
};
|
|
1339
1343
|
}
|
|
@@ -1435,7 +1439,7 @@
|
|
|
1435
1439
|
}
|
|
1436
1440
|
});
|
|
1437
1441
|
};
|
|
1438
|
-
var checkAndReport$
|
|
1442
|
+
var checkAndReport$6 = function checkAndReport(context, node) {
|
|
1439
1443
|
if (!node.async) return;
|
|
1440
1444
|
var subsequentAwaits = getIndependentAwaits(node);
|
|
1441
1445
|
if (subsequentAwaits.length === 0) return;
|
|
@@ -1456,15 +1460,15 @@
|
|
|
1456
1460
|
return {
|
|
1457
1461
|
// const sum = (a, b) => a + b;
|
|
1458
1462
|
ArrowFunctionExpression: function ArrowFunctionExpression(node) {
|
|
1459
|
-
checkAndReport$
|
|
1463
|
+
checkAndReport$6(context, node);
|
|
1460
1464
|
},
|
|
1461
1465
|
// const sum = function (a, b) { return a + b };
|
|
1462
1466
|
FunctionExpression: function FunctionExpression(node) {
|
|
1463
|
-
checkAndReport$
|
|
1467
|
+
checkAndReport$6(context, node);
|
|
1464
1468
|
},
|
|
1465
1469
|
// function sum (a, b) { return a + b };
|
|
1466
1470
|
FunctionDeclaration: function FunctionDeclaration(node) {
|
|
1467
|
-
checkAndReport$
|
|
1471
|
+
checkAndReport$6(context, node);
|
|
1468
1472
|
}
|
|
1469
1473
|
};
|
|
1470
1474
|
}
|
|
@@ -4092,7 +4096,7 @@
|
|
|
4092
4096
|
}
|
|
4093
4097
|
return false;
|
|
4094
4098
|
};
|
|
4095
|
-
var checkAndReport$
|
|
4099
|
+
var checkAndReport$5 = function checkAndReport(node, context) {
|
|
4096
4100
|
if (!shouldReport(node, context)) return;
|
|
4097
4101
|
context.report({
|
|
4098
4102
|
node: node,
|
|
@@ -4110,13 +4114,13 @@
|
|
|
4110
4114
|
create: function create(context) {
|
|
4111
4115
|
return {
|
|
4112
4116
|
Literal: function Literal(node) {
|
|
4113
|
-
checkAndReport$
|
|
4117
|
+
checkAndReport$5(node, context);
|
|
4114
4118
|
},
|
|
4115
4119
|
TemplateLiteral: function TemplateLiteral(node) {
|
|
4116
|
-
checkAndReport$
|
|
4120
|
+
checkAndReport$5(node, context);
|
|
4117
4121
|
},
|
|
4118
4122
|
JSXText: function JSXText(node) {
|
|
4119
|
-
checkAndReport$
|
|
4123
|
+
checkAndReport$5(node, context);
|
|
4120
4124
|
}
|
|
4121
4125
|
};
|
|
4122
4126
|
}
|
|
@@ -4234,7 +4238,7 @@
|
|
|
4234
4238
|
}, ramda.assoc("content", _objectSpread$2(_objectSpread$2({}, parseJsonData(path$2.join(translationsDirPath, changedFileName))), nanosContent[lng])), translationFiles);
|
|
4235
4239
|
});
|
|
4236
4240
|
};
|
|
4237
|
-
var checkAndReport$
|
|
4241
|
+
var checkAndReport$4 = function checkAndReport(_ref) {
|
|
4238
4242
|
var _config$context, _config$count;
|
|
4239
4243
|
var context = _ref.context,
|
|
4240
4244
|
node = _ref.node,
|
|
@@ -4317,7 +4321,7 @@
|
|
|
4317
4321
|
config.count = getObjectPropValue(node.arguments[1], "count");
|
|
4318
4322
|
config.context = getObjectPropValue(node.arguments[1], "context");
|
|
4319
4323
|
}
|
|
4320
|
-
checkAndReport$
|
|
4324
|
+
checkAndReport$4({
|
|
4321
4325
|
key: node.arguments[0].value,
|
|
4322
4326
|
context: context,
|
|
4323
4327
|
node: node,
|
|
@@ -4335,7 +4339,7 @@
|
|
|
4335
4339
|
count: getCountNode(node),
|
|
4336
4340
|
context: contextAttribute === null || contextAttribute === void 0 ? void 0 : contextAttribute.value
|
|
4337
4341
|
};
|
|
4338
|
-
checkAndReport$
|
|
4342
|
+
checkAndReport$4({
|
|
4339
4343
|
key: keyNode.value,
|
|
4340
4344
|
context: context,
|
|
4341
4345
|
node: node,
|
|
@@ -6121,7 +6125,7 @@
|
|
|
6121
6125
|
return getCode$1(context, param);
|
|
6122
6126
|
}).join(", ");
|
|
6123
6127
|
};
|
|
6124
|
-
var checkAndReport$
|
|
6128
|
+
var checkAndReport$3 = function checkAndReport(context, params) {
|
|
6125
6129
|
var isApiAction = isInsideApisDirectory(context);
|
|
6126
6130
|
if (!containsExcessArguments(params, isApiAction)) return;
|
|
6127
6131
|
var loc = {
|
|
@@ -6153,15 +6157,15 @@
|
|
|
6153
6157
|
return {
|
|
6154
6158
|
// const sum = (a, b) => a + b;
|
|
6155
6159
|
ArrowFunctionExpression: function ArrowFunctionExpression(node) {
|
|
6156
|
-
checkAndReport$
|
|
6160
|
+
checkAndReport$3(context, node.params);
|
|
6157
6161
|
},
|
|
6158
6162
|
// const sum = function (a, b) { return a + b };
|
|
6159
6163
|
FunctionExpression: function FunctionExpression(node) {
|
|
6160
|
-
checkAndReport$
|
|
6164
|
+
checkAndReport$3(context, node.params);
|
|
6161
6165
|
},
|
|
6162
6166
|
// function sum (a, b) { return a + b };
|
|
6163
6167
|
FunctionDeclaration: function FunctionDeclaration(node) {
|
|
6164
|
-
checkAndReport$
|
|
6168
|
+
checkAndReport$3(context, node.params);
|
|
6165
6169
|
}
|
|
6166
6170
|
};
|
|
6167
6171
|
}
|
|
@@ -6551,6 +6555,58 @@
|
|
|
6551
6555
|
}
|
|
6552
6556
|
};
|
|
6553
6557
|
|
|
6558
|
+
var SNAKE_CASE_WITHOUT_SINGLE_WORDS = /^[a-z]+_[a-z0-9_]+$/;
|
|
6559
|
+
var PATTERN = {
|
|
6560
|
+
id: {
|
|
6561
|
+
type: "ObjectPattern",
|
|
6562
|
+
properties: ramda.any(neetoCist.matches({
|
|
6563
|
+
type: "Property",
|
|
6564
|
+
key: {
|
|
6565
|
+
name: ramda.test(SNAKE_CASE_WITHOUT_SINGLE_WORDS)
|
|
6566
|
+
}
|
|
6567
|
+
}))
|
|
6568
|
+
},
|
|
6569
|
+
init: {
|
|
6570
|
+
type: "CallExpression",
|
|
6571
|
+
callee: {
|
|
6572
|
+
name: matchesAny(["getQueryParams", "useQueryParams"])
|
|
6573
|
+
},
|
|
6574
|
+
arguments: ramda.none(neetoCist.matches({
|
|
6575
|
+
type: "ObjectExpression",
|
|
6576
|
+
properties: ramda.any(neetoCist.matches({
|
|
6577
|
+
key: {
|
|
6578
|
+
name: "toCamelCase"
|
|
6579
|
+
},
|
|
6580
|
+
value: {
|
|
6581
|
+
value: false
|
|
6582
|
+
}
|
|
6583
|
+
}))
|
|
6584
|
+
}))
|
|
6585
|
+
}
|
|
6586
|
+
};
|
|
6587
|
+
|
|
6588
|
+
var noSnakeCaseDestructuringForUseQueryParamsAndGetQueryParams = {
|
|
6589
|
+
meta: {
|
|
6590
|
+
type: "warn",
|
|
6591
|
+
docs: {
|
|
6592
|
+
url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/no-snake-case-destructuring-for-use-query-params-and-get-query-params.md",
|
|
6593
|
+
description: "Prevent destructuring snake-cased values within the useQueryParams and getQueryParams function"
|
|
6594
|
+
}
|
|
6595
|
+
},
|
|
6596
|
+
create: function create(context) {
|
|
6597
|
+
return {
|
|
6598
|
+
VariableDeclarator: function VariableDeclarator(node) {
|
|
6599
|
+
if (neetoCist.matches(PATTERN, node)) {
|
|
6600
|
+
context.report({
|
|
6601
|
+
node: node,
|
|
6602
|
+
message: AVOID_SNAKE_CASE_DESTRUCTURING_USEQUERYPARAMS_OR_GETQUERYPARAMS
|
|
6603
|
+
});
|
|
6604
|
+
}
|
|
6605
|
+
}
|
|
6606
|
+
};
|
|
6607
|
+
}
|
|
6608
|
+
};
|
|
6609
|
+
|
|
6554
6610
|
// if (condition) statement;
|
|
6555
6611
|
var SINGLE_LINE_IF_CONDITION_PATTERN = {
|
|
6556
6612
|
parent: {
|
|
@@ -6830,6 +6886,50 @@
|
|
|
6830
6886
|
}
|
|
6831
6887
|
};
|
|
6832
6888
|
|
|
6889
|
+
var buildCodeArray = function buildCodeArray(_ref) {
|
|
6890
|
+
var values = _ref.values,
|
|
6891
|
+
context = _ref.context;
|
|
6892
|
+
return values.map(function (value) {
|
|
6893
|
+
return getCode$1(context, value).replace(/\s/g, "");
|
|
6894
|
+
});
|
|
6895
|
+
};
|
|
6896
|
+
var checkAndReport$2 = function checkAndReport(context, node) {
|
|
6897
|
+
// Don't catch arrow function JSX component declaration
|
|
6898
|
+
if (node.body.type !== TYPES.CALL_EXPRESSION) return;
|
|
6899
|
+
var params = buildCodeArray({
|
|
6900
|
+
values: node.params,
|
|
6901
|
+
context: context
|
|
6902
|
+
});
|
|
6903
|
+
var args = buildCodeArray({
|
|
6904
|
+
values: node.body.arguments,
|
|
6905
|
+
context: context
|
|
6906
|
+
});
|
|
6907
|
+
if (ramda.equals(params, args)) {
|
|
6908
|
+
context.report({
|
|
6909
|
+
node: node,
|
|
6910
|
+
message: PREFER_FUNCTION_REFERENCE
|
|
6911
|
+
});
|
|
6912
|
+
}
|
|
6913
|
+
};
|
|
6914
|
+
var preferFunctionReference = {
|
|
6915
|
+
meta: {
|
|
6916
|
+
type: "suggestion",
|
|
6917
|
+
docs: {
|
|
6918
|
+
url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/prefer-function-reference.md",
|
|
6919
|
+
description: "Discourage creating a new function when the existing function can be passed as reference",
|
|
6920
|
+
category: "Best Practices",
|
|
6921
|
+
recommended: true
|
|
6922
|
+
}
|
|
6923
|
+
},
|
|
6924
|
+
create: function create(context) {
|
|
6925
|
+
return {
|
|
6926
|
+
ArrowFunctionExpression: function ArrowFunctionExpression(node) {
|
|
6927
|
+
checkAndReport$2(context, node);
|
|
6928
|
+
}
|
|
6929
|
+
};
|
|
6930
|
+
}
|
|
6931
|
+
};
|
|
6932
|
+
|
|
6833
6933
|
var NEETO_PACKAGES = ["@bigbinary/neetoui", "@bigbinary/neeto-icons"];
|
|
6834
6934
|
|
|
6835
6935
|
var importedFromNeeto = function importedFromNeeto(context, node) {
|
|
@@ -10298,6 +10398,7 @@
|
|
|
10298
10398
|
|
|
10299
10399
|
var index = {
|
|
10300
10400
|
rules: {
|
|
10401
|
+
"no-snake-case-destructuring-for-use-query-params-and-get-query-params": noSnakeCaseDestructuringForUseQueryParamsAndGetQueryParams,
|
|
10301
10402
|
"no-local-storage": noLocalStorage,
|
|
10302
10403
|
"no-lowercase-on-translation": noLowercaseOnTranslation,
|
|
10303
10404
|
"use-use-query-client-hook": useUseQueryClientHook,
|
|
@@ -10373,7 +10474,8 @@
|
|
|
10373
10474
|
"zustand-use-with-immutable-actions-wrapper-inside-create": useWithImmutableActionsWrapperInsideCreate,
|
|
10374
10475
|
"add-required-peer-dependencies": addRequiredPeerDependencies,
|
|
10375
10476
|
"use-common-constants": useCommonConstants,
|
|
10376
|
-
"move-spread-attributes-to-top-position": moveSpreadAttributesToTopPosition
|
|
10477
|
+
"move-spread-attributes-to-top-position": moveSpreadAttributesToTopPosition,
|
|
10478
|
+
"prefer-function-reference": preferFunctionReference
|
|
10377
10479
|
},
|
|
10378
10480
|
configs: {
|
|
10379
10481
|
recommended: recommended,
|