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 | function prepareReturnValue(stylelintResults, options, formatter) {
|
21 | const {
|
22 | reportNeedlessDisables,
|
23 | reportInvalidScopeDisables,
|
24 | reportDescriptionlessDisables,
|
25 | maxWarnings,
|
26 | } = options;
|
27 |
|
28 | const errored = stylelintResults.some(
|
29 | (result) => result.errored || result.parseErrors.length > 0,
|
30 | );
|
31 |
|
32 |
|
33 | const returnValue = {
|
34 | errored,
|
35 | results: [],
|
36 | output: '',
|
37 | reportedDisables: reportDisables(stylelintResults),
|
38 | };
|
39 |
|
40 | if (reportNeedlessDisables) {
|
41 | returnValue.needlessDisables = needlessDisables(stylelintResults);
|
42 | }
|
43 |
|
44 | if (reportInvalidScopeDisables) {
|
45 | returnValue.invalidScopeDisables = invalidScopeDisables(stylelintResults);
|
46 | }
|
47 |
|
48 | if (reportDescriptionlessDisables) {
|
49 | returnValue.descriptionlessDisables = descriptionlessDisables(stylelintResults);
|
50 | }
|
51 |
|
52 | if (maxWarnings !== undefined) {
|
53 | const foundWarnings = stylelintResults.reduce((count, file) => {
|
54 | return count + file.warnings.length;
|
55 | }, 0);
|
56 |
|
57 | if (foundWarnings > maxWarnings) {
|
58 | returnValue.maxWarningsExceeded = { maxWarnings, foundWarnings };
|
59 | }
|
60 | }
|
61 |
|
62 | returnValue.output = formatter(stylelintResults, returnValue);
|
63 | returnValue.results = stylelintResults;
|
64 |
|
65 | return returnValue;
|
66 | }
|
67 |
|
68 | module.exports = prepareReturnValue;
|