@bigbinary/eslint-plugin-neeto 1.1.4 → 1.1.5

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 +41 -42
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -121,7 +121,11 @@
121
121
  "@bigbinary/neeto/zustand-use-prop-to-pick-single-item": "error",
122
122
  "@bigbinary/neeto/use-functions-and-hooks-from-neeto-commons-frontend": "warn",
123
123
  "@bigbinary/neeto/no-unnecessary-if-condition": "error",
124
- "@bigbinary/neeto/zustand-use-with-immutable-actions-wrapper-inside-create": "error"
124
+ "@bigbinary/neeto/zustand-use-with-immutable-actions-wrapper-inside-create": "error",
125
+ "@bigbinary/neeto/no-repetition-in-prop-key-value-names": "error",
126
+ "@bigbinary/neeto/merge-spread-attributes": "error",
127
+ "@bigbinary/neeto/props-inside-spread-attributes-should-be-sorted": "error",
128
+ "@bigbinary/neeto/props-with-different-key-value-should-be-outside-spread-attribute": "error"
125
129
  };
126
130
 
127
131
  var recommended = {
@@ -6226,12 +6230,6 @@
6226
6230
  return ((_property$key = property.key) === null || _property$key === void 0 ? void 0 : _property$key.name) !== ((_property$value = property.value) === null || _property$value === void 0 ? void 0 : _property$value.name);
6227
6231
  });
6228
6232
  };
6229
- var isOtherPropsInBetweenJSXAttribute = function isOtherPropsInBetweenJSXAttribute(attributes) {
6230
- return attributes.slice(1, -1).some(pure.matches(OTHER_PROPS));
6231
- };
6232
- var isOtherPropsAtBottomOrBetweenSpreadAttributes = function isOtherPropsAtBottomOrBetweenSpreadAttributes(properties) {
6233
- return properties.slice(1).some(pure.matches(OTHER_PROPS_INSIDE_SPREAD_ATTRIBUTE));
6234
- };
6235
6233
  var getRepeatedKeyValueProps = function getRepeatedKeyValueProps(attributes) {
6236
6234
  return attributes.filter(function (attribute) {
6237
6235
  var _attribute$value, _attribute$value$expr;
@@ -6558,44 +6556,45 @@
6558
6556
  },
6559
6557
  create: function create(context) {
6560
6558
  return {
6561
- JSXOpeningElement: function JSXOpeningElement(node) {
6562
- var existingSpreadAttributesProperties = node.attributes.flatMap(function (item) {
6563
- return pure.matches(SPREAD_ATTRIBUTE_WITH_OBJECT_EXPRESSION, item) ? item.argument.properties : [];
6564
- });
6565
- var nonRepeatedKeyValueProperties = getNonRepeatedKeyValueProperties(existingSpreadAttributesProperties);
6566
- if (ramda.isEmpty(nonRepeatedKeyValueProperties)) return;
6567
- var isNotFixable = isOtherPropsInBetweenJSXAttribute(node.attributes) || isOtherPropsAtBottomOrBetweenSpreadAttributes(existingSpreadAttributesProperties);
6568
- if (isNotFixable) {
6569
- nonRepeatedKeyValueProperties.map(function (errorNode) {
6570
- return context.report({
6571
- node: errorNode,
6572
- message: DIFFERENT_PROPS_MUST_BE_OUTSIDE
6573
- });
6574
- });
6559
+ JSXSpreadAttribute: function JSXSpreadAttribute(node) {
6560
+ if (!pure.matches(SPREAD_ATTRIBUTE_WITH_OBJECT_EXPRESSION, node)) {
6575
6561
  return;
6576
6562
  }
6577
- nonRepeatedKeyValueProperties.map(function (errorNode) {
6578
- return context.report({
6579
- node: errorNode,
6580
- message: DIFFERENT_PROPS_MUST_BE_OUTSIDE,
6581
- fix: function fix(fixer) {
6582
- var fixToRemoveComma = null;
6583
- var fixToRemoveErrorNode = fixer.remove(errorNode);
6584
- var commaTokenBefore = context.getTokenBefore(errorNode);
6585
- var commaTokenAfter = context.getTokenAfter(errorNode);
6586
- if (commaTokenAfter.value === ",") {
6587
- fixToRemoveComma = fixer.remove(commaTokenAfter);
6588
- } else if (commaTokenBefore.value === ",") {
6589
- fixToRemoveComma = fixer.remove(commaTokenBefore);
6590
- } else {
6591
- fixToRemoveErrorNode = fixer.remove(errorNode.parent.parent);
6563
+ var properties = node.argument.properties;
6564
+ var nonRepeatedKeyValueProperties = getNonRepeatedKeyValueProperties(properties);
6565
+ if (ramda.isEmpty(nonRepeatedKeyValueProperties)) return;
6566
+ nonRepeatedKeyValueProperties.forEach(function (property) {
6567
+ var positionToInsert = null;
6568
+ var index = properties.indexOf(property);
6569
+ var nodesBeforeTarget = properties.slice(0, index);
6570
+ var nodesAfterTarget = properties.slice(index + 1);
6571
+ if (!nodesAfterTarget.find(pure.matches(OTHER_PROPS_INSIDE_SPREAD_ATTRIBUTE))) {
6572
+ positionToInsert = "below";
6573
+ } else if (!nodesBeforeTarget.find(pure.matches(OTHER_PROPS_INSIDE_SPREAD_ATTRIBUTE))) {
6574
+ positionToInsert = "above";
6575
+ }
6576
+ if (positionToInsert) {
6577
+ context.report({
6578
+ node: property,
6579
+ message: DIFFERENT_PROPS_MUST_BE_OUTSIDE,
6580
+ fix: function fix(fixer) {
6581
+ var fixToRemoveComma = null;
6582
+ var fixToRemoveErrorNode = fixer.remove(property);
6583
+ var tokenBefore = context.getTokenBefore(property);
6584
+ var tokenAfter = context.getTokenAfter(property);
6585
+ if (tokenAfter.value === ",") {
6586
+ fixToRemoveComma = fixer.remove(tokenAfter);
6587
+ } else if (tokenBefore.value === ",") {
6588
+ fixToRemoveComma = fixer.remove(tokenBefore);
6589
+ } else {
6590
+ fixToRemoveErrorNode = fixer.remove(node);
6591
+ }
6592
+ var indentLevel = context.getSourceCode().getFirstToken(node.parent.attributes[0]).loc.start.column;
6593
+ var fixToAddProperty = positionToInsert === "below" ? fixer.insertTextAfter(node, "\n".concat(" ".repeat(indentLevel)).concat(property.key.name, "={").concat(property.value.name, "}")) : fixer.insertTextBefore(node, "".concat(property.key.name, "={").concat(property.value.name, "}\n").concat(" ".repeat(indentLevel)));
6594
+ return [fixToRemoveComma, fixToRemoveErrorNode, fixToAddProperty].filter(Boolean);
6592
6595
  }
6593
- var indentLevel = context.getSourceCode().getFirstToken(node.attributes[0]).loc.start.column;
6594
- var newAttribute = "\n".concat(" ".repeat(indentLevel)).concat(errorNode.key.name, "={").concat(errorNode.value.name, "}");
6595
- var fixToAddNewAttribute = fixer.insertTextAfter(errorNode.parent.parent, newAttribute);
6596
- return [fixToRemoveComma, fixToRemoveErrorNode, fixToAddNewAttribute].filter(Boolean);
6597
- }
6598
- });
6596
+ });
6597
+ }
6599
6598
  });
6600
6599
  }
6601
6600
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/eslint-plugin-neeto",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {