UNPKG

1.34 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 =
15 declarationValueIndex(decl) + (decl.raws.between || "").length - 1;
16
17 // The extra characters tacked onto the end ensure that there is a character to check
18 // after the colon. Otherwise, with `background:pink` the character after the
19 const propPlusColon = decl.toString().slice(0, endOfPropIndex) + "xxx";
20
21 for (let i = 0, l = propPlusColon.length; i < l; i++) {
22 if (propPlusColon[i] !== ":") {
23 continue;
24 }
25
26 opts.locationChecker({
27 source: propPlusColon,
28 index: i,
29 lineCheckStr: decl.value,
30 err: m => {
31 if (opts.fix && opts.fix(decl, i)) {
32 return;
33 }
34
35 report({
36 message: m,
37 node: decl,
38 index: decl.prop.toString().length + 1,
39 result: opts.result,
40 ruleName: opts.checkedRuleName
41 });
42 }
43 });
44 break;
45 }
46 });
47};