UNPKG

2.81 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const base_command_1 = require("../base-command");
5const command_1 = require("@oclif/command");
6const runner_1 = require("../../services/tslint/runner");
7const config_1 = require("../../services/tslint/config");
8const config_2 = require("../../services/stylelint/config");
9const runner_2 = require("../../services/stylelint/runner");
10var ArgumentsKeys;
11(function (ArgumentsKeys) {
12 ArgumentsKeys["sourcesDirectory"] = "sources_directory";
13 ArgumentsKeys["linterType"] = "linter_type";
14})(ArgumentsKeys || (ArgumentsKeys = {}));
15var LinterType;
16(function (LinterType) {
17 LinterType["ts"] = "ts";
18 LinterType["style"] = "style";
19})(LinterType || (LinterType = {}));
20class LintCommand extends base_command_1.BaseCommand {
21 run() {
22 return tslib_1.__awaiter(this, void 0, void 0, function* () {
23 const { linter_type } = this.getArguments();
24 this.getRunner(linter_type).run();
25 });
26 }
27 getRunner(type) {
28 const { sources_directory } = this.getArguments();
29 const flags = this.getFlags();
30 if (type === LinterType.ts) {
31 const tsLintRunnerConfig = config_1.createTsLintConfig(Object.assign(Object.assign({}, flags), { path: sources_directory }));
32 if (flags.verbose) {
33 console.log("TsLint Parameters", tsLintRunnerConfig, "\n");
34 }
35 return new runner_1.TsLintRunner(tsLintRunnerConfig);
36 }
37 if (type === LinterType.style) {
38 const styleLintRunnerConfig = config_2.createStyleLintConfig(Object.assign(Object.assign({}, flags), { path: sources_directory }));
39 if (flags.verbose) {
40 console.log("StyleLint Parameters", styleLintRunnerConfig, "\n");
41 }
42 return new runner_2.StyleLintRunner(styleLintRunnerConfig, flags.force);
43 }
44 throw new Error(`Lint runner for '${type}' is not implemented yet`);
45 }
46}
47exports.default = LintCommand;
48LintCommand.description = "lint source code";
49LintCommand.args = [
50 {
51 name: ArgumentsKeys.linterType,
52 description: "type of the linter",
53 options: [LinterType.ts, LinterType.style],
54 required: true,
55 },
56 {
57 name: ArgumentsKeys.sourcesDirectory,
58 description: "directory with sources of the application",
59 required: true,
60 }
61];
62LintCommand.flags = Object.assign(Object.assign({}, base_command_1.BaseCommand.flags), { fix: command_1.flags.boolean({
63 default: false,
64 description: "fixes linting errors"
65 }), force: command_1.flags.boolean({
66 char: "f",
67 default: false,
68 description: "return status code 0 even if there are lint errors"
69 }) });