postcss-sorting
Advanced tools
Comparing version 1.1.0 to 1.2.0
32
index.js
@@ -62,3 +62,24 @@ var postcss = require('postcss'); | ||
function createLineBreaks(lineBreaksCount) { | ||
return new Array(lineBreaksCount + 1).join('\n'); | ||
} | ||
function getLinesBetweenChildrenFromOptions(opts) { | ||
var options = opts || {}; | ||
var lines = options['empty-lines-between-children-rules']; | ||
if (lines === undefined || lines === null) { | ||
return 0; | ||
} | ||
if (typeof lines !== 'number' || isNaN(lines) || !isFinite(lines) || lines < 0 || Math.floor(lines) !== lines) { | ||
throw new Error('Type of "empty-lines-between-children-rules" option must be integer with positive value.'); | ||
} | ||
return lines; | ||
} | ||
module.exports = postcss.plugin('postcss-sorting', function (opts) { | ||
var linesBetweenChildrenRules = getLinesBetweenChildrenFromOptions(opts); | ||
return function (css) { | ||
@@ -200,6 +221,11 @@ var order = getSortOrder(opts); | ||
if (prevNode && node.groupIndex > prevNode.groupIndex) { | ||
if (node.raws.before) { | ||
node.raws.before = '\n' + node.raws.before; | ||
if (prevNode && node.raws.before) { | ||
if (node.groupIndex > prevNode.groupIndex) { | ||
node.raws.before = createLineBreaks(1) + node.raws.before; | ||
} | ||
// Insert empty lines between children classes | ||
if (node.type === 'rule' && prevNode.type === 'rule' && linesBetweenChildrenRules > 0) { | ||
node.raws.before = createLineBreaks(linesBetweenChildrenRules) + node.raws.before; | ||
} | ||
} | ||
@@ -206,0 +232,0 @@ }); |
The MIT License (MIT) | ||
Copyright 2015 Aleks Hudochenkov <aleks@hudochenkov.com> | ||
Copyright 2016 Aleks Hudochenkov <aleks@hudochenkov.com> | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of |
{ | ||
"name": "postcss-sorting", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "PostCSS plugin to sort rules content with specified order.", | ||
@@ -20,6 +20,6 @@ "keywords": [ | ||
"dependencies": { | ||
"postcss": "^5.0.10" | ||
"postcss": "^5.0.14" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.7.0", | ||
"ava": "^0.11.0", | ||
"eslint": "^1.10.2", | ||
@@ -26,0 +26,0 @@ "postcss-scss": "^0.1.3" |
@@ -5,3 +5,3 @@ # PostCSS Sorting [![Build Status][ci-img]][ci] | ||
[Sublime Text plugin] is available also. | ||
Also available as [Sublime Text plugin] and unofficial [Atom plugin]. | ||
@@ -25,7 +25,7 @@ ## Features | ||
Currently there is only one option. | ||
Currently, there are only two options. | ||
### `sort-order` | ||
Set sort order. If no order is set, plugin uses default config. | ||
Set sort order. If no order is set, the plugin uses default config. | ||
@@ -60,3 +60,3 @@ **Note**: Use one of [predefined configs] as an example. | ||
Prefixed properties may not be in sort order. Plugin will look for unprefixed property and if it find one it will use that property order for prefixed property. It would be better not to write prefixed properties in CSS at all and delegate this job to [Autoprefixer]. | ||
Prefixed properties may not be in sort order. Plugin will look for unprefixed property and if it find one it will use that property order for the prefixed property. It would be better not to write prefixed properties in CSS at all and delegate this job to [Autoprefixer]. | ||
@@ -87,3 +87,3 @@ Example: `{ "sort-order": [ "position", "-webkit-box-sizing", "box-sizing", "width" ] }` | ||
Using array of arrays for `sort-order` separate content into groups by empty line. | ||
Using an array of arrays for `sort-order` separate content into groups by an empty line. | ||
@@ -113,6 +113,6 @@ Example: `{ "sort-order": [ [ "margin", "padding" ], [ "border", "background" ] ] }` | ||
Any @at-rule inside other rule can be sorted. There is some keywords: | ||
Any @at-rule inside another rule can be sorted. There is some keywords: | ||
* `@atrule` — any at-rule. | ||
* `@atrulename` — any at-rule with specific name. Ex., `@media` or `@mixin`. | ||
* `@atrulename` — any at-rule with a specific name. Ex., `@media` or `@mixin`. | ||
* `@atrulename parameter` — any at-rule with specific name and parameter. Ex., `@mixin clearfix`. | ||
@@ -218,3 +218,3 @@ | ||
You can override this by using a “leftovers” token: `...` — just place it either in its own group, or near other properties in any other group and CSSComb would place all the properties that were not sorted where the `...` was in `sort-order`. | ||
You can override this by using a “leftovers” token: `...` — just place it either in its own group or near other properties in any other group and CSSComb would place all the properties that were not sorted where the `...` was in `sort-order`. | ||
@@ -248,2 +248,46 @@ So, with this value: | ||
### `empty-lines-between-children-rules` | ||
Set number of empty lines between nested children rules. By default there is no empty lines between '>child' rules. | ||
Acceptable value: `{Number}` of empty lines | ||
Example: `{ "empty-lines-between-children-rules": 1, "sort-order": [ ["..."], [">child"] ] }` | ||
```scss | ||
/* before */ | ||
.block { | ||
position: absolute; | ||
span { | ||
display: inline-block; | ||
} | ||
&__element { | ||
display: none; | ||
} | ||
&:hover { | ||
top: 0; | ||
} | ||
} | ||
/* after */ | ||
.block { | ||
position: absolute; | ||
span { | ||
display: inline-block; | ||
} | ||
&__element { | ||
display: none; | ||
} | ||
&:hover { | ||
top: 0; | ||
} | ||
} | ||
``` | ||
## Usage | ||
@@ -310,3 +354,3 @@ | ||
This plugin is heavily inspired by [CSSComb]. Some code logic, tests and documentation parts are taken from this tool. | ||
This plugin is heavily inspired by [CSSComb]. Some code logic, tests, and documentation parts are taken from this tool. | ||
@@ -318,4 +362,4 @@ [PostCSS]: https://github.com/postcss/postcss | ||
[predefined configs]: https://github.com/hudochenkov/postcss-sorting/tree/master/configs | ||
[predefined config]: https://github.com/hudochenkov/postcss-sorting/tree/master/configs | ||
[Sublime Text plugin]: https://github.com/hudochenkov/sublime-postcss-sorting | ||
[Atom plugin]: https://github.com/lysyi3m/atom-postcss-sorting | ||
@@ -322,0 +366,0 @@ [CSSComb]: https://github.com/csscomb/csscomb.js |
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
56355
10
1417
363
Updatedpostcss@^5.0.14