Skip to content

Commit a0c82ed

Browse files
committed
Fix an issue when there is a lot of comments in the end of a rule #24
1 parent 7cebd54 commit a0c82ed

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,12 @@ module.exports = postcss.plugin('postcss-sorting', function (opts) {
251251
});
252252

253253
// Add last comments in the rule. Need this because last comments are not belonging to anything
254-
rule.each(function (node) {
254+
rule.each(function (node, index) {
255255
if (node.type === 'comment' && !node.hasOwnProperty('groupIndex') && !node.ruleComment) {
256+
node.groupIndex = Infinity;
257+
node.propertyIndex = Infinity;
258+
node.initialIndex = index;
259+
256260
processed.push(node);
257261
}
258262
});

test/fixtures/last-comments.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,16 @@ div {
44
/* comment 2 */
55
/* comment 3 */
66
}
7+
.block {
8+
position: absolute;
9+
top: 100%;
10+
right: 50%;
11+
/* foo 1 */
12+
/* foo 2 */
13+
/* foo 3 */
14+
/* foo 4 */
15+
/* foo 5 */
16+
/* foo 6 */
17+
/* foo 7 */
18+
/* foo 8 */
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
div {
22
display: none;
3+
34
/* comment 1 */
45
/* comment 2 */
56
/* comment 3 */
67
}
8+
.block {
9+
position: absolute;
10+
top: 100%;
11+
right: 50%;
12+
13+
/* foo 1 */
14+
/* foo 2 */
15+
/* foo 3 */
16+
/* foo 4 */
17+
/* foo 5 */
18+
/* foo 6 */
19+
/* foo 7 */
20+
/* foo 8 */
21+
}

0 commit comments

Comments
 (0)