Socket
Socket
Sign inDemoInstall

stylelint

Package Overview
Dependencies
Maintainers
3
Versions
238
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stylelint - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

dist/rules/function-linear-gradient-no-nonstandard-direction/index.js

17

CHANGELOG.md

@@ -1,10 +0,19 @@

* 1.1.0
# 1.2.0
* Added: `function-linear-gradient-no-nonstandard-direction` rule.
* Added: `rule-properties-order` now by default ignores the order of properties left out of your specified array; and the options `"top"`, `"bottom"`, and `"ignore"` are provided to change that behavior.
* Added: `rule-properties-order` now looks for roots of hyphenated properties in custom arrays so each extension (e.g. `padding-top` as an extension of `padding`) does not need to be specified individually.
* Added: `"always-single-line"` option to `declaration-colon-space-after`.
* Added: support for declarations directly on root (e.g. Sass variable declarations).
* Fixed: `declaration-colon-newline-after` `"always-multi-line"` warning message.
# 1.1.0
* Added: `declaration-colon-newline-after` rule.
* Fixed: bug preventing various rules from registering the correct rule names in their warnings, and therefore also preventing them from being disabled with comments.
* Added: the `indentation` rule now checks indentation of multi-line at-rule params, unless there's the `except` option of `param`.
* Fixed: the `color-no-invalid-hex` rule no longer flags hashes in `url()` arguments.
* Added: support for end-of-line comments in `selector-list-comma-newline-after`.
* Added: protection against `#${sass-interpolation}` in rules checking for hex colors.
* Added: support for strings (translated to RegExps) in `custom-property-pattern` and `custom-media-pattern`.
* Fixed: bug preventing various rules from registering the correct rule names in their warnings, and therefore also preventing them from being disabled with comments.
* Fixed: the `color-no-invalid-hex` rule no longer flags hashes in `url()` arguments.
* Fixed: rules using `node.raw()` instead of `node.raws` to avoid expected errors.

@@ -58,5 +67,5 @@

* Removed: `jsesc` devDependency.
* Added: `rule-no-shorthand-property-overrides` rule.
* Added: `ruleTester` to `stylelint.utils` for use by authors of custom rules.
* Removed: `jsesc` devDependency.

@@ -63,0 +72,0 @@ # 0.3.2

@@ -21,6 +21,2 @@ "use strict";

var _rcLoader = require("rc-loader");
var _rcLoader2 = _interopRequireDefault(_rcLoader);
var _stream = require("stream");

@@ -38,7 +34,2 @@

var stylelintConfig = config || (0, _rcLoader2["default"])("stylelint");
if (!stylelintConfig) {
throw new Error("No stylelint config found");
}
var linter = new _stream.Transform({ objectMode: true });

@@ -70,3 +61,3 @@

}
(0, _postcss2["default"])().use((0, _plugin2["default"])(stylelintConfig)).process(css, processOptions).then(function (result) {
(0, _postcss2["default"])().use((0, _plugin2["default"])(config)).process(css, processOptions).then(function (result) {
callback(null, result);

@@ -73,0 +64,0 @@ })["catch"](function (err) {

@@ -18,2 +18,5 @@ "use strict";

return "Unexpected whitespace after \":\"";
},
expectedAfterMultiLine: function expectedAfterMultiLine() {
return "Unexpected whitespace after \":\" with a multi-line value";
}

@@ -20,0 +23,0 @@ });

@@ -19,2 +19,5 @@ "use strict";

return "Unexpected whitespace after \":\"";
},
expectedAfterSingleLine: function expectedAfterSingleLine() {
return "Expected single space after \":\" with a single-line value";
}

@@ -30,3 +33,3 @@ });

actual: expectation,
possible: ["always", "never"]
possible: ["always", "never", "always-single-line"]
});

@@ -59,19 +62,19 @@ if (!validOptions) {

}
check(declString, i, decl);
locationChecker({
source: declString,
index: i,
lineCheckStr: decl.value,
err: function err(m) {
(0, _utils.report)({
message: m,
node: decl,
index: decl.prop.toString().length + 1,
result: result,
ruleName: checkedRuleName
});
}
});
break;
}
});
function check(source, index, node) {
locationChecker({ source: source, index: index, err: function err(m) {
return (0, _utils.report)({
message: m,
node: node,
index: node.prop.toString().length + 1,
result: result,
ruleName: checkedRuleName
});
}
});
}
}

@@ -55,2 +55,3 @@ "use strict";

except: ["block", "value", "param"],
ignore: ["value", "param"],
hierarchicalSelectors: [_lodash.isBoolean]

@@ -179,7 +180,10 @@ },

function checkValue(decl, declLevel) {
var declString = decl.toString();
if (decl.value.indexOf("\n") === -1) {
return;
}
if ((0, _utils.optionsHaveIgnored)(options, "value")) {
return;
}
var declString = decl.toString();
var valueLevel = (0, _utils.optionsHaveException)(options, "value") ? declLevel : declLevel + 1;

@@ -231,2 +235,6 @@

function checkAtRuleParams(atRule, ruleLevel) {
if ((0, _utils.optionsHaveIgnored)(options, "param")) {
return;
}
var paramLevel = (0, _utils.optionsHaveException)(options, "param") ? ruleLevel : ruleLevel + 1;

@@ -233,0 +241,0 @@

@@ -137,2 +137,6 @@ "use strict";

var _functionLinearGradientNoNonstandardDirection = require("./function-linear-gradient-no-nonstandard-direction");
var _functionLinearGradientNoNonstandardDirection2 = _interopRequireDefault(_functionLinearGradientNoNonstandardDirection);
var _functionParenthesesSpaceInside = require("./function-parentheses-space-inside");

@@ -387,2 +391,3 @@

"function-comma-space-before": _functionCommaSpaceBefore2["default"],
"function-linear-gradient-no-nonstandard-direction": _functionLinearGradientNoNonstandardDirection2["default"],
"function-parentheses-space-inside": _functionParenthesesSpaceInside2["default"],

@@ -389,0 +394,0 @@ "function-space-after": _functionSpaceAfter2["default"],

@@ -24,3 +24,3 @@ "use strict";

exports["default"] = function (expectation) {
exports["default"] = function (expectation, options) {
return function (root, result) {

@@ -30,2 +30,8 @@ var validOptions = (0, _utils.validateOptions)(result, ruleName, {

possible: ["alphabetical", _lodash.isString]
}, {
actual: options,
possible: {
unspecified: ["top", "bottom", "ignore"]
},
optional: true
});

@@ -44,5 +50,6 @@ if (!validOptions) {

function checkInNode(node) {
// By default, ignore unspecified properties altogether
var unspecified = options && options.unspecified ? options.unspecified : "ignore";
var previousProp = {};
var isFirstDecl = true;
var previousProp = undefined;

@@ -65,4 +72,3 @@ node.each(function (child) {

// Skip first decl
if (isFirstDecl) {
isFirstDecl = false;
if (!previousProp) {
previousProp = prop;

@@ -78,5 +84,4 @@ return;

// Different unprefixed property names
// Different unprefixed property names ...
if (prop.unprefixedName !== previousProp.unprefixedName) {
// Alphabetical

@@ -94,2 +99,14 @@ if (expectation === "alphabetical" && prop.unprefixedName >= previousProp.unprefixedName) {

// If either this or prev prop was not found but they have a hyphen
// (e.g. `padding-top`), try looking for the segment preceding the hyphen
// and use that index
if (propIndex === -1 && prop.unprefixedName.indexOf("-") !== -1) {
var propPreHyphen = prop.unprefixedName.slice(0, prop.unprefixedName.indexOf("-"));
propIndex = expectation.indexOf(propPreHyphen);
}
if (previousPropIndex === -1 && previousProp.unprefixedName.indexOf("-") !== -1) {
var previousPropPreHyphen = previousProp.unprefixedName.slice(0, previousProp.unprefixedName.indexOf("-"));
previousPropIndex = expectation.indexOf(previousPropPreHyphen);
}
// Check that two known properties are in order

@@ -101,6 +118,45 @@ if (propIndex !== -1 && previousPropIndex !== -1 && propIndex >= previousPropIndex) {

// Skip over unknown properties as any subsequent known properties will flag
if (propIndex === -1) {
previousProp = prop;
return;
// If this or the previous property was not found in the array ...
if (previousPropIndex === -1 || propIndex === -1) {
// If neither were found, let it be
if (previousPropIndex === -1 && propIndex === -1) {
return;
}
// If we are meant to ignore unspecified properties, let it be
if (unspecified === "ignore") {
return;
}
// If unspecified properties should be at the top,
// then the not-found-propery must be the previous one
if (unspecified === "top") {
if (previousPropIndex === -1) {
return;
}
(0, _utils.report)({
message: messages.expected(prop.name, previousProp.name),
node: child,
result: result,
ruleName: ruleName
});
previousProp = prop;
return;
}
// If unspecified properties should be at the top,
// then the not-found-propery must be this one (not the previous one)
if (unspecified === "bottom") {
if (propIndex === -1) {
return;
}
(0, _utils.report)({
message: messages.expected(previousProp.name, prop.name),
node: child,
result: result,
ruleName: ruleName
});
previousProp = prop;
return;
}
}

@@ -107,0 +163,0 @@ }

@@ -24,7 +24,7 @@ /**

var result = "";
if (statement.type !== "rule" && statement.type !== "atrule") {
return;
return result;
}
var result = "";
if (!noBefore) {

@@ -31,0 +31,0 @@ result += statement.raw("before");

{
"name": "stylelint",
"version": "1.1.0",
"version": "1.2.0",
"description": "Modern CSS linter",

@@ -5,0 +5,0 @@ "keywords": [

@@ -13,2 +13,3 @@ import {

rejectedAfter: () => `Unexpected whitespace after ":"`,
expectedAfterMultiLine: () => `Unexpected whitespace after ":" with a multi-line value`,
})

@@ -15,0 +16,0 @@

@@ -13,2 +13,3 @@ import {

rejectedAfter: () => `Unexpected whitespace after ":"`,
expectedAfterSingleLine: () => `Expected single space after ":" with a single-line value`,
})

@@ -24,2 +25,3 @@

"never",
"always-single-line",
],

@@ -44,18 +46,19 @@ })

if (declString[i] !== ":") { continue }
check(declString, i, decl)
locationChecker({
source: declString,
index: i,
lineCheckStr: decl.value,
err: m => {
report({
message: m,
node: decl,
index: decl.prop.toString().length + 1,
result,
ruleName: checkedRuleName,
})
},
})
break
}
})
function check(source, index, node) {
locationChecker({ source, index, err: m =>
report({
message: m,
node,
index: node.prop.toString().length + 1,
result,
ruleName: checkedRuleName,
}),
})
}
}

@@ -62,1 +62,30 @@ # declaration-colon-space-after

```
### `"always-single-line"`
There *must always* be a single space after the colon *if the declaration's value is single-line*.
The following patterns are considered warnings:
```css
a {
box-shadow: 0 0 0 1px #5b9dd9, 0 0 2px 1px rgba(30, 140, 190, 0.8);
}
```
The following patterns are *not* considered warnings:
```css
a {
box-shadow:
0 0 0 1px #5b9dd9,
0 0 2px 1px rgba(30, 140, 190, 0.8);
}
```
```css
a {
box-shadow:0 0 0 1px #5b9dd9,
0 0 2px 1px rgba(30, 140, 190, 0.8);
}
```
import { repeat, isNumber, isBoolean } from "lodash"
import {
optionsHaveException,
optionsHaveIgnored,
report,

@@ -51,2 +52,3 @@ ruleMessages,

except: [ "block", "value", "param" ],
ignore: [ "value", "param" ],
hierarchicalSelectors: [isBoolean],

@@ -180,5 +182,6 @@ },

function checkValue(decl, declLevel) {
const declString = decl.toString()
if (decl.value.indexOf("\n") === -1) { return }
if (optionsHaveIgnored(options, "value")) { return }
const declString = decl.toString()
const valueLevel = (optionsHaveException(options, "value"))

@@ -232,2 +235,4 @@ ? declLevel

function checkAtRuleParams(atRule, ruleLevel) {
if (optionsHaveIgnored(options, "param")) { return }
const paramLevel = (optionsHaveException(options, "param"))

@@ -234,0 +239,0 @@ ? ruleLevel

@@ -123,3 +123,2 @@ # indentation

```css
```css
@media print,

@@ -148,2 +147,34 @@ (-webkit-min-device-pixel-ratio: 1.25),

### `ignore: ["value"]`
Ignore the indentation of values.
For example, with `2`:
The following patterns are *not* considered warnings:
```css
a {
background-position: top left,
top right,
bottom left,
bottom right;
}
```
### `ignore: ["param"]`
Ignore the indentation of at-rule params.
For example, with `2`:
The following patterns are *not* considered warnings:
```css
@media print,
(-webkit-min-device-pixel-ratio: 1.25),
(min-resolution: 120dpi) {
}
```
### `hierarchicalSelectors: true|false`

@@ -150,0 +181,0 @@

@@ -33,2 +33,3 @@ import atRuleEmptyLineBefore from "./at-rule-empty-line-before"

import functionCommaSpaceBefore from "./function-comma-space-before"
import functionLinearGradientNoNonstandardDirection from "./function-linear-gradient-no-nonstandard-direction"
import functionParenthesesSpaceInside from "./function-parentheses-space-inside"

@@ -122,2 +123,3 @@ import functionSpaceAfter from "./function-space-after"

"function-comma-space-before": functionCommaSpaceBefore,
"function-linear-gradient-no-nonstandard-direction": functionLinearGradientNoNonstandardDirection,
"function-parentheses-space-inside": functionParenthesesSpaceInside,

@@ -124,0 +126,0 @@ "function-space-after": functionSpaceAfter,

@@ -15,3 +15,3 @@ import { isString } from "lodash"

export default function (expectation) {
export default function (expectation, options) {
return (root, result) => {

@@ -24,2 +24,8 @@ const validOptions = validateOptions(result, ruleName, {

],
}, {
actual: options,
possible: {
unspecified: [ "top", "bottom", "ignore" ],
},
optional: true,
})

@@ -36,5 +42,6 @@ if (!validOptions) { return }

function checkInNode(node) {
// By default, ignore unspecified properties altogether
const unspecified = (options && options.unspecified) ? options.unspecified : "ignore"
let previousProp = {}
let isFirstDecl = true
let previousProp

@@ -55,4 +62,3 @@ node.each(child => {

// Skip first decl
if (isFirstDecl) {
isFirstDecl = false
if (!previousProp) {
previousProp = prop

@@ -69,5 +75,4 @@ return

// Different unprefixed property names
// Different unprefixed property names ...
if (prop.unprefixedName !== previousProp.unprefixedName) {
// Alphabetical

@@ -83,5 +88,17 @@ if (expectation === "alphabetical"

const propIndex = expectation.indexOf(prop.unprefixedName)
const previousPropIndex = expectation.indexOf(previousProp.unprefixedName)
let propIndex = expectation.indexOf(prop.unprefixedName)
let previousPropIndex = expectation.indexOf(previousProp.unprefixedName)
// If either this or prev prop was not found but they have a hyphen
// (e.g. `padding-top`), try looking for the segment preceding the hyphen
// and use that index
if (propIndex === -1 && prop.unprefixedName.indexOf("-") !== -1) {
const propPreHyphen = prop.unprefixedName.slice(0, prop.unprefixedName.indexOf("-"))
propIndex = expectation.indexOf(propPreHyphen)
}
if (previousPropIndex === -1 && previousProp.unprefixedName.indexOf("-") !== -1) {
const previousPropPreHyphen = previousProp.unprefixedName.slice(0, previousProp.unprefixedName.indexOf("-"))
previousPropIndex = expectation.indexOf(previousPropPreHyphen)
}
// Check that two known properties are in order

@@ -94,6 +111,37 @@ if (propIndex !== -1 && previousPropIndex !== -1

// Skip over unknown properties as any subsequent known properties will flag
if (propIndex === -1) {
previousProp = prop
return
// If this or the previous property was not found in the array ...
if (previousPropIndex === -1 || propIndex === -1) {
// If neither were found, let it be
if (previousPropIndex === -1 && propIndex === -1) { return }
// If we are meant to ignore unspecified properties, let it be
if (unspecified === "ignore") { return }
// If unspecified properties should be at the top,
// then the not-found-propery must be the previous one
if (unspecified === "top") {
if (previousPropIndex === -1) { return }
report({
message: messages.expected(prop.name, previousProp.name),
node: child,
result,
ruleName,
})
previousProp = prop
return
}
// If unspecified properties should be at the top,
// then the not-found-propery must be this one (not the previous one)
if (unspecified === "bottom") {
if (propIndex === -1) { return }
report({
message: messages.expected(previousProp.name, prop.name),
node: child,
result,
ruleName,
})
previousProp = prop
return
}
}

@@ -100,0 +148,0 @@ }

@@ -62,2 +62,26 @@ # rule-properties-order

There are some important details to keep in mind:
**By default, unlisted properties will be ignored.** So if you specify an array
and do not include `display`, that means that the `display` property can be
included before or after any other property. *This can be changed with the
`unspecified` option* (see below).
**If an (unprefixed) property name is not included in your array
and it contains a hyphen (e.g. `padding-left`), the rule will look for the string
before that first hyphen in your array (e.g. `padding`) and use that
position.** This means that you do not have to specify each extension of the root property;
you can just specify the root property and the extensions will be accounted for.
For example, if you have included `border` in your array but not
`border-top`, the rule will expect `border-top` to appear in the same relative
position as `border`.
Other relevant rules include `margin`, `border`, `animation`, `transition`, etc.
Using this fallback, the order of these hyphenated relative to their peer extensions
(e.g. `border-top` to `border-bottom`) will be *arbitrary*. If you would like to
enforce a specific ordering (e.g. always put `border-right` before `border-left`), you
should specify those particular names in your array.
Given:

@@ -102,1 +126,217 @@

```
Given:
```js
["padding", "color"]
```
The following patterns are considered warnings:
```css
a {
color: pink;
padding: 1em;
}
```
```css
a {
color: pink;
padding-top: 1em;
}
```
```css
a {
padding-left: 2em;
color: pink;
padding-top: 1em;
}
```
The following patterns are *not* considered warnings:
```css
a {
padding: 1em;
color: pink;
}
```
```css
a {
padding-top: 1em;
color: pink;
}
```
```css
a {
padding-left: 2em;
padding-top: 1em;
color: pink;
}
```
```css
a {
padding-top: 1em;
padding-left: 2em;
color: pink;
}
```
Given:
```js
["padding", "padding-top", "padding-right", "padding-bottom", "padding-left", "color"]
```
The following patterns are considered warnings:
```css
a {
padding-left: 2em;
padding-top: 1em;
padding: 1em;
color: pink;
}
```
The following patterns are *not* considered warnings:
```css
a {
padding-top: 1em;
padding-right: 1em;
padding-bottom: 0.5em;
padding-left: 0.5em;
color: pink;
}
```
```css
a {
padding: 1em;
padding-right: 2em;
padding-left: 2.5em;
color: pink;
}
```
## Optional options
### `unspecified: "top"|"bottom"|"ignore"`
These options only apply if you've defined your own array of properties.
Default behavior is the same as `"ignore"`: an unspecified property can appear before or after
any other property.
With `"top"`, unspecified properties are expected *before* any specified properties.
With `"bottom"`, unspecified properties are expected *after* any specified properties.
Given this configuration:
```js
[2, ["color", "background"], { unspecified: "ignore" }]
```
The following patterns are *not* considered warnings:
```css
a {
color: pink;
background: orange;
left: 0;
}
```
```css
a {
left: 0;
color: pink;
background: orange;
}
```
```css
a {
color: pink;
left: 0;
background: orange;
}
```
Given this configuration:
```js
[2, ["color", "background"], { unspecified: "top" }]
```
The following patterns are considered warnings:
```css
a {
color: pink;
background: orange;
left: 0;
}
```
```css
a {
color: pink;
left: 0;
background: orange;
}
```
The following patterns are *not* considered warnings:
```css
a {
left: 0;
color: pink;
background: orange;
}
```
Given this configuration:
```js
[2, ["color", "background"], { unspecified: "bottom" }]
```
The following patterns are considered warnings:
```css
a {
left: 0;
color: pink;
background: orange;
}
```
```css
a {
color: pink;
left: 0;
background: orange;
}
```
The following patterns are *not* considered warnings:
```css
a {
color: pink;
background: orange;
left: 0;
}
```

@@ -14,5 +14,5 @@ /**

export default function (statement, { noBefore }={}) {
if (statement.type !== "rule" && statement.type !== "atrule") { return }
let result = ""
if (statement.type !== "rule" && statement.type !== "atrule") { return result }
let result = ""
if (!noBefore) {

@@ -19,0 +19,0 @@ result += statement.raw("before")

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