@abaplint/core
Version:
abaplint - Core API
82 lines • 3.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.XMLConsistency = exports.XMLConsistencyConf = void 0;
const issue_1 = require("../issue");
const _irule_1 = require("./_irule");
const Objects = require("../objects");
const _basic_rule_config_1 = require("./_basic_rule_config");
const fast_xml_parser_1 = require("fast-xml-parser");
class XMLConsistencyConf extends _basic_rule_config_1.BasicRuleConfig {
}
exports.XMLConsistencyConf = XMLConsistencyConf;
class XMLConsistency {
constructor() {
this.conf = new XMLConsistencyConf();
}
getMetadata() {
return {
key: "xml_consistency",
title: "XML consistency",
shortDescription: `Checks the consistency of main XML files, eg. naming for CLAS and INTF objects`,
tags: [_irule_1.RuleTag.Naming, _irule_1.RuleTag.Syntax],
};
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
initialize(_reg) {
return this;
}
run(obj) {
var _a, _b;
const issues = [];
const file = obj.getXMLFile();
if (file === undefined) {
return issues;
}
const xml = obj.getXML();
if (xml) {
const res = fast_xml_parser_1.XMLValidator.validate(xml);
if (res !== true) {
issues.push(issue_1.Issue.atRow(file, 1, "XML parser error: " + res.err.msg, this.getMetadata().key, this.conf.severity));
}
}
// todo, have some XML validation in each object?
if (obj instanceof Objects.Class) {
const name = obj.getNameFromXML();
if (name === undefined) {
issues.push(issue_1.Issue.atRow(file, 1, "Name undefined in XML", this.getMetadata().key, this.conf.severity));
}
else if (obj.getDescription() && obj.getDescription().length > 60) {
issues.push(issue_1.Issue.atRow(file, 1, "Description too long", this.getMetadata().key, this.conf.severity));
}
else if (name !== obj.getName().toUpperCase()) {
issues.push(issue_1.Issue.atRow(file, 1, "Name in XML does not match object", this.getMetadata().key, this.conf.severity));
}
else if (((_a = obj.getMainABAPFile()) === null || _a === void 0 ? void 0 : _a.getStructure()) !== undefined && obj.getClassDefinition() === undefined) {
issues.push(issue_1.Issue.atRow(file, 1, "Class matching XML name not found in ABAP file", this.getMetadata().key, this.conf.severity));
}
}
else if (obj instanceof Objects.Interface) {
const name = obj.getNameFromXML();
if (name === undefined) {
issues.push(issue_1.Issue.atRow(file, 1, "Name undefined in XML", this.getMetadata().key, this.conf.severity));
}
else if (obj.getDescription() && obj.getDescription().length > 60) {
issues.push(issue_1.Issue.atRow(file, 1, "Description too long", this.getMetadata().key, this.conf.severity));
}
else if (name !== obj.getName().toUpperCase()) {
issues.push(issue_1.Issue.atRow(file, 1, "Name in XML does not match object", this.getMetadata().key, this.conf.severity));
}
else if (obj.getDefinition() !== undefined && ((_b = obj.getDefinition()) === null || _b === void 0 ? void 0 : _b.getName().toUpperCase()) !== name.toUpperCase()) {
issues.push(issue_1.Issue.atRow(file, 1, "Interface matching XML name not found in ABAP file", this.getMetadata().key, this.conf.severity));
}
}
return issues;
}
}
exports.XMLConsistency = XMLConsistency;
//# sourceMappingURL=xml_consistency.js.map