@abaplint/core
Version:
abaplint - Core API
122 lines (120 loc) • 4.12 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RemoveDescriptions = exports.RemoveDescriptionsConf = void 0;
const issue_1 = require("../issue");
const fast_xml_parser_1 = require("fast-xml-parser");
const Objects = require("../objects");
const _basic_rule_config_1 = require("./_basic_rule_config");
const position_1 = require("../position");
const ddic_1 = require("../ddic");
const xml_utils_1 = require("../xml_utils");
class RemoveDescriptionsConf extends _basic_rule_config_1.BasicRuleConfig {
constructor() {
super(...arguments);
/** Ignore global exception classes */
this.ignoreExceptions = false;
/** Ignore global workflow classes */
this.ignoreWorkflow = true;
}
}
exports.RemoveDescriptionsConf = RemoveDescriptionsConf;
class RemoveDescriptions {
constructor() {
this.conf = new RemoveDescriptionsConf();
}
getMetadata() {
return {
key: "remove_descriptions",
title: "Remove descriptions",
shortDescription: `Ensures you have no descriptions in metadata of methods, parameters, etc.
Class descriptions are required, see rule description_empty.
Consider using ABAP Doc for documentation.`,
tags: [],
};
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
initialize(reg) {
this.reg = reg;
return this;
}
run(obj) {
// plan is omitting knowledge about descriptions in abaplint, so this rule must parse the XML
const ddic = new ddic_1.DDIC(this.reg);
if (obj instanceof Objects.Class) {
let def;
try {
def = obj.getClassDefinition();
}
catch (_a) {
return [];
}
if (def === undefined) {
return [];
}
else if (this.conf.ignoreExceptions && ddic.isException(def, obj)) {
return [];
}
else if (this.conf.ignoreWorkflow === true && def.interfaces.find(e => e.name.toUpperCase() === "IF_WORKFLOW")) {
return [];
}
return this.checkClass(obj);
}
else if (obj instanceof Objects.Interface) {
return this.checkInterface(obj);
}
return [];
}
//////////////
checkInterface(obj) {
const xml = obj.getXML();
if (xml === undefined) {
return [];
}
const file = obj.getXMLFile();
if (file === undefined) {
return [];
}
return this.checkXML(xml, file);
}
checkClass(obj) {
const xml = obj.getXML();
if (xml === undefined) {
return [];
}
const file = obj.getXMLFile();
if (file === undefined) {
return [];
}
return this.checkXML(xml, file);
}
checkXML(xml, file) {
const parsed = new fast_xml_parser_1.XMLParser({ parseTagValue: false, ignoreAttributes: true, trimValues: false }).parse(xml);
if (parsed === undefined || parsed.abapGit["asx:abap"]["asx:values"] === undefined) {
return [];
}
const desc = parsed.abapGit["asx:abap"]["asx:values"].DESCRIPTIONS;
if (desc === undefined) {
return [];
}
const reported = {}; // there might be multiple translations
const ret = [];
for (const d of (0, xml_utils_1.xmlToArray)(desc.SEOCOMPOTX)) {
const message = "Remove description for " + d.CMPNAME;
if (reported[d.CMPNAME] !== undefined) {
continue;
}
const position = new position_1.Position(1, 1);
const issue = issue_1.Issue.atPosition(file, position, message, this.getMetadata().key, this.conf.severity);
ret.push(issue);
reported[d.CMPNAME] = true;
}
return ret;
}
}
exports.RemoveDescriptions = RemoveDescriptions;
//# sourceMappingURL=remove_descriptions.js.map