stylelint-scss
Advanced tools
Comparing version 4.4.0 to 4.5.0
@@ -13,2 +13,8 @@ "use strict"; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
var ruleToCheckAgainst = "function-no-unknown"; | ||
@@ -28,2 +34,29 @@ var ruleName = (0, _utils.namespace)(ruleToCheckAgainst); | ||
exports.meta = meta; | ||
function isNamespacedFunction(fn) { | ||
var namespacedFunc = /^\w+\.\w+$/; | ||
return namespacedFunc.test(fn); | ||
} | ||
function isAtUseAsSyntax(nodes) { | ||
var _nodes$slice = nodes.slice(-3), | ||
_nodes$slice2 = _slicedToArray(_nodes$slice, 3), | ||
first = _nodes$slice2[0], | ||
second = _nodes$slice2[1], | ||
third = _nodes$slice2[2]; | ||
return first.type === "word" && first.value === "as" && second.type === "space" && third.type === "word"; | ||
} | ||
function getAtUseNamespace(nodes) { | ||
if (isAtUseAsSyntax(nodes)) { | ||
var _nodes$slice3 = nodes.slice(-1), | ||
_nodes$slice4 = _slicedToArray(_nodes$slice3, 1), | ||
_last = _nodes$slice4[0]; | ||
return _last.value; | ||
} | ||
var _nodes = _slicedToArray(nodes, 1), | ||
first = _nodes[0]; | ||
var parts = first.value.split("/"); | ||
var _parts$slice = parts.slice(-1), | ||
_parts$slice2 = _slicedToArray(_parts$slice, 1), | ||
last = _parts$slice2[0]; | ||
return last; | ||
} | ||
function rule(primaryOption, secondaryOptions) { | ||
@@ -64,2 +97,18 @@ return function (root, result) { | ||
} | ||
if (isNamespacedFunction(funcName)) { | ||
var atUseNamespaces = []; | ||
root.walkAtRules(/^use$/i, function (atRule) { | ||
var _valueParser = (0, _postcssValueParser["default"])(atRule.params), | ||
nodes = _valueParser.nodes; | ||
atUseNamespaces.push(getAtUseNamespace(nodes)); | ||
}); | ||
if (atUseNamespaces.length) { | ||
var _funcName$split = funcName.split("."), | ||
_funcName$split2 = _slicedToArray(_funcName$split, 1), | ||
_namespace = _funcName$split2[0]; | ||
if (atUseNamespaces.includes(_namespace)) { | ||
return; | ||
} | ||
} | ||
} | ||
if (!ignoreFunctionsAsSet.has(funcName)) { | ||
@@ -66,0 +115,0 @@ _stylelint.utils.report({ |
@@ -142,3 +142,3 @@ "use strict"; | ||
} | ||
var dataURIRegex = /^url\(\s*['"]?data:.+;base64,.+['"]?\s*\)$/; | ||
var dataURIRegex = /^url\(\s*['"]?data:.+['"]?\s*\)/; | ||
root.walk(function (item) { | ||
@@ -145,0 +145,0 @@ if (item.prop === "unicode-range") { |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports["default"] = findOperators; | ||
exports.isInsideFunctionCall = isInsideFunctionCall; | ||
exports.mathOperatorCharType = mathOperatorCharType; | ||
@@ -149,3 +150,3 @@ /** | ||
if (character === "*") { | ||
return "op"; | ||
return checkMultiplication(string, index); | ||
} | ||
@@ -172,2 +173,27 @@ | ||
/** | ||
* Checks the specified `*` char type: operator, sign (*), part of string | ||
* | ||
* @param {String} string - the source string | ||
* @param {Number} index - the index of the character in string to check | ||
* @return {String|false} | ||
* • "op", if the character is a operator in a math/string operation | ||
* • "sign" if it is a sign before a positive number, | ||
* • "char" if it is a part of a string or identifier, | ||
* • false - if it is none from above (most likely an error) | ||
*/ | ||
function checkMultiplication(string, index) { | ||
var insideFn = isInsideFunctionCall(string, index); | ||
if (insideFn.is && insideFn.fn) { | ||
var fnArgsReg = new RegExp(insideFn.fn + "\\(([^)]+)\\)"); | ||
var fnArgs = string.match(fnArgsReg); | ||
var isSingleMultiplicationChar = Array.isArray(fnArgs) && fnArgs[1] === "*"; | ||
// e.g. selector(:has(*)) | ||
if (isSingleMultiplicationChar) { | ||
return "char"; | ||
} | ||
} | ||
return "op"; | ||
} | ||
/** | ||
* Checks the specified `+` char type: operator, sign (+ or -), part of string | ||
@@ -327,2 +353,6 @@ * | ||
if (isInsideInterpolation(string, index)) { | ||
// e.g. `url(https://my-url.com/image-#{$i -2}-dark.svg)` | ||
if (isInsideFunctionCall_.fn === "url") { | ||
return "op"; | ||
} | ||
if (isInsideFunctionCall_.is && (isValueWithUnitAfter_.is && !isValueWithUnitAfter_.opsBetween || isNumberAfter_.is && !isNumberAfter_.opsBetween)) { | ||
@@ -472,3 +502,7 @@ return "sign"; | ||
var isInsideFn = isInsideFunctionCall(string, index); | ||
if (isInsideFn.is && isInsideFn.fn === "url" && isProtocolBefore(before)) { | ||
if (isInsideFn.is && isInsideFn.fn === "url") { | ||
// e.g. `url(https://my-url.com/image-#{$i /2}-dark.svg)` | ||
if (isInsideInterpolation(string, index)) { | ||
return "op"; | ||
} | ||
return "char"; | ||
@@ -629,3 +663,3 @@ } | ||
var after = string.substring(index + 1).trim(); | ||
var beforeMatch = before.match(/([a-zA-Z_-][\w-]*)\([^(){}]+$/); | ||
var beforeMatch = before.match(/(?:[a-zA-Z_-][\w-]*\()?(:?[a-zA-Z_-][\w-]*)\(/); | ||
if (beforeMatch && beforeMatch[0] && after.search(/^[^(,]+\)/) !== -1) { | ||
@@ -801,5 +835,2 @@ result.is = true; | ||
} | ||
function isProtocolBefore(before) { | ||
return before.search(/https?:/) !== -1; | ||
} | ||
function isFunctionBefore(before) { | ||
@@ -806,0 +837,0 @@ return before.trim().search(/[\w-]\(.*?\)\s*$/) !== -1; |
{ | ||
"name": "stylelint-scss", | ||
"description": "A collection of SCSS specific rules for Stylelint", | ||
"version": "4.4.0", | ||
"version": "4.5.0", | ||
"author": "Krister Kari", | ||
@@ -6,0 +6,0 @@ "babel": { |
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
303525
7481