UNPKG

1.17 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const stylelint_1 = require("stylelint");
4class StyleLintRunner {
5 constructor(config, force = false) {
6 this.config = config;
7 this.force = force;
8 this.printResult = (data) => {
9 // do things with data.output, data.errored,
10 // and data.results
11 const formattedResult = stylelint_1.formatters.string(data.results);
12 console.log(formattedResult); // eslint-disable-line no-console
13 if (data.errored && !this.noErrorExitCode) {
14 process.exitCode = 1;
15 }
16 };
17 this.handleUnexpectedError = (error) => {
18 // do things with err e.g.
19 console.error(error.stack); // eslint-disable-line no-console
20 if (!this.noErrorExitCode) {
21 process.exitCode = 1;
22 }
23 };
24 }
25 get noErrorExitCode() {
26 return this.force;
27 }
28 run() {
29 stylelint_1.lint(this.config)
30 .then(this.printResult)
31 .catch(this.handleUnexpectedError);
32 }
33}
34exports.StyleLintRunner = StyleLintRunner;