declapract
Version:
A tool to declaratively define best practices, maintainable evolve them, and scalably enforce them.
62 lines • 3.56 kB
JavaScript
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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.evaluteProjectAgainstPracticeDeclaration = void 0;
const chalk_1 = __importDefault(require("chalk"));
const domain_1 = require("../../../domain");
const FilePracticeEvaluation_1 = require("../../../domain/objects/FilePracticeEvaluation");
const evaluateProjectAgainstProjectCheckDeclaration_1 = require("./evaluateProjectAgainstProjectCheckDeclaration");
const evaluteProjectAgainstPracticeDeclaration = (_a) => __awaiter(void 0, [_a], void 0, function* ({ practice, project, }) {
// evaluate all of the best practices checks and bad practices checks
const bestPracticeFileCheckEvaluations = practice.bestPractice
? yield (0, evaluateProjectAgainstProjectCheckDeclaration_1.evaluteProjectAgainstProjectCheckDeclaration)({
practiceRef: `${practice.name}.best-practice`,
purpose: domain_1.FileCheckPurpose.BEST_PRACTICE,
declaration: practice.bestPractice,
project,
})
: [];
const badPracticeFileCheckEvaluations = (yield Promise.all(practice.badPractices.map((badPractice) => (0, evaluateProjectAgainstProjectCheckDeclaration_1.evaluteProjectAgainstProjectCheckDeclaration)({
practiceRef: `${practice.name}.bad-practice.${badPractice.name}`,
purpose: domain_1.FileCheckPurpose.BAD_PRACTICE,
declaration: badPractice,
project,
})))).flat();
// merge the results per file (i.e., if a file passes best practices (or does not exist there) but fails bad practices, just report it as failed once... but if it exists in either and passes all, then report as passed once)
const pathsEvaluated = [
...new Set([
...bestPracticeFileCheckEvaluations,
...badPracticeFileCheckEvaluations,
].map((evaluation) => evaluation.path)),
].sort();
const evaluations = pathsEvaluated.map((path) => {
const checks = [
...bestPracticeFileCheckEvaluations,
...badPracticeFileCheckEvaluations,
].filter((check) => check.path === path);
const result = checks.every(domain_1.hasPassed)
? domain_1.FileEvaluationResult.PASS
: domain_1.FileEvaluationResult.FAIL;
return new FilePracticeEvaluation_1.FilePracticeEvaluation({
path,
result,
checks,
practice,
});
});
console.log(chalk_1.default.gray(` ✓ evaluated practice:${practice.name}`)); // tslint:disable-line: no-console
return evaluations;
});
exports.evaluteProjectAgainstPracticeDeclaration = evaluteProjectAgainstPracticeDeclaration;
//# sourceMappingURL=evaluateProjectAgainstPracticeDeclaration.js.map
;