1 | 'use strict';
|
2 |
|
3 | const _ = require('lodash');
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | module.exports = function (violation) {
|
31 | const ruleName = violation.ruleName;
|
32 | const result = violation.result;
|
33 | const message = violation.message;
|
34 | const line = violation.line;
|
35 | const node = violation.node;
|
36 | const index = violation.index;
|
37 | const word = violation.word;
|
38 |
|
39 | result.stylelint = result.stylelint || {
|
40 | ruleSeverities: {},
|
41 | customMessages: {},
|
42 | };
|
43 |
|
44 |
|
45 | if (result.stylelint.quiet && result.stylelint.ruleSeverities[ruleName] !== 'error') {
|
46 | return;
|
47 | }
|
48 |
|
49 |
|
50 |
|
51 | const startLine = line || node.positionBy({ index }).line;
|
52 |
|
53 | if (
|
54 | result.stylelint.disabledRanges &&
|
55 | (!result.stylelint.ignoreDisables || result.stylelint.reportNeedlessDisables)
|
56 | ) {
|
57 | const ranges = result.stylelint.disabledRanges[ruleName] || result.stylelint.disabledRanges.all;
|
58 |
|
59 | for (const range of ranges) {
|
60 | if (
|
61 |
|
62 |
|
63 |
|
64 | range.start <= startLine &&
|
65 | (range.end === undefined || range.end >= startLine) &&
|
66 | (!range.rules || range.rules.includes(ruleName))
|
67 | ) {
|
68 | if (result.stylelint.reportNeedlessDisables) {
|
69 |
|
70 |
|
71 | const disabledWarnings =
|
72 | result.stylelint.disabledWarnings || (result.stylelint.disabledWarnings = []);
|
73 |
|
74 | disabledWarnings.push({
|
75 | rule: ruleName,
|
76 | line: startLine,
|
77 | });
|
78 |
|
79 | if (!result.stylelint.ignoreDisables) {
|
80 | return;
|
81 | }
|
82 |
|
83 | break;
|
84 | } else {
|
85 | return;
|
86 | }
|
87 | }
|
88 | }
|
89 | }
|
90 |
|
91 |
|
92 | const severity = _.get(result.stylelint, ['ruleSeverities', ruleName], 'ignore');
|
93 |
|
94 | if (!result.stylelint.stylelintError && severity === 'error') {
|
95 | result.stylelint.stylelintError = true;
|
96 | }
|
97 |
|
98 |
|
99 | const warningProperties = {
|
100 | severity,
|
101 | rule: ruleName,
|
102 | };
|
103 |
|
104 | if (node) {
|
105 | warningProperties.node = node;
|
106 | }
|
107 |
|
108 | if (index) {
|
109 | warningProperties.index = index;
|
110 | }
|
111 |
|
112 | if (word) {
|
113 | warningProperties.word = word;
|
114 | }
|
115 |
|
116 | const warningMessage = _.get(result.stylelint, ['customMessages', ruleName], message);
|
117 |
|
118 | result.warn(warningMessage, warningProperties);
|
119 | };
|