Socket
Socket
Sign inDemoInstall

stylelint-order

Package Overview
Dependencies
341
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.1 to 3.1.0

4

CHANGELOG.md

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

## 3.1.0
* Added `emptyLineBefore: "threshold"` option, and related options (`emptyLineMinimumPropertyThreshold`, `emptyLineBeforeUnspecified: "threshold"`) to `properties-order`.
## 3.0.1

@@ -7,0 +11,0 @@

14

package.json
{
"name": "stylelint-order",
"version": "3.0.1",
"version": "3.1.0",
"description": "A collection of order related linting rules for stylelint.",

@@ -31,3 +31,3 @@ "keywords": [

"dependencies": {
"lodash": "^4.17.14",
"lodash": "^4.17.15",
"postcss": "^7.0.17",

@@ -40,8 +40,8 @@ "postcss-sorting": "^5.0.1"

"devDependencies": {
"eslint": "^6.0.1",
"eslint": "^6.2.2",
"eslint-config-hudochenkov": "^3.0.1",
"eslint-config-prettier": "^6.0.0",
"husky": "^3.0.0",
"jest": "^24.8.0",
"lint-staged": "^9.2.0",
"eslint-config-prettier": "^6.1.0",
"husky": "^3.0.4",
"jest": "^24.9.0",
"lint-staged": "^9.2.5",
"prettier": "~1.18.2",

@@ -48,0 +48,0 @@ "stylelint": "^10.1.0"

@@ -56,3 +56,3 @@ # properties-alphabetical-order

}
``
```

@@ -64,3 +64,3 @@ ```css

}
````
```

@@ -67,0 +67,0 @@ ```css

@@ -7,3 +7,8 @@ const stylelint = require('stylelint');

module.exports = function checkEmptyLineBefore(firstPropData, secondPropData, sharedInfo) {
module.exports = function checkEmptyLineBefore(
firstPropData,
secondPropData,
sharedInfo,
propsCount
) {
const firstPropIsUnspecified = !firstPropData.orderData;

@@ -26,2 +31,5 @@ const secondPropIsUnspecified = !secondPropData.orderData;

// Line threshold logic
const belowEmptyLineThreshold = propsCount < sharedInfo.emptyLineMinimumPropertyThreshold;
if (betweenGroupsInSpecified || startOfUnspecifiedGroup) {

@@ -37,3 +45,12 @@ // Get an array of just the property groups, remove any solo properties

if (!hasEmptyLineBefore(secondPropData.node) && emptyLineBefore === 'always') {
// Threshold logic
const emptyLineThresholdInsertLines =
!belowEmptyLineThreshold && emptyLineBefore === 'threshold';
const emptyLineThresholdRemoveLines =
belowEmptyLineThreshold && emptyLineBefore === 'threshold';
if (
!hasEmptyLineBefore(secondPropData.node) &&
(emptyLineBefore === 'always' || emptyLineThresholdInsertLines)
) {
if (sharedInfo.isFixEnabled) {

@@ -49,3 +66,6 @@ addEmptyLineBefore(secondPropData.node, sharedInfo.context.newline);

}
} else if (hasEmptyLineBefore(secondPropData.node) && emptyLineBefore === 'never') {
} else if (
hasEmptyLineBefore(secondPropData.node) &&
(emptyLineBefore === 'never' || emptyLineThresholdRemoveLines)
) {
if (sharedInfo.isFixEnabled) {

@@ -52,0 +72,0 @@ removeEmptyLinesBefore(secondPropData.node, sharedInfo.context.newline);

@@ -13,2 +13,3 @@ const stylelint = require('stylelint');

const allPropData = getAllPropData(node);
const propsCount = node.nodes.filter(item => utils.isProperty(item)).length;

@@ -95,3 +96,3 @@ if (!sharedInfo.isFixEnabled) {

checkEmptyLineBefore(previousNodeData, nodeData, sharedInfo);
checkEmptyLineBefore(previousNodeData, nodeData, sharedInfo, propsCount);
});

@@ -98,0 +99,0 @@

@@ -14,3 +14,3 @@ const stylelint = require('stylelint');

expectedEmptyLineBefore: property => `Expected an empty line before property "${property}"`,
rejectedEmptyLineBefore: property => `Unexpected an empty line before property "${property}"`,
rejectedEmptyLineBefore: property => `Unexpected empty line before property "${property}"`,
});

@@ -31,4 +31,5 @@

unspecified: ['top', 'bottom', 'ignore', 'bottomAlphabetical'],
emptyLineBeforeUnspecified: ['always', 'never'],
emptyLineBeforeUnspecified: ['always', 'never', 'threshold'],
disableFix: _.isBoolean,
emptyLineMinimumPropertyThreshold: _.isNumber,
},

@@ -46,2 +47,7 @@ optional: true,

const emptyLineBeforeUnspecified = _.get(options, 'emptyLineBeforeUnspecified', '');
const emptyLineMinimumPropertyThreshold = _.get(
options,
'emptyLineMinimumPropertyThreshold',
0
);
const disableFix = _.get(options, 'disableFix', false);

@@ -57,2 +63,3 @@ const isFixEnabled = context.fix && !disableFix;

emptyLineBeforeUnspecified,
emptyLineMinimumPropertyThreshold,
messages,

@@ -59,0 +66,0 @@ ruleName,

@@ -21,3 +21,4 @@ # properties-order

* [`unspecified: "top"|"bottom"|"bottomAlphabetical"|"ignore"`](#unspecified-topbottombottomalphabeticalignore)
* [`emptyLineBeforeUnspecified: "always"|"never"`](#emptyLineBeforeUnspecified-alwaysnever)
* [`emptyLineBeforeUnspecified: "always"|"never"|"threshold"`](#emptyLineBeforeUnspecified-alwaysneverthreshold)
* [`emptyLineMinimumPropertyThreshold: <number>`](#emptylineminimumpropertythreshold-number)
* [`disableFix: true`](#disablefix-true)

@@ -38,3 +39,3 @@ * [Autofixing caveats](#autofixing-caveats)

* `properties (array of strings)`: The properties in this group.
* `emptyLineBefore ("always"|"never")`: If `always`, this group must be separated from other properties by an empty newline. If emptyLineBefore is `never`, the group must have no empty lines separating it from other properties. By default this property isn't set. Rule will check empty lines between properties _only_. However, shared-line comments ignored by rule. Shared-line comment is a comment on the same line as declaration before this comment.
* `emptyLineBefore ("always"|"never"|"threshold")`: If `always`, this group must be separated from other properties by an empty newline. If emptyLineBefore is `never`, the group must have no empty lines separating it from other properties. By default this property isn't set. Rule will check empty lines between properties _only_. However, shared-line comments ignored by rule. Shared-line comment is a comment on the same line as declaration before this comment. For `threshold`, refer to the [`emptyLineMinimumPropertyThreshold` documentation](#emptylineminimumpropertythreshold-number).
* `noEmptyLineBetween`: If `true`, properties within group should not have empty lines between them.

@@ -600,8 +601,11 @@ * `groupName`: An optional name for the group. This will be used in error messages.

### `emptyLineBeforeUnspecified: "always"|"never"`
### `emptyLineBeforeUnspecified: "always"|"never"|"threshold"`
Default behavior does not enforce the presence of an empty line before an unspecified block of properties.
If `"always"`, the unspecified group must be separated from other properties by an empty newline. If `"never"`, the unspecified group must have no empty lines separating it from other properties.
If `"always"`, the unspecified group must be separated from other properties by an empty newline.
If `"never"`, the unspecified group must have no empty lines separating it from other properties.
For `"threshold"`, see the [`emptyLineMinimumPropertyThreshold` documentation](#emptylineminimumpropertythreshold-number) for more information.
Given:

@@ -643,2 +647,128 @@

### `emptyLineMinimumPropertyThreshold: <number>`
If a group is configured with `emptyLineBefore: 'threshold'`, the empty line behaviour toggles based on the number of properties in the rule.
When the configured minimum property threshold is reached, empty lines are **inserted**. When the number of properties is **less than** the minimum property threshold, empty lines are **removed**.
_e.g. threshold set to **3**, and there are **5** properties in total, then groups set to `'threshold'` will have an empty line inserted._
The same behaviour is applied to unspecified groups when `emptyLineBeforeUnspecified: "threshold"`
Given:
```js
[
[
{
emptyLineBefore: 'threshold',
properties: ['display'],
},
{
emptyLineBefore: 'threshold',
properties: ['height', 'width'],
},
{
emptyLineBefore: 'always',
properties: ['border'],
},
{
emptyLineBefore: 'never',
properties: ['transform'],
},
],
{
unspecified: 'bottom',
emptyLineBeforeUnspecified: 'threshold',
emptyLineMinimumPropertyThreshold: 4,
}
]
```
The following patterns are considered warnings:
```css
a {
display: block;
height: 1px;
width: 2px;
color: blue;
}
a {
display: block;
height: 1px;
width: 2px;
border: 0;
color: blue;
}
a {
display: block;
height: 1px;
width: 2px;
border: 0;
transform: none;
color: blue;
}
```
The following patterns are *not* considered warnings:
```css
a {
display: block;
height: 1px;
width: 2px;
}
a {
display: block;
height: 1px;
width: 2px;
border: 0;
}
a {
display: block;
height: 1px;
width: 2px;
border: 0;
transform: none;
}
a {
display: block;
height: 1px;
border: 0;
}
a {
border: 0;
transform: none;
color: blue;
}
a {
display: block;
height: 1px;
width: 2px;
border: 0;
transform: none;
color: blue;
}
```
### `disableFix: true`

@@ -650,3 +780,3 @@

Properties will be grouped together, if other node types between them (except comments). They will be groupped with the first found property. E. g.:
Properties will be grouped together, if other node types between them (except comments). They will be grouped with the first found property. E.g.:

@@ -653,0 +783,0 @@ ```css

@@ -45,3 +45,3 @@ const _ = require('lodash');

return _.includes(['always', 'never'], item.emptyLineBefore);
return _.includes(['always', 'never', 'threshold'], item.emptyLineBefore);
})

@@ -48,0 +48,0 @@ ) {

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc