UNPKG

declapract

Version:

A tool to declaratively define best practices, maintainable evolve them, and scalably enforce them.

44 lines 2.59 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.applyPlan = void 0; const chalk_1 = __importDefault(require("chalk")); const indent_string_1 = __importDefault(require("indent-string")); const domain_1 = require("../../../../domain"); const UnexpectedCodePathError_1 = require("../../../UnexpectedCodePathError"); const getColoredPlanTitle_1 = require("../display/color/getColoredPlanTitle"); const sortFileCheckEvaluationsByPracticeRef_1 = require("../sortFileCheckEvaluationsByPracticeRef"); const sortFilePracticeEvaluationsByPracticeName_1 = require("../sortFilePracticeEvaluationsByPracticeName"); const fixFile_1 = require("./fixFile"); /** * for each "fixable" and "failed" check in the plan, apply the fix */ const applyPlan = async ({ plan, projectRootDirectory, }) => { // sanity check that the plan has fixable actions if (plan.action !== domain_1.RequiredAction.FIX_AUTOMATIC) throw new UnexpectedCodePathError_1.UnexpectedCodePathError('asked to apply a plan which does not have action FIX_AUTOMATIC specified', { plan, }); // should have been filtered out by now // print out the title for this file const title = (0, getColoredPlanTitle_1.getColoredPlanTitle)({ plan }); console.log(` * ${title}`); // tslint:disable-line: no-console // for each failed evaluation check, output that we're applying it for (const practiceEvaluation of plan.evaluations.sort(sortFilePracticeEvaluationsByPracticeName_1.sortFilePracticeEvaluationsByPracticeName)) { // grab the failed, fixable checks const failedFixableChecks = practiceEvaluation.checks .filter(domain_1.hasFailed) .filter(domain_1.isFixableCheck) .sort(sortFileCheckEvaluationsByPracticeRef_1.sortFileCheckEvaluationsByPracticeRef); // apply each of them, one at a time sequentially for (const checkEvaluation of failedFixableChecks) { await (0, fixFile_1.fixFile)({ evaluation: checkEvaluation, projectRootDirectory }); const statusToken = chalk_1.default.green('✓'); const fixabilityToken = chalk_1.default.gray('(fix:applied)'); console.log((0, indent_string_1.default)(`${statusToken} practice:${checkEvaluation.practiceRef} ${fixabilityToken}`, 4)); // tslint:disable-line: no-console } } }; exports.applyPlan = applyPlan; //# sourceMappingURL=applyPlan.js.map