@bigbinary/eslint-plugin-neeto 1.1.1 → 1.1.2

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 +75 -39
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -262,19 +262,19 @@
262
262
  }
263
263
  }
264
264
 
265
- function _arrayLikeToArray$1(arr, len) {
265
+ function _arrayLikeToArray$2(arr, len) {
266
266
  if (len == null || len > arr.length) len = arr.length;
267
267
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
268
268
  return arr2;
269
269
  }
270
270
 
271
- function _unsupportedIterableToArray$1(o, minLen) {
271
+ function _unsupportedIterableToArray$2(o, minLen) {
272
272
  if (!o) return;
273
- if (typeof o === "string") return _arrayLikeToArray$1(o, minLen);
273
+ if (typeof o === "string") return _arrayLikeToArray$2(o, minLen);
274
274
  var n = Object.prototype.toString.call(o).slice(8, -1);
275
275
  if (n === "Object" && o.constructor) n = o.constructor.name;
276
276
  if (n === "Map" || n === "Set") return Array.from(o);
277
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen);
277
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$2(o, minLen);
278
278
  }
279
279
 
280
280
  function _nonIterableRest() {
@@ -282,7 +282,7 @@
282
282
  }
283
283
 
284
284
  function _slicedToArray(arr, i) {
285
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray$1(arr, i) || _nonIterableRest();
285
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray$2(arr, i) || _nonIterableRest();
286
286
  }
287
287
 
288
288
  var regeneratorRuntime$1 = {exports: {}};
@@ -1512,7 +1512,7 @@
1512
1512
  };
1513
1513
 
1514
1514
  function _arrayWithoutHoles(arr) {
1515
- if (Array.isArray(arr)) return _arrayLikeToArray$1(arr);
1515
+ if (Array.isArray(arr)) return _arrayLikeToArray$2(arr);
1516
1516
  }
1517
1517
 
1518
1518
  function _iterableToArray(iter) {
@@ -1524,7 +1524,7 @@
1524
1524
  }
1525
1525
 
1526
1526
  function _toConsumableArray(arr) {
1527
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray$1(arr) || _nonIterableSpread();
1527
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray$2(arr) || _nonIterableSpread();
1528
1528
  }
1529
1529
 
1530
1530
  var camelize = function camelize(text) {
@@ -6217,6 +6217,9 @@
6217
6217
  }
6218
6218
  };
6219
6219
 
6220
+ function _createForOfIteratorHelper$1(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$1(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; } } }; }
6221
+ function _unsupportedIterableToArray$1(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$1(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$1(o, minLen); }
6222
+ function _arrayLikeToArray$1(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; }
6220
6223
  var getNonRepeatedKeyValueProperties = function getNonRepeatedKeyValueProperties(nodeProperties) {
6221
6224
  return nodeProperties.filter(function (property) {
6222
6225
  var _property$key, _property$value;
@@ -6273,6 +6276,28 @@
6273
6276
  });
6274
6277
  return "{...{".concat(jsxSpreadAttributeArray.join(", "), "}}");
6275
6278
  };
6279
+ var getClosestNode = function getClosestNode(errorNode, nodes) {
6280
+ var areaToSearch = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "before";
6281
+ var closestNode = null;
6282
+ var closestDistance = Infinity;
6283
+ var _iterator = _createForOfIteratorHelper$1(nodes),
6284
+ _step;
6285
+ try {
6286
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
6287
+ var node = _step.value;
6288
+ var distance = errorNode.range[0] - node.range[1];
6289
+ if ((areaToSearch === "before" && distance > 0 || areaToSearch === "after" && distance < 0) && distance < closestDistance) {
6290
+ closestNode = node;
6291
+ closestDistance = distance;
6292
+ }
6293
+ }
6294
+ } catch (err) {
6295
+ _iterator.e(err);
6296
+ } finally {
6297
+ _iterator.f();
6298
+ }
6299
+ return closestNode;
6300
+ };
6276
6301
 
6277
6302
  var mergeSpreadAttributes = {
6278
6303
  meta: {
@@ -6358,40 +6383,51 @@
6358
6383
  create: function create(context) {
6359
6384
  return {
6360
6385
  JSXOpeningElement: function JSXOpeningElement(node) {
6361
- var repeatedKeyValueProps = getRepeatedKeyValueProps(node.attributes);
6362
- if (ramda.isEmpty(repeatedKeyValueProps)) return;
6363
- var existingSpreadAttributes = node.attributes.filter(pure.matches(SPREAD_ATTRIBUTE_WITH_OBJECT_EXPRESSION));
6364
- var existingSpreadAttributesProperties = existingSpreadAttributes.flatMap(function (item) {
6365
- return item.argument.properties;
6366
- });
6367
- if (isOtherPropsInBetweenJSXAttribute(node.attributes) || isOtherPropsAtBottomOrBetweenSpreadAttributes(existingSpreadAttributesProperties)) {
6368
- repeatedKeyValueProps.map(function (errorNode) {
6369
- return context.report({
6370
- node: errorNode,
6371
- message: PROP_KEY_VALUE_DUPLICATE
6372
- });
6373
- });
6374
- return;
6375
- }
6376
- repeatedKeyValueProps.map(function (errorNode) {
6377
- return context.report({
6378
- node: errorNode,
6379
- message: PROP_KEY_VALUE_DUPLICATE,
6380
- fix: function fix(fixer) {
6381
- var fixToAddProperty = null;
6382
- var errorNodeName = errorNode.name.name;
6383
- if (pure.isNotEmpty(existingSpreadAttributes)) {
6384
- var properties = existingSpreadAttributes[0].argument.properties;
6385
- fixToAddProperty = fixer.insertTextAfter(properties[properties.length - 1], ", ".concat(errorNodeName));
6386
- } else {
6387
- var positionToInsert = pure.matches(OTHER_PROPS, node.attributes[0]) ? 1 : 0;
6388
- fixToAddProperty = fixer.insertTextBefore(node.attributes[positionToInsert], "{...{ ".concat(errorNodeName, "}}"));
6386
+ var initialAttributes = node.attributes;
6387
+ if (ramda.isEmpty(getRepeatedKeyValueProps(initialAttributes))) return;
6388
+ var attributes = [];
6389
+ var _loop = function _loop() {
6390
+ var currentAttribute = initialAttributes[i];
6391
+ if (pure.matches(OTHER_PROPS, currentAttribute) || i === initialAttributes.length - 1) {
6392
+ if (!pure.matches(OTHER_PROPS, currentAttribute)) {
6393
+ attributes.push(currentAttribute);
6394
+ }
6395
+ if (pure.isNotEmpty(attributes)) {
6396
+ var repeatedKeyValueProps = getRepeatedKeyValueProps(attributes);
6397
+ if (!ramda.isEmpty(repeatedKeyValueProps)) {
6398
+ var existingSpreadAttributes = attributes.filter(pure.matches(SPREAD_ATTRIBUTE_WITH_OBJECT_EXPRESSION));
6399
+ context.report({
6400
+ node: node,
6401
+ message: PROP_KEY_VALUE_DUPLICATE,
6402
+ fix: function fix(fixer) {
6403
+ return repeatedKeyValueProps.flatMap(function (errorNode) {
6404
+ var fixToAddProperty = null;
6405
+ var errorNodeName = errorNode.name.name;
6406
+ if (pure.isNotEmpty(existingSpreadAttributes)) {
6407
+ var closestSpreadAttribute = getClosestNode(errorNode, existingSpreadAttributes);
6408
+ if (closestSpreadAttribute) {
6409
+ fixToAddProperty = fixer.insertTextAfter(ramda.last(closestSpreadAttribute.argument.properties), ", ".concat(errorNodeName));
6410
+ } else {
6411
+ closestSpreadAttribute = getClosestNode(errorNode, existingSpreadAttributes, "after");
6412
+ fixToAddProperty = fixer.insertTextBefore(closestSpreadAttribute.argument.properties[0], "".concat(errorNodeName, ", "));
6413
+ }
6414
+ } else {
6415
+ fixToAddProperty = fixer.insertTextBefore(attributes[0], "{...{ ".concat(errorNodeName, "}}"));
6416
+ }
6417
+ return [fixToAddProperty, fixer.remove(errorNode)];
6418
+ });
6419
+ }
6420
+ });
6389
6421
  }
6390
- var fixToRemoveErrorNode = fixer.remove(errorNode);
6391
- return [fixToAddProperty, fixToRemoveErrorNode];
6422
+ attributes = [];
6392
6423
  }
6393
- });
6394
- });
6424
+ } else {
6425
+ attributes.push(currentAttribute);
6426
+ }
6427
+ };
6428
+ for (var i = 0; i < initialAttributes.length; i++) {
6429
+ _loop();
6430
+ }
6395
6431
  }
6396
6432
  };
6397
6433
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/eslint-plugin-neeto",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {