UNPKG

908 BJavaScriptView Raw
1"use strict";
2
3const atRuleParamIndex = require("../utils/atRuleParamIndex");
4const report = require("../utils/report");
5const styleSearch = require("style-search");
6
7module.exports = function(opts) {
8 opts.root.walkAtRules(/^media$/i, atRule => {
9 const params = atRule.raws.params ? atRule.raws.params.raw : atRule.params;
10
11 styleSearch({ source: params, target: ":" }, match => {
12 checkColon(params, match.startIndex, atRule);
13 });
14 });
15
16 function checkColon(source, index, node) {
17 opts.locationChecker({
18 source,
19 index,
20 err: m => {
21 const colonIndex = index + atRuleParamIndex(node);
22
23 if (opts.fix && opts.fix(node, colonIndex)) {
24 return;
25 }
26
27 report({
28 message: m,
29 node,
30 index: colonIndex,
31 result: opts.result,
32 ruleName: opts.checkedRuleName
33 });
34 }
35 });
36 }
37};