1 | 'use strict';
|
2 |
|
3 | const descriptionlessDisables = require('./descriptionlessDisables');
|
4 | const invalidScopeDisables = require('./invalidScopeDisables');
|
5 | const needlessDisables = require('./needlessDisables');
|
6 | const reportDisables = require('./reportDisables');
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | module.exports = function prepareReturnValue(stylelintResults, maxWarnings, formatter, cwd) {
|
22 | reportDisables(stylelintResults);
|
23 | needlessDisables(stylelintResults);
|
24 | invalidScopeDisables(stylelintResults);
|
25 | descriptionlessDisables(stylelintResults);
|
26 |
|
27 | const errored = stylelintResults.some(
|
28 | (result) =>
|
29 | result.errored ||
|
30 | result.parseErrors.length > 0 ||
|
31 | result.warnings.some((warning) => warning.severity === 'error'),
|
32 | );
|
33 |
|
34 |
|
35 | const returnValue = {
|
36 | cwd,
|
37 | errored,
|
38 | results: [],
|
39 | output: '',
|
40 | reportedDisables: [],
|
41 | ruleMetadata: getRuleMetadata(stylelintResults),
|
42 | };
|
43 |
|
44 | if (maxWarnings !== undefined) {
|
45 | const foundWarnings = stylelintResults.reduce((count, file) => count + file.warnings.length, 0);
|
46 |
|
47 | if (foundWarnings > maxWarnings) {
|
48 | returnValue.maxWarningsExceeded = { maxWarnings, foundWarnings };
|
49 | }
|
50 | }
|
51 |
|
52 | returnValue.output = formatter(stylelintResults, returnValue);
|
53 | returnValue.results = stylelintResults;
|
54 |
|
55 | return returnValue;
|
56 | };
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | function getRuleMetadata(lintResults) {
|
62 | const [lintResult] = lintResults;
|
63 |
|
64 | if (lintResult === undefined) return {};
|
65 |
|
66 | if (lintResult._postcssResult === undefined) return {};
|
67 |
|
68 | return lintResult._postcssResult.stylelint.ruleMetadata;
|
69 | }
|