UNPKG

1.22 kBJavaScriptView Raw
1'use strict';
2
3const declarationValueIndex = require('../utils/declarationValueIndex');
4const isStandardSyntaxDeclaration = require('../utils/isStandardSyntaxDeclaration');
5const report = require('../utils/report');
6
7module.exports = function (opts) {
8 opts.root.walkDecls((decl) => {
9 if (!isStandardSyntaxDeclaration(decl)) {
10 return;
11 }
12
13 // Get the raw prop, and only the prop
14 const endOfPropIndex = declarationValueIndex(decl) + (decl.raws.between || '').length - 1;
15
16 // The extra characters tacked onto the end ensure that there is a character to check
17 // after the colon. Otherwise, with `background:pink` the character after the
18 const propPlusColon = `${decl.toString().slice(0, endOfPropIndex)}xxx`;
19
20 for (let i = 0, l = propPlusColon.length; i < l; i++) {
21 if (propPlusColon[i] !== ':') {
22 continue;
23 }
24
25 opts.locationChecker({
26 source: propPlusColon,
27 index: i,
28 lineCheckStr: decl.value,
29 err: (m) => {
30 if (opts.fix && opts.fix(decl, i)) {
31 return;
32 }
33
34 report({
35 message: m,
36 node: decl,
37 index: decl.prop.toString().length + 1,
38 result: opts.result,
39 ruleName: opts.checkedRuleName,
40 });
41 },
42 });
43 break;
44 }
45 });
46};