UNPKG

raas-core

Version:
178 lines 5.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const fs = require("fs"); const cheerio = require("cheerio"); const modelService_1 = require("./modelService"); class AnaysisResultsUtil { static loadFromLocation(location) { return new Promise((resolve, reject) => { fs.exists(location, exists => { if (exists) { fs.readFile(location, (err, data) => { if (err) { reject(err); } else { resolve(cheerio.load(data)); } }); } else { reject(); } }); }); } static loadFomData(data) { return cheerio.load(data); } static save(dom, location) { return new Promise((resolve, reject) => { fs.writeFile(location, dom.xml(), null, e => { if (e) reject(e); else resolve(); }); }); } } exports.AnaysisResultsUtil = AnaysisResultsUtil; class AnalysisResults { constructor(dom, summary) { this.dom = dom; this.summary = summary; } getHints() { const hints = []; this.dom('hints').children().each((i, ele) => { const id = modelService_1.RhamtModelService.generateUniqueId(); const hint = { id, quickfixes: this.getQuickfixes(ele), file: '', severity: '', ruleId: '', effort: '', title: '', messageOrDescription: '', links: [], report: '', originalLineSource: '', lineNumber: 0, column: 0, length: 0, sourceSnippet: '' }; ele.children.forEach((child, i) => { switch (child.name) { case 'column': { hint.column = Number(child.children[0].nodeValue); break; } case 'title': { hint.title = child.children[0].nodeValue; break; } case 'message': { hint.messageOrDescription = child.children[0].nodeValue; break; } case 'effort': { hint.effort = child.children[0].nodeValue; break; } case 'file': { hint.file = child.children[0].nodeValue; break; } case 'hint': { hint.messageOrDescription = child.children[0].nodeValue; break; } case 'issue-category': { break; } case 'links': { break; } case 'quickfixes': { break; } case 'rule-id': { hint.ruleId = child.children[0].nodeValue; break; } } }); hints.push(hint); }); return hints; } getQuickfixes(ele) { const quickfixes = []; return quickfixes; } getClassifications() { const classifications = []; this.dom('classifications').children().each((i, ele) => { const id = modelService_1.RhamtModelService.generateUniqueId(); const classification = { id, quickfixes: this.getQuickfixes(ele), file: '', severity: '', ruleId: '', effort: '', title: id, messageOrDescription: '', links: [], report: '', description: '' }; ele.children.forEach((child, i) => { switch (child.name) { case 'classification': { classification.title = child.children[0].nodeValue; break; } case 'description': { classification.description = child.children[0].nodeValue; break; } case 'effort': { classification.effort = child.children[0].nodeValue; break; } case 'file': { classification.file = child.children[0].nodeValue; break; } case 'issue-category': { break; } case 'links': { break; } case 'quickfixes': { break; } case 'rule-id': { classification.ruleId = child.children[0].nodeValue; break; } } }); classifications.push(classification); }); return classifications; } deleteIssue(name) { return false; } markAsFixed(name) { return false; } } exports.AnalysisResults = AnalysisResults; //# sourceMappingURL=analysisResults.js.map