1 | 'use strict';
|
2 |
|
3 | const declarationValueIndex = require('../utils/declarationValueIndex');
|
4 | const isStandardSyntaxDeclaration = require('../utils/isStandardSyntaxDeclaration');
|
5 | const report = require('../utils/report');
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | module.exports = function declarationColonSpaceChecker(opts) {
|
19 | opts.root.walkDecls((decl) => {
|
20 | if (!isStandardSyntaxDeclaration(decl)) {
|
21 | return;
|
22 | }
|
23 |
|
24 |
|
25 | const endOfPropIndex = declarationValueIndex(decl) + (decl.raws.between || '').length - 1;
|
26 |
|
27 |
|
28 |
|
29 | const propPlusColon = `${decl.toString().slice(0, endOfPropIndex)}xxx`;
|
30 |
|
31 | for (let i = 0, l = propPlusColon.length; i < l; i++) {
|
32 | if (propPlusColon[i] !== ':') {
|
33 | continue;
|
34 | }
|
35 |
|
36 | opts.locationChecker({
|
37 | source: propPlusColon,
|
38 | index: i,
|
39 | lineCheckStr: decl.value,
|
40 | err: (message) => {
|
41 | if (opts.fix && opts.fix(decl, i)) {
|
42 | return;
|
43 | }
|
44 |
|
45 | report({
|
46 | message,
|
47 | node: decl,
|
48 | index: decl.prop.toString().length + 1,
|
49 | result: opts.result,
|
50 | ruleName: opts.checkedRuleName,
|
51 | });
|
52 | },
|
53 | });
|
54 | break;
|
55 | }
|
56 | });
|
57 | };
|