postcss-sorting
Advanced tools
Comparing version 1.5.0 to 1.6.0
@@ -5,2 +5,8 @@ # Change Log | ||
## 1.6.0 | ||
* Add special comments to disable processing for some part in style sheet | ||
* Support custom properties as $variable #27 | ||
* Fix an issue when there is a lot of comments in the end of a rule #24 | ||
* At-rule parameter now supports parentheses. For example, `@include mwp(1)`. (thanks, @Redknife) #29 | ||
## 1.5.0 | ||
@@ -7,0 +13,0 @@ * Add `empty-lines-before-comment` and `empty-lines-after-comment`, which add empty lines before and after a comment or a group of comments. |
23
index.js
@@ -82,3 +82,3 @@ var postcss = require('postcss'); | ||
// If atRule has a parameter like @mixin name or @include name, sort by this parameter | ||
var atruleParameter = (/^[\w-]+/).exec(node.params); | ||
var atruleParameter = (/^[\w-\(\)]+/).exec(node.params); | ||
@@ -104,3 +104,3 @@ if (atruleParameter && atruleParameter.length) { | ||
case 'decl': | ||
return (/^\$[\w-]+/).test(node.prop) ? '$variable' : node.prop; | ||
return (/^(\$|--)[\w-]+/).test(node.prop) ? '$variable' : node.prop; | ||
@@ -226,4 +226,17 @@ case 'atrule': | ||
var linesAfterComment = opts['empty-lines-after-comment']; | ||
var enableSorting = true; | ||
css.walk(function (rule) { | ||
if (rule.type === 'comment' && rule.parent.type === 'root') { | ||
if (rule.text === 'postcss-sorting: on') { | ||
enableSorting = true; | ||
} else if (rule.text === 'postcss-sorting: off') { | ||
enableSorting = false; | ||
} | ||
} | ||
if (!enableSorting) { | ||
return; | ||
} | ||
// Process only rules and atrules with nodes | ||
@@ -257,4 +270,8 @@ if ((rule.type === 'rule' || rule.type === 'atrule') && rule.nodes && rule.nodes.length) { | ||
// Add last comments in the rule. Need this because last comments are not belonging to anything | ||
rule.each(function (node) { | ||
rule.each(function (node, index) { | ||
if (node.type === 'comment' && !node.hasOwnProperty('groupIndex') && !node.ruleComment) { | ||
node.groupIndex = Infinity; | ||
node.propertyIndex = Infinity; | ||
node.initialIndex = index; | ||
processed.push(node); | ||
@@ -261,0 +278,0 @@ } |
{ | ||
"name": "postcss-sorting", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "PostCSS plugin to sort rules content with specified order.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -35,2 +35,3 @@ # PostCSS Sorting [![Build Status][ci-img]][ci] | ||
* [`empty-lines-after-comment`](#empty-lines-after-comment) | ||
* [Disabling in style sheet](#disabling-in-style-sheet) | ||
* [Migration from CSSComb](#migration-from-csscomb) | ||
@@ -508,2 +509,26 @@ * [Usage](#usage) | ||
### Disabling in style sheet | ||
The plugin can be temporarily turned off by using special comments. | ||
```css | ||
/* postcss-sorting: off */ | ||
.block1 { | ||
width: 50px; | ||
display: inline-block; | ||
} | ||
/* postcss-sorting: on */ | ||
``` | ||
Due to plugin nature only comments in the root of stylesheet will affect plugin processing. In this case comments will be treated like regular comments: | ||
```css | ||
.block5 { | ||
/* postcss-sorting: off */ | ||
width: 20px; | ||
display: inline-block; | ||
/* postcss-sorting: on */ | ||
} | ||
``` | ||
### Migration from CSSComb | ||
@@ -510,0 +535,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56250
1533
624