@bigbinary/eslint-plugin-neeto 1.1.20 → 1.1.21
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 +1 -0
- package/dist/index.js +49 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -113,6 +113,7 @@ module.exports = {
|
|
|
113
113
|
- [use-functions-and-hooks-from-neeto-commons-frontend.md](./docs/src/rules/use-functions-and-hooks-from-neeto-commons-frontend.md)
|
|
114
114
|
- [zustand-use-with-immutable-actions-wrapper-inside-create](./docs/src/rules/zustand-use-with-immutable-actions-wrapper-inside-create.md)
|
|
115
115
|
- [add-required-peer-dependencies](./docs/src/rules/add-required-peer-dependencies.md)
|
|
116
|
+
- [move-spread-attributes-to-top-position](./docs/src/rules/move-spread-attributes-to-top-position.md)
|
|
116
117
|
|
|
117
118
|
## Other references
|
|
118
119
|
|
package/dist/index.js
CHANGED
|
@@ -151,7 +151,8 @@
|
|
|
151
151
|
"@bigbinary/neeto/merge-spread-attributes": "error",
|
|
152
152
|
"@bigbinary/neeto/props-inside-spread-attributes-should-be-sorted": "error",
|
|
153
153
|
"@bigbinary/neeto/props-with-different-key-value-should-be-outside-spread-attribute": "error",
|
|
154
|
-
"@bigbinary/neeto/use-common-constants": "warn"
|
|
154
|
+
"@bigbinary/neeto/use-common-constants": "warn",
|
|
155
|
+
"@bigbinary/neeto/move-spread-attributes-to-top-position": "error"
|
|
155
156
|
};
|
|
156
157
|
|
|
157
158
|
var recommended = {
|
|
@@ -547,6 +548,7 @@
|
|
|
547
548
|
var USE_WITH_T_HOC_IN_DUMB_COMPONENTS = 'Use "withT" HOC from "neeto-commons-frontend" instead of useTranslation hook in Dumb components';
|
|
548
549
|
var NO_WITH_T_IN_SMART_COMPONENTS = '"withT" HOC should only be used in dumb components. "useTranslation" hook should be used here.';
|
|
549
550
|
var USE_STANDARD_DATE_TIME_FORMATS = 'Use "dateFormat/timeFormat" from "@bigbinary/neeto-commons-frontend/utils" instead. Refer: https://github.com/bigbinary/neeto-commons-frontend/blob/main/docs/utils/README.md#dateformattimeformat';
|
|
551
|
+
var MOVE_SPREAD_ATTRIBUTES_TO_TOP = "Move spread attribute to top";
|
|
550
552
|
|
|
551
553
|
var PACKAGES_TO_CHECK = ["@bigbinary/neeto-molecules", "@bigbinary/neetoui", "@bigbinary/neeto-commons-frontend"];
|
|
552
554
|
|
|
@@ -6879,6 +6881,13 @@
|
|
|
6879
6881
|
array.splice(index, 1);
|
|
6880
6882
|
}
|
|
6881
6883
|
};
|
|
6884
|
+
var findIndexToInsert = function findIndexToInsert(endIndex, attributes) {
|
|
6885
|
+
var index = endIndex - 1;
|
|
6886
|
+
for (; index >= 0; --index) {
|
|
6887
|
+
if (attributes[index].type === TYPES.JSX_SPREAD_ATTRIBUTE) return index + 1;
|
|
6888
|
+
}
|
|
6889
|
+
return index + 1;
|
|
6890
|
+
};
|
|
6882
6891
|
|
|
6883
6892
|
var mergeSpreadAttributes = {
|
|
6884
6893
|
meta: {
|
|
@@ -7004,6 +7013,43 @@
|
|
|
7004
7013
|
}
|
|
7005
7014
|
};
|
|
7006
7015
|
|
|
7016
|
+
var moveSpreadAttributesToTopPosition = {
|
|
7017
|
+
meta: {
|
|
7018
|
+
type: "problem",
|
|
7019
|
+
docs: {
|
|
7020
|
+
url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/move-spread-attributes-to-top-position.md",
|
|
7021
|
+
description: "Enforce moving spread attributes to top most position in oprning elements"
|
|
7022
|
+
},
|
|
7023
|
+
fixable: "code"
|
|
7024
|
+
},
|
|
7025
|
+
create: function create(context) {
|
|
7026
|
+
return {
|
|
7027
|
+
JSXSpreadAttribute: function JSXSpreadAttribute(node) {
|
|
7028
|
+
var _node$argument$proper;
|
|
7029
|
+
if (!pure.matches(SPREAD_ATTRIBUTE_WITH_OBJECT_EXPRESSION, node) || (_node$argument$proper = node.argument.properties) !== null && _node$argument$proper !== void 0 && _node$argument$proper.find(pure.matches(OTHER_PROPS_INSIDE_SPREAD_ATTRIBUTE))) {
|
|
7030
|
+
return;
|
|
7031
|
+
}
|
|
7032
|
+
var attributes = node.parent.attributes;
|
|
7033
|
+
var nodeIndex = pure.findIndexBy({
|
|
7034
|
+
range: node.range
|
|
7035
|
+
}, attributes);
|
|
7036
|
+
var indexToInsert = findIndexToInsert(nodeIndex, attributes);
|
|
7037
|
+
if (indexToInsert === nodeIndex) return;
|
|
7038
|
+
var indentLevel = context.getSourceCode().getFirstToken(attributes[0]).loc.start.column;
|
|
7039
|
+
context.report({
|
|
7040
|
+
node: node,
|
|
7041
|
+
message: MOVE_SPREAD_ATTRIBUTES_TO_TOP,
|
|
7042
|
+
fix: function fix(fixer) {
|
|
7043
|
+
var removeNode = fixer.remove(node);
|
|
7044
|
+
var moveNode = fixer.insertTextBefore(attributes[indexToInsert], "".concat(context.getSourceCode().getText(node), "\n").concat(" ".repeat(indentLevel)));
|
|
7045
|
+
return [moveNode, removeNode];
|
|
7046
|
+
}
|
|
7047
|
+
});
|
|
7048
|
+
}
|
|
7049
|
+
};
|
|
7050
|
+
}
|
|
7051
|
+
};
|
|
7052
|
+
|
|
7007
7053
|
var noRepetitionInPropKeyAndValueName = {
|
|
7008
7054
|
meta: {
|
|
7009
7055
|
type: "problem",
|
|
@@ -26901,7 +26947,8 @@
|
|
|
26901
26947
|
"no-unnecessary-if-condition": noUnnecessaryIfCondition,
|
|
26902
26948
|
"zustand-use-with-immutable-actions-wrapper-inside-create": useWithImmutableActionsWrapperInsideCreate,
|
|
26903
26949
|
"add-required-peer-dependencies": addRequiredPeerDependencies,
|
|
26904
|
-
"use-common-constants": useCommonConstants
|
|
26950
|
+
"use-common-constants": useCommonConstants,
|
|
26951
|
+
"move-spread-attributes-to-top-position": moveSpreadAttributesToTopPosition
|
|
26905
26952
|
},
|
|
26906
26953
|
configs: {
|
|
26907
26954
|
recommended: recommended,
|