UNPKG

@fimbul/wotan

Version:

Pluggable TypeScript and JavaScript linter

53 lines 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.module = void 0; const tslib_1 = require("tslib"); const base_1 = require("./base"); const inversify_1 = require("inversify"); const runner_1 = require("../runner"); const formatter_loader_1 = require("../services/formatter-loader"); const ymir_1 = require("@fimbul/ymir"); const cached_file_system_1 = require("../services/cached-file-system"); let LintCommandRunner = class LintCommandRunner extends base_1.AbstractCommandRunner { constructor(runner, formatterLoader, logger, fs) { super(); this.runner = runner; this.formatterLoader = formatterLoader; this.logger = logger; this.fs = fs; } run(options) { var _a; const formatter = new (this.formatterLoader.loadFormatter((_a = options.formatter) !== null && _a !== void 0 ? _a : 'stylish'))(); const result = this.runner.lintCollection(options); let success = true; if (formatter.prefix !== undefined) this.logger.log(formatter.prefix); for (const [file, summary] of result) { if (summary.findings.some((f) => f.severity === 'error')) success = false; const formatted = formatter.format(file, summary); if (formatted !== undefined) this.logger.log(formatted); if (options.fix && summary.fixes) this.fs.writeFile(file, summary.content); } if (formatter.flush !== undefined) { const formatted = formatter.flush(); if (formatted !== undefined) this.logger.log(formatted); } return success; } }; LintCommandRunner = tslib_1.__decorate([ inversify_1.injectable(), tslib_1.__metadata("design:paramtypes", [runner_1.Runner, formatter_loader_1.FormatterLoader, ymir_1.MessageHandler, cached_file_system_1.CachedFileSystem]) ], LintCommandRunner); exports.module = new inversify_1.ContainerModule((bind) => { bind(base_1.AbstractCommandRunner).to(LintCommandRunner); }); //# sourceMappingURL=lint.js.map