UNPKG

kist

Version:

Package Pipeline Processor

64 lines (63 loc) 3.08 kB
"use strict"; // ============================================================================ // Import // ============================================================================ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.LintAction = void 0; const eslint_1 = require("eslint"); const Action_1 = require("../../core/pipeline/Action"); // ============================================================================ // Classes // ============================================================================ /** * LintAction handles linting TypeScript and JavaScript files using ESLint. * This action can be configured to run in strict mode or automatically fix issues. */ class LintAction extends Action_1.Action { constructor() { super(); // Call the parent class constructor this.eslint = new eslint_1.ESLint({}); // Initialize ESLint with default config } execute(options) { return __awaiter(this, void 0, void 0, function* () { const { targetFiles = ["src/**/*.ts"], fix = false, configPath = ".eslintrc.js", } = options; if (!targetFiles || targetFiles.length === 0) { throw new Error("Invalid options: 'targetFiles' is required and must contain at least one file or directory."); } this.logInfo(`Starting ESLint on: ${targetFiles.join(", ")}`); try { // Update ESLint instance with correct configuration this.eslint = new eslint_1.ESLint({ fix, overrideConfigFile: configPath }); const results = yield this.eslint.lintFiles(targetFiles); if (fix) { yield eslint_1.ESLint.outputFixes(results); } const formatter = yield this.eslint.loadFormatter("stylish"); console.log(formatter.format(results)); this.logInfo("ESLint linting completed successfully."); } catch (error) { this.logError("ESLint encountered an error.", error); throw error; } }); } /** * Provides a description of the action. * * @returns A string description of the action. */ describe() { return "Runs ESLint on specified files and directories, with optional auto-fixing."; } } exports.LintAction = LintAction;