UNPKG

1.41 kBJavaScriptView Raw
1'use strict';
2
3/** @typedef {import('postcss/lib/comment')} PostcssComment */
4/** @typedef {import('stylelint').RangeType} RangeType */
5/** @typedef {import('stylelint').DisableReportRange} DisableReportRange */
6/** @typedef {import('stylelint').StylelintDisableOptionsReport} StylelintDisableOptionsReport */
7
8/**
9 * @param {import('stylelint').StylelintResult[]} results
10 */
11module.exports = function (results) {
12 results.forEach((result) => {
13 // File with `CssSyntaxError` have not `_postcssResult`
14 if (!result._postcssResult) {
15 return;
16 }
17
18 const rangeData = result._postcssResult.stylelint.disabledRanges;
19
20 /** @type {Set<PostcssComment>} */
21 const alreadyReported = new Set();
22
23 Object.keys(rangeData).forEach((rule) => {
24 rangeData[rule].forEach((range) => {
25 if (range.description) return;
26
27 if (alreadyReported.has(range.comment)) return;
28
29 alreadyReported.add(range.comment);
30
31 // If the comment doesn't have a location, we can't report a useful error.
32 // In practice we expect all comments to have locations, though.
33 if (!range.comment.source || !range.comment.source.start) return;
34
35 result.warnings.push({
36 text: `Disable for "${rule}" is missing a description`,
37 rule: '--report-descriptionless-disables',
38 line: range.comment.source.start.line,
39 column: range.comment.source.start.column,
40 severity: 'error',
41 });
42 });
43 });
44 });
45};