@bigbinary/eslint-plugin-neeto 1.0.62 → 1.0.63

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 (2) hide show
  1. package/dist/index.js +133 -26
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -96,7 +96,7 @@
96
96
  "@bigbinary/neeto/routes-should-be-declared-and-default-exported": "error",
97
97
  "@bigbinary/neeto/routes-should-match-object-path": "error",
98
98
  "@bigbinary/neeto/use-array-methods": "warn",
99
- "@bigbinary/neeto/use-axios-config-for-passing-query-parameters": "error",
99
+ "@bigbinary/neeto/use-axios-config-for-passing-query-parameters": "warn",
100
100
  "@bigbinary/neeto/use-camel-case-or-pascal-case-for-function-names": "error",
101
101
  "@bigbinary/neeto/use-common-routes": "error",
102
102
  "@bigbinary/neeto/use-components-children-prop-in-trans": "error",
@@ -167,19 +167,19 @@
167
167
  }
168
168
  }
169
169
 
170
- function _arrayLikeToArray(arr, len) {
170
+ function _arrayLikeToArray$1(arr, len) {
171
171
  if (len == null || len > arr.length) len = arr.length;
172
172
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
173
173
  return arr2;
174
174
  }
175
175
 
176
- function _unsupportedIterableToArray(o, minLen) {
176
+ function _unsupportedIterableToArray$1(o, minLen) {
177
177
  if (!o) return;
178
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
178
+ if (typeof o === "string") return _arrayLikeToArray$1(o, minLen);
179
179
  var n = Object.prototype.toString.call(o).slice(8, -1);
180
180
  if (n === "Object" && o.constructor) n = o.constructor.name;
181
181
  if (n === "Map" || n === "Set") return Array.from(o);
182
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
182
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen);
183
183
  }
184
184
 
185
185
  function _nonIterableRest() {
@@ -187,7 +187,7 @@
187
187
  }
188
188
 
189
189
  function _slicedToArray(arr, i) {
190
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
190
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray$1(arr, i) || _nonIterableRest();
191
191
  }
192
192
 
193
193
  var regeneratorRuntime$1 = {exports: {}};
@@ -1412,7 +1412,7 @@
1412
1412
  };
1413
1413
 
1414
1414
  function _arrayWithoutHoles(arr) {
1415
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
1415
+ if (Array.isArray(arr)) return _arrayLikeToArray$1(arr);
1416
1416
  }
1417
1417
 
1418
1418
  function _iterableToArray(iter) {
@@ -1424,7 +1424,7 @@
1424
1424
  }
1425
1425
 
1426
1426
  function _toConsumableArray(arr) {
1427
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
1427
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray$1(arr) || _nonIterableSpread();
1428
1428
  }
1429
1429
 
1430
1430
  var camelize = function camelize(text) {
@@ -7395,38 +7395,145 @@
7395
7395
  }]
7396
7396
  };
7397
7397
 
7398
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
7399
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
7400
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7401
+ var extractVariableValue = function extractVariableValue(inputValue) {
7402
+ var match = inputValue.match(/\${([^}]+)}/);
7403
+ return match ? match[1] : "\"".concat(inputValue, "\"");
7404
+ };
7405
+ var getUrlSearchParams = function getUrlSearchParams(urlString) {
7406
+ var params = {};
7407
+ var queryString = urlString.split("?")[1].slice(0, -1);
7408
+ if (queryString) {
7409
+ var searchParams = new URLSearchParams(queryString);
7410
+ var _iterator = _createForOfIteratorHelper(searchParams),
7411
+ _step;
7412
+ try {
7413
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
7414
+ var _step$value = _slicedToArray(_step.value, 2),
7415
+ key = _step$value[0],
7416
+ value = _step$value[1];
7417
+ if (ramda.isEmpty(value)) return {};
7418
+ params[key] = extractVariableValue(value);
7419
+ }
7420
+ } catch (err) {
7421
+ _iterator.e(err);
7422
+ } finally {
7423
+ _iterator.f();
7424
+ }
7425
+ }
7426
+ return params;
7427
+ };
7428
+ var getParamsFixString = function getParamsFixString(params, paramsString) {
7429
+ var keys = Object.keys(params);
7430
+ if (keys.length === 1 && keys[0] === params[keys[0]]) {
7431
+ return "params: ".concat(keys[0]);
7432
+ }
7433
+ return "params: { ".concat(paramsString, "}");
7434
+ };
7435
+ var getFixForParamsObjectAlreadyPresent = function getFixForParamsObjectAlreadyPresent(paramsNode, fixer, paramsString) {
7436
+ if (paramsNode.value.type === TYPES.IDENTIFIER) {
7437
+ return fixer.replaceText(paramsNode, "params: { ...".concat(paramsNode.value.name, ", ").concat(paramsString, " }"));
7438
+ }
7439
+ return fixer.insertTextAfter(ramda.last(paramsNode.value.properties), ", ".concat(paramsString));
7440
+ };
7441
+ var getFix = function getFix(_ref) {
7442
+ var urlNode = _ref.urlNode,
7443
+ context = _ref.context,
7444
+ node = _ref.node,
7445
+ fixer = _ref.fixer;
7446
+ var urlString = context.getSourceCode().getText(urlNode);
7447
+ var fixForParams = getFixForParams({
7448
+ urlNode: urlNode,
7449
+ urlString: urlString,
7450
+ node: node,
7451
+ fixer: fixer
7452
+ });
7453
+ if (!fixForParams) return null;
7454
+ return [getFixForUrl(fixer, urlString, urlNode), fixForParams];
7455
+ };
7456
+ var getFixForUrl = function getFixForUrl(fixer, urlString, urlNode) {
7457
+ var urlWithoutSearchParams = urlString.split("?")[0].slice(1);
7458
+ var match = urlWithoutSearchParams.match(/^\${([^}]+)}$/);
7459
+ var urlFixString = "";
7460
+ if (match) {
7461
+ urlFixString = match[1];
7462
+ } else {
7463
+ urlFixString = urlWithoutSearchParams.includes("${") ? "`".concat(urlWithoutSearchParams, "`") : "\"".concat(urlWithoutSearchParams, "\"");
7464
+ }
7465
+ return fixer.replaceText(urlNode, urlFixString);
7466
+ };
7467
+ var getFixForParams = function getFixForParams(_ref2) {
7468
+ var urlNode = _ref2.urlNode,
7469
+ urlString = _ref2.urlString,
7470
+ node = _ref2.node,
7471
+ fixer = _ref2.fixer;
7472
+ var objectNode = pure.findBy({
7473
+ type: TYPES.OBJECT_EXPRESSION
7474
+ }, node.arguments);
7475
+ var objectProperties = objectNode === null || objectNode === void 0 ? void 0 : objectNode.properties;
7476
+ var paramsNode = objectProperties === null || objectProperties === void 0 ? void 0 : objectProperties.find(function (prop) {
7477
+ return prop.key.name === "params";
7478
+ });
7479
+ var params = getUrlSearchParams(urlString);
7480
+ if (ramda.isEmpty(params)) return null;
7481
+ var paramsString = Object.entries(params).map(function (_ref3) {
7482
+ var _ref4 = _slicedToArray(_ref3, 2),
7483
+ key = _ref4[0],
7484
+ value = _ref4[1];
7485
+ return "".concat(key, ": ").concat(value);
7486
+ }).join(", ");
7487
+ if (objectNode) {
7488
+ if (paramsNode) {
7489
+ return getFixForParamsObjectAlreadyPresent(paramsNode, fixer, paramsString);
7490
+ }
7491
+ var positionToInsert = ramda.last(objectProperties);
7492
+ var _fixString = getParamsFixString(params, paramsString);
7493
+ return fixer.insertTextAfter(positionToInsert, ", ".concat(_fixString));
7494
+ }
7495
+ var fixString = getParamsFixString(params, paramsString);
7496
+ return fixer.insertTextAfter(urlNode, ", { ".concat(fixString, "}"));
7497
+ };
7398
7498
  var getPropValue = function getPropValue(configNode, name) {
7399
7499
  var _configNode$propertie;
7400
- return (_configNode$propertie = configNode.properties.find(function (_ref) {
7401
- var key = _ref.key;
7500
+ return (_configNode$propertie = configNode.properties.find(function (_ref5) {
7501
+ var key = _ref5.key;
7402
7502
  return key.name === name;
7403
7503
  })) === null || _configNode$propertie === void 0 ? void 0 : _configNode$propertie.value;
7404
7504
  };
7405
- var checkAndReport = function checkAndReport(_ref2) {
7406
- var context = _ref2.context,
7407
- node = _ref2.node,
7408
- urlNode = _ref2.urlNode;
7409
- var isQuestionMarkPresent = false;
7410
- if (urlNode.type === TYPES.LITERAL) {
7411
- isQuestionMarkPresent = urlNode.value.includes("?");
7412
- } else {
7413
- isQuestionMarkPresent = urlNode.quasis.some(function (_ref3) {
7414
- var value = _ref3.value;
7415
- return value.cooked.includes("?");
7505
+ var checkAndReport = function checkAndReport(_ref6) {
7506
+ var context = _ref6.context,
7507
+ node = _ref6.node,
7508
+ urlNode = _ref6.urlNode;
7509
+ var isQuestionMarkPresent = urlNode.type === TYPES.LITERAL ? urlNode.value.includes("?") : urlNode.quasis.some(function (_ref7) {
7510
+ var value = _ref7.value;
7511
+ return value.cooked.includes("?");
7512
+ });
7513
+ if (isQuestionMarkPresent) {
7514
+ context.report({
7515
+ node: node,
7516
+ message: USE_AXIOS_CONFIG_FOR_PASSING_QUERY_PARAMETERS_MESSAGE,
7517
+ fix: function fix(fixer) {
7518
+ return getFix({
7519
+ urlNode: urlNode,
7520
+ context: context,
7521
+ node: node,
7522
+ fixer: fixer
7523
+ });
7524
+ }
7416
7525
  });
7417
7526
  }
7418
- if (isQuestionMarkPresent) context.report({
7419
- node: node,
7420
- message: USE_AXIOS_CONFIG_FOR_PASSING_QUERY_PARAMETERS_MESSAGE
7421
- });
7422
7527
  };
7528
+
7423
7529
  var useAxiosConfigForPassingQueryParameters = {
7424
7530
  meta: {
7425
7531
  type: "problem",
7426
7532
  docs: {
7427
7533
  url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/use-axios-config-for-passing-query-parameters.md",
7428
7534
  description: "Enforces using the config parameter of axios to send query parameters through axios"
7429
- }
7535
+ },
7536
+ fixable: "code"
7430
7537
  },
7431
7538
  create: function create(context) {
7432
7539
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/eslint-plugin-neeto",
3
- "version": "1.0.62",
3
+ "version": "1.0.63",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {