1 |
|
2 |
|
3 | 'use strict';
|
4 |
|
5 | const atRuleParamIndex = require('../utils/atRuleParamIndex');
|
6 | const report = require('../utils/report');
|
7 | const styleSearch = require('style-search');
|
8 |
|
9 | module.exports = function (opts) {
|
10 | opts.root.walkAtRules(/^media$/i, (atRule) => {
|
11 | const params = atRule.raws.params ? atRule.raws.params.raw : atRule.params;
|
12 |
|
13 | styleSearch({ source: params, target: ',' }, (match) => {
|
14 | let index = match.startIndex;
|
15 |
|
16 | if (opts.allowTrailingComments) {
|
17 |
|
18 | let execResult;
|
19 |
|
20 | while ((execResult = /^[^\S\r\n]*\/\*([\s\S]*?)\*\//.exec(params.slice(index + 1)))) {
|
21 | index += execResult[0].length;
|
22 | }
|
23 |
|
24 | if ((execResult = /^([^\S\r\n]*\/\/([\s\S]*?))\r?\n/.exec(params.slice(index + 1)))) {
|
25 | index += execResult[1].length;
|
26 | }
|
27 | }
|
28 |
|
29 | checkComma(params, index, atRule);
|
30 | });
|
31 | });
|
32 |
|
33 | function checkComma(source, index, node) {
|
34 | opts.locationChecker({
|
35 | source,
|
36 | index,
|
37 | err: (m) => {
|
38 | const commaIndex = index + atRuleParamIndex(node);
|
39 |
|
40 | if (opts.fix && opts.fix(node, commaIndex)) {
|
41 | return;
|
42 | }
|
43 |
|
44 | report({
|
45 | message: m,
|
46 | node,
|
47 | index: commaIndex,
|
48 | result: opts.result,
|
49 | ruleName: opts.checkedRuleName,
|
50 | });
|
51 | },
|
52 | });
|
53 | }
|
54 | };
|