@bigbinary/eslint-plugin-neeto 1.1.35 → 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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/dist/index.js +67 -20
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -121,6 +121,7 @@ module.exports = {
121
121
  - [zustand-use-with-immutable-actions-wrapper-inside-create](./docs/src/rules/zustand-use-with-immutable-actions-wrapper-inside-create.md)
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
+ - [prefer-function-reference.md](./docs/src/rules/prefer-function-reference.md)
124
125
 
125
126
  ## Other references
126
127
 
package/dist/index.js CHANGED
@@ -161,7 +161,8 @@
161
161
  "@bigbinary/neeto/props-inside-spread-attributes-should-be-sorted": "error",
162
162
  "@bigbinary/neeto/props-with-different-key-value-should-be-outside-spread-attribute": "error",
163
163
  "@bigbinary/neeto/use-common-constants": "warn",
164
- "@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"
165
166
  };
166
167
 
167
168
  var recommended = {
@@ -562,6 +563,7 @@
562
563
  var NO_LOCAL_STORAGE = "Do not use localStorage directly. Use 'getFromLocalStorage()', 'setToLocalStorage()', 'removeFromLocalStorage()' or 'useLocalStorage()' from neeto-commons-frontend instead.";
563
564
  var NO_TRANSLATION_LOWERCASE = "No need to lowercase i18next translations";
564
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.";
565
567
 
566
568
  var PACKAGES_TO_CHECK = ["@bigbinary/neeto-molecules", "@bigbinary/neetoui", "@bigbinary/neeto-commons-frontend"];
567
569
 
@@ -1313,7 +1315,7 @@
1313
1315
  }
1314
1316
  };
1315
1317
 
1316
- var checkAndReport$6 = function checkAndReport(context, node) {
1318
+ var checkAndReport$7 = function checkAndReport(context, node) {
1317
1319
  if (!isInsideApisDirectory(context)) return;
1318
1320
  context.report({
1319
1321
  node: node,
@@ -1331,11 +1333,11 @@
1331
1333
  create: function create(context) {
1332
1334
  return {
1333
1335
  ExportNamedDeclaration: function ExportNamedDeclaration(node) {
1334
- checkAndReport$6(context, node);
1336
+ checkAndReport$7(context, node);
1335
1337
  },
1336
1338
  ExportDefaultDeclaration: function ExportDefaultDeclaration(node) {
1337
1339
  if (node.declaration.type !== TYPES.OBJECT_EXPRESSION) return;
1338
- checkAndReport$6(context, node);
1340
+ checkAndReport$7(context, node);
1339
1341
  }
1340
1342
  };
1341
1343
  }
@@ -1437,7 +1439,7 @@
1437
1439
  }
1438
1440
  });
1439
1441
  };
1440
- var checkAndReport$5 = function checkAndReport(context, node) {
1442
+ var checkAndReport$6 = function checkAndReport(context, node) {
1441
1443
  if (!node.async) return;
1442
1444
  var subsequentAwaits = getIndependentAwaits(node);
1443
1445
  if (subsequentAwaits.length === 0) return;
@@ -1458,15 +1460,15 @@
1458
1460
  return {
1459
1461
  // const sum = (a, b) => a + b;
1460
1462
  ArrowFunctionExpression: function ArrowFunctionExpression(node) {
1461
- checkAndReport$5(context, node);
1463
+ checkAndReport$6(context, node);
1462
1464
  },
1463
1465
  // const sum = function (a, b) { return a + b };
1464
1466
  FunctionExpression: function FunctionExpression(node) {
1465
- checkAndReport$5(context, node);
1467
+ checkAndReport$6(context, node);
1466
1468
  },
1467
1469
  // function sum (a, b) { return a + b };
1468
1470
  FunctionDeclaration: function FunctionDeclaration(node) {
1469
- checkAndReport$5(context, node);
1471
+ checkAndReport$6(context, node);
1470
1472
  }
1471
1473
  };
1472
1474
  }
@@ -4094,7 +4096,7 @@
4094
4096
  }
4095
4097
  return false;
4096
4098
  };
4097
- var checkAndReport$4 = function checkAndReport(node, context) {
4099
+ var checkAndReport$5 = function checkAndReport(node, context) {
4098
4100
  if (!shouldReport(node, context)) return;
4099
4101
  context.report({
4100
4102
  node: node,
@@ -4112,13 +4114,13 @@
4112
4114
  create: function create(context) {
4113
4115
  return {
4114
4116
  Literal: function Literal(node) {
4115
- checkAndReport$4(node, context);
4117
+ checkAndReport$5(node, context);
4116
4118
  },
4117
4119
  TemplateLiteral: function TemplateLiteral(node) {
4118
- checkAndReport$4(node, context);
4120
+ checkAndReport$5(node, context);
4119
4121
  },
4120
4122
  JSXText: function JSXText(node) {
4121
- checkAndReport$4(node, context);
4123
+ checkAndReport$5(node, context);
4122
4124
  }
4123
4125
  };
4124
4126
  }
@@ -4236,7 +4238,7 @@
4236
4238
  }, ramda.assoc("content", _objectSpread$2(_objectSpread$2({}, parseJsonData(path$2.join(translationsDirPath, changedFileName))), nanosContent[lng])), translationFiles);
4237
4239
  });
4238
4240
  };
4239
- var checkAndReport$3 = function checkAndReport(_ref) {
4241
+ var checkAndReport$4 = function checkAndReport(_ref) {
4240
4242
  var _config$context, _config$count;
4241
4243
  var context = _ref.context,
4242
4244
  node = _ref.node,
@@ -4319,7 +4321,7 @@
4319
4321
  config.count = getObjectPropValue(node.arguments[1], "count");
4320
4322
  config.context = getObjectPropValue(node.arguments[1], "context");
4321
4323
  }
4322
- checkAndReport$3({
4324
+ checkAndReport$4({
4323
4325
  key: node.arguments[0].value,
4324
4326
  context: context,
4325
4327
  node: node,
@@ -4337,7 +4339,7 @@
4337
4339
  count: getCountNode(node),
4338
4340
  context: contextAttribute === null || contextAttribute === void 0 ? void 0 : contextAttribute.value
4339
4341
  };
4340
- checkAndReport$3({
4342
+ checkAndReport$4({
4341
4343
  key: keyNode.value,
4342
4344
  context: context,
4343
4345
  node: node,
@@ -6123,7 +6125,7 @@
6123
6125
  return getCode$1(context, param);
6124
6126
  }).join(", ");
6125
6127
  };
6126
- var checkAndReport$2 = function checkAndReport(context, params) {
6128
+ var checkAndReport$3 = function checkAndReport(context, params) {
6127
6129
  var isApiAction = isInsideApisDirectory(context);
6128
6130
  if (!containsExcessArguments(params, isApiAction)) return;
6129
6131
  var loc = {
@@ -6155,15 +6157,15 @@
6155
6157
  return {
6156
6158
  // const sum = (a, b) => a + b;
6157
6159
  ArrowFunctionExpression: function ArrowFunctionExpression(node) {
6158
- checkAndReport$2(context, node.params);
6160
+ checkAndReport$3(context, node.params);
6159
6161
  },
6160
6162
  // const sum = function (a, b) { return a + b };
6161
6163
  FunctionExpression: function FunctionExpression(node) {
6162
- checkAndReport$2(context, node.params);
6164
+ checkAndReport$3(context, node.params);
6163
6165
  },
6164
6166
  // function sum (a, b) { return a + b };
6165
6167
  FunctionDeclaration: function FunctionDeclaration(node) {
6166
- checkAndReport$2(context, node.params);
6168
+ checkAndReport$3(context, node.params);
6167
6169
  }
6168
6170
  };
6169
6171
  }
@@ -6884,6 +6886,50 @@
6884
6886
  }
6885
6887
  };
6886
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
+
6887
6933
  var NEETO_PACKAGES = ["@bigbinary/neetoui", "@bigbinary/neeto-icons"];
6888
6934
 
6889
6935
  var importedFromNeeto = function importedFromNeeto(context, node) {
@@ -10428,7 +10474,8 @@
10428
10474
  "zustand-use-with-immutable-actions-wrapper-inside-create": useWithImmutableActionsWrapperInsideCreate,
10429
10475
  "add-required-peer-dependencies": addRequiredPeerDependencies,
10430
10476
  "use-common-constants": useCommonConstants,
10431
- "move-spread-attributes-to-top-position": moveSpreadAttributesToTopPosition
10477
+ "move-spread-attributes-to-top-position": moveSpreadAttributesToTopPosition,
10478
+ "prefer-function-reference": preferFunctionReference
10432
10479
  },
10433
10480
  configs: {
10434
10481
  recommended: recommended,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/eslint-plugin-neeto",
3
- "version": "1.1.35",
3
+ "version": "1.1.36",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {