stylelint
Advanced tools
Comparing version 3.1.2 to 3.1.3
@@ -0,1 +1,6 @@ | ||
# 3.1.3 | ||
* Fixed: Bug causing preventing the disabling of rules analyzing the `root` node, including: `max-line-length`, `max-empty-lines`, `no-eol-whitespace`, `no-missing-eof-newline`, and `string-quotes`. | ||
* Fixed: Bug causing `rule-properties-order` to get confused by properties with an unspecified order. | ||
# 3.1.2 | ||
@@ -2,0 +7,0 @@ |
@@ -35,2 +35,9 @@ "use strict"; | ||
var alphabetical = expectation === "alphabetical"; | ||
var expectedOrder = alphabetical ? null : createExpectedOrder(expectation); | ||
// By default, ignore unspecified properties | ||
var unspecified = _lodash2.default.get(options, ["unspecified"], "ignore"); | ||
var allPropData = []; | ||
var lastKnownLineSeparatedGroup = 1; | ||
// Shallow loop | ||
@@ -44,4 +51,4 @@ root.each(function (node) { | ||
function checkNode(node) { | ||
var allPropData = []; | ||
var lastKnownLineSeparatedGroup = 1; | ||
allPropData = []; | ||
lastKnownLineSeparatedGroup = 1; | ||
@@ -72,2 +79,3 @@ node.each(function (child) { | ||
unprefixedName: unprefixedPropName, | ||
orderData: alphabetical ? null : getOrderData(expectedOrder, unprefixedPropName), | ||
before: child.raw("before"), | ||
@@ -86,3 +94,3 @@ index: allPropData.length, | ||
var isCorrectOrder = expectation === "alphabetical" ? checkAlpabeticalOrder(previousPropData, propData) : checkOrder(previousPropData, propData, lastKnownLineSeparatedGroup, child); | ||
var isCorrectOrder = alphabetical ? checkAlpabeticalOrder(previousPropData, propData) : checkOrder(previousPropData, propData); | ||
@@ -102,14 +110,3 @@ if (isCorrectOrder) { | ||
function checkAlpabeticalOrder(firstPropData, secondPropData) { | ||
// If unprefixed prop names are the same, compare the prefixed versions | ||
if (firstPropData.unprefixedName === secondPropData.unprefixedName) { | ||
return firstPropData.name <= secondPropData.name; | ||
} | ||
return firstPropData.unprefixedName < secondPropData.unprefixedName; | ||
} | ||
function checkOrder(firstPropData, secondPropData, lastKnownLineSeparatedGroup, node) { | ||
var expectedOrder = createExpectedOrder(expectation); | ||
function checkOrder(firstPropData, secondPropData) { | ||
// If the unprefixed property names are the same, resort to alphabetical ordering | ||
@@ -120,13 +117,8 @@ if (firstPropData.unprefixedName === secondPropData.unprefixedName) { | ||
// By default, ignore unspecified properties | ||
var unspecified = _lodash2.default.get(options, ["unspecified"], "ignore"); | ||
var firstPropIsUnspecified = !firstPropData.orderData; | ||
var secondPropIsUnspecified = !secondPropData.orderData; | ||
var firstPropOrderValue = getOrderValue(expectedOrder, firstPropData.unprefixedName); | ||
var secondPropOrderValue = getOrderValue(expectedOrder, secondPropData.unprefixedName); | ||
var firstPropIsUnspecified = !firstPropOrderValue; | ||
var secondPropIsUnspecified = !secondPropOrderValue; | ||
// Now check newlines between ... | ||
var firstPropLineSeparatedGroup = !firstPropIsUnspecified ? firstPropOrderValue.lineSeparatedGroup : lastKnownLineSeparatedGroup; | ||
var secondPropLineSeparatedGroup = !secondPropIsUnspecified ? secondPropOrderValue.lineSeparatedGroup : lastKnownLineSeparatedGroup; | ||
var firstPropLineSeparatedGroup = !firstPropIsUnspecified ? firstPropData.orderData.lineSeparatedGroup : lastKnownLineSeparatedGroup; | ||
var secondPropLineSeparatedGroup = !secondPropIsUnspecified ? secondPropData.orderData.lineSeparatedGroup : lastKnownLineSeparatedGroup; | ||
if (firstPropLineSeparatedGroup !== secondPropLineSeparatedGroup) { | ||
@@ -136,3 +128,3 @@ if (!hasEmptyLineBefore(secondPropData.node)) { | ||
message: messages.expectedEmptyLineBetween(secondPropData.name, firstPropData.name), | ||
node: node, | ||
node: secondPropData.node, | ||
result: result, | ||
@@ -147,5 +139,22 @@ ruleName: ruleName | ||
if (!firstPropIsUnspecified && !secondPropIsUnspecified) { | ||
return firstPropOrderValue.expectedPosition <= secondPropOrderValue.expectedPosition; | ||
return firstPropData.orderData.expectedPosition <= secondPropData.orderData.expectedPosition; | ||
} | ||
if (firstPropIsUnspecified && !secondPropIsUnspecified) { | ||
// If first prop is unspecified, look for a specified prop before it to | ||
// compare to the current prop | ||
var priorSpecifiedPropData = _lodash2.default.findLast(allPropData.slice(0, -1), function (d) { | ||
return !!d.orderData; | ||
}); | ||
if (priorSpecifiedPropData && priorSpecifiedPropData.orderData && priorSpecifiedPropData.orderData.expectedPosition > secondPropData.orderData.expectedPosition) { | ||
(0, _utils.report)({ | ||
message: messages.expected(secondPropData.name, priorSpecifiedPropData.name), | ||
node: secondPropData.node, | ||
result: result, | ||
ruleName: ruleName | ||
}); | ||
return true; // avoid logging another warning | ||
} | ||
} | ||
// Now deal with unspecified props ... | ||
@@ -200,4 +209,3 @@ | ||
function createExpectedOrder(input) { | ||
var expectedOrder = {}; | ||
var order = {}; | ||
var lineSeparatedGroup = 1; | ||
@@ -222,3 +230,3 @@ var expectedPosition = 0; | ||
} | ||
expectedOrder[item] = { lineSeparatedGroup: lineSeparatedGroup, expectedPosition: expectedPosition }; | ||
order[item] = { lineSeparatedGroup: lineSeparatedGroup, expectedPosition: expectedPosition }; | ||
return; | ||
@@ -243,15 +251,15 @@ } | ||
} | ||
return expectedOrder; | ||
return order; | ||
} | ||
function getOrderValue(expectedOrder, propName) { | ||
var orderValue = expectedOrder[propName]; | ||
function getOrderData(expectedOrder, propName) { | ||
var orderData = expectedOrder[propName]; | ||
// If prop was not specified but has a hyphen | ||
// (e.g. `padding-top`), try looking for the segment preceding the hyphen | ||
// and use that index | ||
if (!orderValue && propName.lastIndexOf("-") !== -1) { | ||
if (!orderData && propName.lastIndexOf("-") !== -1) { | ||
var propNamePreHyphen = propName.slice(0, propName.lastIndexOf("-")); | ||
orderValue = getOrderValue(expectedOrder, propNamePreHyphen); | ||
orderData = getOrderData(expectedOrder, propNamePreHyphen); | ||
} | ||
return orderValue; | ||
return orderData; | ||
} | ||
@@ -274,2 +282,11 @@ | ||
return false; | ||
} | ||
function checkAlpabeticalOrder(firstPropData, secondPropData) { | ||
// If unprefixed prop names are the same, compare the prefixed versions | ||
if (firstPropData.unprefixedName === secondPropData.unprefixedName) { | ||
return firstPropData.name <= secondPropData.name; | ||
} | ||
return firstPropData.unprefixedName < secondPropData.unprefixedName; | ||
} |
@@ -8,25 +8,23 @@ "use strict"; | ||
exports.default = function (_ref) { | ||
var | ||
/** | ||
* Report a violation. | ||
* | ||
* This function accounts for `disabledRanges` attached to the result. | ||
* That is, if the reported violation is within a disabledRange, | ||
* it is ignored. Otherwise, it is attached to the result as a | ||
* postcss warning. | ||
* | ||
* It also accounts for the rule's severity. | ||
* | ||
* You *must* pass *either* a node or a line number. | ||
* | ||
* @param {object} violation - Details about the violation | ||
* @param {string} violation.ruleName - The name of the rule | ||
* @param {Result} violation.result - postcss Result object | ||
* @param {string} violation.message - Message to inform user of the violation | ||
* @param {Node} [violation.node] - postcss Node object | ||
* @param {Node} [violation.index] - Index that should be passed to result.warn() | ||
* @param {Node} [violation.word] - Word that should be passed to result.warn() | ||
* @param {number} [violation.line] - Line number of the violation | ||
*/ | ||
var /** | ||
* Report a violation. | ||
* | ||
* This function accounts for `disabledRanges` attached to the result. | ||
* That is, if the reported violation is within a disabledRange, | ||
* it is ignored. Otherwise, it is attached to the result as a | ||
* postcss warning. | ||
* | ||
* It also accounts for the rule's severity. | ||
* | ||
* You *must* pass *either* a node or a line number. | ||
* | ||
* @param {object} violation - Details about the violation | ||
* @param {string} violation.ruleName - The name of the rule | ||
* @param {Result} violation.result - postcss Result object | ||
* @param {string} violation.message - Message to inform user of the violation | ||
* @param {Node} [violation.node] - postcss Node object | ||
* @param {Node} [violation.index] - Index that should be passed to result.warn() | ||
* @param {Node} [violation.word] - Word that should be passed to result.warn() | ||
* @param {number} [violation.line] - Line number of the violation | ||
*/ | ||
ruleName = _ref.ruleName; | ||
@@ -47,3 +45,5 @@ var result = _ref.result; | ||
var startLine = line || (0, _lodash.get)(node, "source.start.line"); | ||
// If a line is not passed, use the node.positionBy method to get the | ||
// line number that the complaint pertains to | ||
var startLine = line || node.positionBy({ index: index }).line; | ||
@@ -108,4 +108,2 @@ if (result.stylelint.disabledRanges) { | ||
result.warn(message, warningProperties); | ||
}; | ||
var _lodash = require("lodash"); | ||
}; |
{ | ||
"name": "stylelint", | ||
"version": "3.1.2", | ||
"version": "3.1.3", | ||
"description": "Modern CSS linter", | ||
@@ -52,3 +52,3 @@ "keywords": [ | ||
"babel-preset-es2015": "^6.1.18", | ||
"babel-tape-runner": "^1.3.0", | ||
"babel-tape-runner": "^2.0.0", | ||
"eslint": "^1.4.1", | ||
@@ -55,0 +55,0 @@ "eslint-config-stylelint": "^0.1.0", |
@@ -40,2 +40,9 @@ import _ from "lodash" | ||
const alphabetical = expectation === "alphabetical" | ||
const expectedOrder = (alphabetical) ? null : createExpectedOrder(expectation) | ||
// By default, ignore unspecified properties | ||
const unspecified = _.get(options, ["unspecified"], "ignore") | ||
let allPropData = [] | ||
let lastKnownLineSeparatedGroup = 1 | ||
// Shallow loop | ||
@@ -49,4 +56,4 @@ root.each(node => { | ||
function checkNode(node) { | ||
const allPropData = [] | ||
let lastKnownLineSeparatedGroup = 1 | ||
allPropData = [] | ||
lastKnownLineSeparatedGroup = 1 | ||
@@ -73,2 +80,3 @@ node.each(child => { | ||
unprefixedName: unprefixedPropName, | ||
orderData: (alphabetical) ? null : getOrderData(expectedOrder, unprefixedPropName), | ||
before: child.raw("before"), | ||
@@ -85,5 +93,5 @@ index: allPropData.length, | ||
const isCorrectOrder = (expectation === "alphabetical") | ||
const isCorrectOrder = (alphabetical) | ||
? checkAlpabeticalOrder(previousPropData, propData) | ||
: checkOrder(previousPropData, propData, lastKnownLineSeparatedGroup, child) | ||
: checkOrder(previousPropData, propData) | ||
@@ -101,14 +109,3 @@ if (isCorrectOrder) { return } | ||
function checkAlpabeticalOrder(firstPropData, secondPropData) { | ||
// If unprefixed prop names are the same, compare the prefixed versions | ||
if (firstPropData.unprefixedName === secondPropData.unprefixedName) { | ||
return firstPropData.name <= secondPropData.name | ||
} | ||
return firstPropData.unprefixedName < secondPropData.unprefixedName | ||
} | ||
function checkOrder(firstPropData, secondPropData, lastKnownLineSeparatedGroup, node) { | ||
const expectedOrder = createExpectedOrder(expectation) | ||
function checkOrder(firstPropData, secondPropData) { | ||
// If the unprefixed property names are the same, resort to alphabetical ordering | ||
@@ -119,16 +116,11 @@ if (firstPropData.unprefixedName === secondPropData.unprefixedName) { | ||
// By default, ignore unspecified properties | ||
const unspecified = _.get(options, ["unspecified"], "ignore") | ||
const firstPropIsUnspecified = !firstPropData.orderData | ||
const secondPropIsUnspecified = !secondPropData.orderData | ||
const firstPropOrderValue = getOrderValue(expectedOrder, firstPropData.unprefixedName) | ||
const secondPropOrderValue = getOrderValue(expectedOrder, secondPropData.unprefixedName) | ||
const firstPropIsUnspecified = !firstPropOrderValue | ||
const secondPropIsUnspecified = !secondPropOrderValue | ||
// Now check newlines between ... | ||
const firstPropLineSeparatedGroup = (!firstPropIsUnspecified) | ||
? firstPropOrderValue.lineSeparatedGroup | ||
? firstPropData.orderData.lineSeparatedGroup | ||
: lastKnownLineSeparatedGroup | ||
const secondPropLineSeparatedGroup = (!secondPropIsUnspecified) | ||
? secondPropOrderValue.lineSeparatedGroup | ||
? secondPropData.orderData.lineSeparatedGroup | ||
: lastKnownLineSeparatedGroup | ||
@@ -139,3 +131,3 @@ if (firstPropLineSeparatedGroup !== secondPropLineSeparatedGroup) { | ||
message: messages.expectedEmptyLineBetween(secondPropData.name, firstPropData.name), | ||
node, | ||
node: secondPropData.node, | ||
result, | ||
@@ -150,5 +142,23 @@ ruleName, | ||
if (!firstPropIsUnspecified && !secondPropIsUnspecified) { | ||
return firstPropOrderValue.expectedPosition <= secondPropOrderValue.expectedPosition | ||
return firstPropData.orderData.expectedPosition <= secondPropData.orderData.expectedPosition | ||
} | ||
if (firstPropIsUnspecified && !secondPropIsUnspecified) { | ||
// If first prop is unspecified, look for a specified prop before it to | ||
// compare to the current prop | ||
const priorSpecifiedPropData = _.findLast(allPropData.slice(0, -1), d => !!d.orderData) | ||
if ( | ||
priorSpecifiedPropData && priorSpecifiedPropData.orderData | ||
&& priorSpecifiedPropData.orderData.expectedPosition > secondPropData.orderData.expectedPosition | ||
) { | ||
report({ | ||
message: messages.expected(secondPropData.name, priorSpecifiedPropData.name), | ||
node: secondPropData.node, | ||
result, | ||
ruleName, | ||
}) | ||
return true // avoid logging another warning | ||
} | ||
} | ||
// Now deal with unspecified props ... | ||
@@ -170,4 +180,3 @@ | ||
function createExpectedOrder(input) { | ||
const expectedOrder = {} | ||
const order = {} | ||
let lineSeparatedGroup = 1 | ||
@@ -188,3 +197,3 @@ let expectedPosition = 0 | ||
if (!inFlexibleGroup) { expectedPosition += 1 } | ||
expectedOrder[item] = { lineSeparatedGroup, expectedPosition } | ||
order[item] = { lineSeparatedGroup, expectedPosition } | ||
return | ||
@@ -209,15 +218,15 @@ } | ||
} | ||
return expectedOrder | ||
return order | ||
} | ||
function getOrderValue(expectedOrder, propName) { | ||
let orderValue = expectedOrder[propName] | ||
function getOrderData(expectedOrder, propName) { | ||
let orderData = expectedOrder[propName] | ||
// If prop was not specified but has a hyphen | ||
// (e.g. `padding-top`), try looking for the segment preceding the hyphen | ||
// and use that index | ||
if (!orderValue && propName.lastIndexOf("-") !== -1) { | ||
if (!orderData && propName.lastIndexOf("-") !== -1) { | ||
const propNamePreHyphen = propName.slice(0, propName.lastIndexOf("-")) | ||
orderValue = getOrderValue(expectedOrder, propNamePreHyphen) | ||
orderData = getOrderData(expectedOrder, propNamePreHyphen) | ||
} | ||
return orderValue | ||
return orderData | ||
} | ||
@@ -233,1 +242,10 @@ | ||
} | ||
function checkAlpabeticalOrder(firstPropData, secondPropData) { | ||
// If unprefixed prop names are the same, compare the prefixed versions | ||
if (firstPropData.unprefixedName === secondPropData.unprefixedName) { | ||
return firstPropData.name <= secondPropData.name | ||
} | ||
return firstPropData.unprefixedName < secondPropData.unprefixedName | ||
} |
@@ -379,3 +379,3 @@ # rule-properties-order | ||
```js | ||
[2, ["color", "background"], { unspecified: "ignore" }] | ||
[["color", "background"], { unspecified: "ignore" }] | ||
``` | ||
@@ -412,3 +412,3 @@ | ||
```js | ||
[2, ["color", "background"], { unspecified: "top" }] | ||
[["color", "background"], { unspecified: "top" }] | ||
``` | ||
@@ -435,3 +435,2 @@ | ||
The following patterns are *not* considered warnings: | ||
@@ -450,3 +449,3 @@ | ||
```js | ||
[2, ["color", "background"], { unspecified: "bottom" }] | ||
[["color", "background"], { unspecified: "bottom" }] | ||
``` | ||
@@ -473,3 +472,2 @@ | ||
The following patterns are *not* considered warnings: | ||
@@ -476,0 +474,0 @@ |
@@ -1,3 +0,1 @@ | ||
import { get } from "lodash" | ||
/** | ||
@@ -40,3 +38,5 @@ * Report a violation. | ||
const startLine = line || get(node, "source.start.line") | ||
// If a line is not passed, use the node.positionBy method to get the | ||
// line number that the complaint pertains to | ||
const startLine = line || node.positionBy({ index }).line | ||
@@ -43,0 +43,0 @@ if (result.stylelint.disabledRanges) { |
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
687708
15303