Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-sorting

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-sorting - npm Package Compare versions

Comparing version 1.2.2 to 1.2.3

4

CHANGELOG.md

@@ -5,2 +5,6 @@ # Change Log

## 1.2.3
* Fixed removing last comments in the rule.
* Fixed adding empty lines between children rules if there are comments between them.
## 1.2.2

@@ -7,0 +11,0 @@ * Fixed removing comments in rule if they are only children.

63

index.js

@@ -127,2 +127,19 @@ var postcss = require('postcss');

function addIndexesToNode(node, index, order) {
// Index to place the nodes that shouldn't be sorted
var lastGroupIndex = order['...'] ? order['...'].group : Infinity;
var lastPropertyIndex = order['...'] ? order['...'].prop : Infinity;
var orderProperty = getOrderProperty(node, order);
// If the declaration's property is in order's list, save its
// group and property indexes. Otherwise set them to 10000, so
// declaration appears at the bottom of a sorted list:
node.groupIndex = orderProperty && orderProperty.group > -1 ? orderProperty.group : lastGroupIndex;
node.propertyIndex = orderProperty && orderProperty.prop > -1 ? orderProperty.prop : lastPropertyIndex;
node.initialIndex = index;
return node;
}
function fetchAllCommentsBeforeNode(comments, previousNode, node, currentInitialIndex) {

@@ -167,2 +184,17 @@ if (!previousNode || previousNode.type !== 'comment') {

function getApplicableNode(node) {
// find if there any rules before, and skip the comments
var prevNode = node.prev();
if (prevNode.type === 'rule') {
return node;
}
if (prevNode.type === 'comment') {
return getApplicableNode(prevNode);
}
return false;
}
module.exports = postcss.plugin('postcss-sorting', function (opts) {

@@ -176,6 +208,2 @@ // Verify options and use defaults if not specified

// Index to place the nodes that shouldn't be sorted
var lastGroupIndex = order['...'] ? order['...'].group : Infinity;
var lastPropertyIndex = order['...'] ? order['...'].prop : Infinity;
css.walk(function (rule) {

@@ -191,2 +219,4 @@ // Process only rules and atrules with nodes

if (index === 0 && node.raws.before.indexOf('\n') === -1) {
node.ruleComment = true; // need this flag to not append this comment twice
processed.push(node);

@@ -198,11 +228,4 @@ }

var orderProperty = getOrderProperty(node, order);
node = addIndexesToNode(node, index, order);
// If the declaration's property is in order's list, save its
// group and property indexes. Otherwise set them to 10000, so
// declaration appears at the bottom of a sorted list:
node.groupIndex = orderProperty && orderProperty.group > -1 ? orderProperty.group : lastGroupIndex;
node.propertyIndex = orderProperty && orderProperty.prop > -1 ? orderProperty.prop : lastPropertyIndex;
node.initialIndex = index;
// If comment on separate line before node, use node's indexes for comment

@@ -217,2 +240,9 @@ var commentsBefore = fetchAllCommentsBeforeNode([], node.prev(), node);

// Add last comments in the rule. Need this because last comments are not belonging to anything
rule.each(function (node) {
if (node.type === 'comment' && !node.hasOwnProperty('groupIndex') && !node.ruleComment) {
processed.push(node);
}
});
// Sort declarations saved for sorting:

@@ -252,4 +282,9 @@ processed.sort(function (a, b) {

// Insert empty lines between children classes
if (node.type === 'rule' && prevNode.type === 'rule' && linesBetweenChildrenRules > 0) {
node.raws.before = createLineBreaks(linesBetweenChildrenRules) + node.raws.before;
if (node.type === 'rule' && linesBetweenChildrenRules > 0) {
// between child rules can be comments, so empty lines should be added to first comment between rules, rather than to rule
var applicableNode = getApplicableNode(node);
if (applicableNode) {
applicableNode.raws.before = createLineBreaks(linesBetweenChildrenRules) + applicableNode.raws.before;
}
}

@@ -256,0 +291,0 @@ }

{
"name": "postcss-sorting",
"version": "1.2.2",
"version": "1.2.3",
"description": "PostCSS plugin to sort rules content with specified order.",

@@ -19,2 +19,6 @@ "keywords": [

"homepage": "https://github.com/hudochenkov/postcss-sorting",
"files": [
"configs",
"index.js"
],
"dependencies": {

@@ -24,6 +28,6 @@ "postcss": "^5.0.16"

"devDependencies": {
"ava": "^0.11.0",
"ava": "^0.13.0",
"eslint": "^1.10.2",
"postcss-less": "^0.2.0",
"postcss-scss": "^0.1.5"
"postcss-less": "^0.8.0",
"postcss-scss": "^0.1.7"
},

@@ -30,0 +34,0 @@ "scripts": {

@@ -345,2 +345,8 @@ # PostCSS Sorting [![Build Status][ci-img]][ci]

## Related tools
If you want format stylesheets, use [perfectionist], also a PostCSS-based tool.
Don't forget to lint stylesheets with [stylelint]!
## Thanks

@@ -364,1 +370,3 @@

[Autoprefixer]: https://github.com/postcss/autoprefixer
[perfectionist]: https://github.com/ben-eb/perfectionist
[stylelint]: http://stylelint.io/
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc