3 const _ = require("lodash");
4 const declarationValueIndex = require("../utils/declarationValueIndex");
5 const isStandardSyntaxFunction = require("../utils/isStandardSyntaxFunction");
6 const report = require("../utils/report");
7 const styleSearch = require("style-search");
8 const valueParser = require("postcss-value-parser");
10 module.exports = function(opts) {
11 opts.root.walkDecls(decl => {
12 const declValue = _.get(decl, "raws.value.raw", decl.value);
14 valueParser(declValue).walk(valueNode => {
15 if (valueNode.type !== "function") {
19 if (!isStandardSyntaxFunction(valueNode)) {
23 // Ignore `url()` arguments, which may contain data URIs or other funky stuff
24 if (valueNode.value.toLowerCase() === "url") {
28 const functionArguments = (() => {
29 let result = valueParser.stringify(valueNode);
30 // Remove function name and opening paren
31 result = result.slice(valueNode.value.length + 1);
32 // Remove closing paren
33 result = result.slice(0, result.length - 1);
34 // 1. Remove comments including preceeding whitespace (when only succeeded by whitespace)
35 // 2. Remove all other comments, but leave adjacent whitespace intact
36 result = result.replace(
37 /( *\/(\*.*\*\/(?!\S)|\/.*)|(\/(\*.*\*\/|\/.*)))/,
45 source: functionArguments,
47 functionArguments: "skip"
50 opts.locationChecker({
51 source: functionArguments,
52 index: match.startIndex,
55 declarationValueIndex(decl) +
56 valueNode.value.length +
58 valueNode.sourceIndex +
65 ruleName: opts.checkedRuleName