UNPKG

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