eslint-plugin-tailwind-variants 2.0.1 → 2.0.3
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.
|
@@ -19,6 +19,12 @@ export const MESSAGE_IDS = {
|
|
|
19
19
|
patternTooLong: "patternTooLong",
|
|
20
20
|
unsortedCustomProperties: "unsortedCustomProperties",
|
|
21
21
|
};
|
|
22
|
+
function isNodeWithOffset(node) {
|
|
23
|
+
return (node.loc != null &&
|
|
24
|
+
typeof node.loc.start.offset ===
|
|
25
|
+
"number" &&
|
|
26
|
+
typeof node.loc.end.offset === "number");
|
|
27
|
+
}
|
|
22
28
|
export const rule = createRule({
|
|
23
29
|
name: "sort-custom-properties",
|
|
24
30
|
meta: {
|
|
@@ -138,21 +144,33 @@ export const rule = createRule({
|
|
|
138
144
|
}
|
|
139
145
|
return a.property.localeCompare(b.property);
|
|
140
146
|
});
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
147
|
+
const allNodesHaveOffsets = sorted.every((item) => isNodeWithOffset(item.node));
|
|
148
|
+
if (!allNodesHaveOffsets)
|
|
149
|
+
return null;
|
|
150
|
+
const getFullDeclaration = (node) => {
|
|
151
|
+
const lineStartIndex = sourceCode.getIndexFromLoc({
|
|
152
|
+
column: 1,
|
|
153
|
+
line: node.loc.start.line,
|
|
154
|
+
});
|
|
155
|
+
const endIndex = node.loc.end.offset + 1; // Include semicolon
|
|
156
|
+
return sourceCode.text.slice(lineStartIndex, endIndex);
|
|
145
157
|
};
|
|
146
158
|
const fixes = currentBlockProperties.map((prop, index) => {
|
|
147
159
|
const sortedNode = sorted[index].node;
|
|
148
|
-
const
|
|
160
|
+
const sortedDeclaration = getFullDeclaration(sortedNode);
|
|
161
|
+
// Column is 1-based in ESLint loc
|
|
149
162
|
const currentLineStart = sourceCode.getIndexFromLoc({
|
|
150
163
|
column: 1,
|
|
151
164
|
line: prop.node.loc.start.line,
|
|
152
165
|
});
|
|
166
|
+
let endLine = prop.node.loc.end.line + 1;
|
|
167
|
+
const nextProp = currentBlockProperties[index + 1];
|
|
168
|
+
if (nextProp) {
|
|
169
|
+
endLine = nextProp.node.loc.start.line;
|
|
170
|
+
}
|
|
153
171
|
const currentLineEnd = sourceCode.getIndexFromLoc({
|
|
154
172
|
column: 1,
|
|
155
|
-
line:
|
|
173
|
+
line: endLine,
|
|
156
174
|
});
|
|
157
175
|
let replacement = "";
|
|
158
176
|
if (emptyLineBetweenGroups && index > 0) {
|
|
@@ -162,7 +180,7 @@ export const rule = createRule({
|
|
|
162
180
|
replacement = "\n";
|
|
163
181
|
}
|
|
164
182
|
}
|
|
165
|
-
replacement +=
|
|
183
|
+
replacement += sortedDeclaration + "\n";
|
|
166
184
|
return fixer.replaceTextRange([currentLineStart, currentLineEnd], replacement);
|
|
167
185
|
});
|
|
168
186
|
return fixes;
|