4 const _ = require("lodash");
9 * This function accounts for `disabledRanges` attached to the result.
10 * That is, if the reported violation is within a disabledRange,
11 * it is ignored. Otherwise, it is attached to the result as a
14 * It also accounts for the rule's severity.
16 * You *must* pass *either* a node or a line number.
18 module.exports = function(
29 const ruleName = violation.ruleName;
30 const result = violation.result;
31 const message = violation.message;
32 const line = violation.line;
33 const node = violation.node;
34 const index = violation.index;
35 const word = violation.word;
37 result.stylelint = result.stylelint || {};
39 // In quiet mode, mere warnings are ignored
41 result.stylelint.quiet &&
42 result.stylelint.ruleSeverities[ruleName] !== "error"
47 // If a line is not passed, use the node.positionBy method to get the
48 // line number that the complaint pertains to
49 const startLine = line || node.positionBy({ index }).line;
51 if (result.stylelint.disabledRanges && !result.stylelint.ignoreDisables) {
53 result.stylelint.disabledRanges[ruleName] ||
54 result.stylelint.disabledRanges.all;
55 for (const range of ranges) {
57 // If the violation is within a disabledRange,
58 // and that disabledRange's rules include this one,
59 // do not register a warning
60 range.start <= startLine &&
61 (range.end >= startLine || range.end === undefined) &&
62 (!range.rules || range.rules.indexOf(ruleName) !== -1)
69 const severity = _.get(
71 ["ruleSeverities", ruleName],
75 if (!result.stylelint.stylelintError && severity === "error") {
76 result.stylelint.stylelintError = true;
79 const warningProperties /*: Object*/ = {
84 warningProperties.node = node;
87 warningProperties.index = index;
90 warningProperties.word = word;
93 const warningMessage = _.get(
95 ["customMessages", ruleName],
98 result.warn(warningMessage, warningProperties);