@abaplint/core
Version:
abaplint - Core API
94 lines • 4.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MSAGConsistency = exports.MSAGConsistencyConf = void 0;
const issue_1 = require("../issue");
const _basic_rule_config_1 = require("./_basic_rule_config");
const objects_1 = require("../objects");
const position_1 = require("../position");
class MSAGConsistencyConf extends _basic_rule_config_1.BasicRuleConfig {
constructor() {
super(...arguments);
/** parameters must be numbered */
this.numericParameters = true;
}
}
exports.MSAGConsistencyConf = MSAGConsistencyConf;
class MSAGConsistency {
constructor() {
this.conf = new MSAGConsistencyConf();
}
getMetadata() {
return {
key: "msag_consistency",
title: "MSAG consistency check",
shortDescription: `Checks the validity of messages in message classes`,
extendedInformation: `Message numbers must be 3 digits, message text must not be empty, no message number duplicates`,
};
}
getDescription(reason) {
return "Message class invalid: " + reason;
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
initialize(_reg) {
return this;
}
run(obj) {
const issues = [];
if (!(obj instanceof objects_1.MessageClass)) {
return [];
}
const numbers = new Set();
for (const message of obj.getMessages()) {
// todo, get the right positions in xml file, and report the issue there
if (!message.getNumber().match(/\d\d\d/)) {
const text = this.getDescription("Message number must be 3 digits: message " + message.getNumber());
const position = new position_1.Position(1, 1);
const issue = issue_1.Issue.atPosition(obj.getFiles()[0], position, text, this.getMetadata().key, this.conf.severity);
issues.push(issue);
}
if (message.getMessage() === "") {
const text = "Message text empty: message " + message.getNumber();
const position = new position_1.Position(1, 1);
const issue = issue_1.Issue.atPosition(obj.getFiles()[0], position, text, this.getMetadata().key, this.conf.severity);
issues.push(issue);
}
const num = message.getNumber();
if (numbers.has(num)) {
const text = "Duplicate message number " + num;
const position = new position_1.Position(1, 1);
const issue = issue_1.Issue.atPosition(obj.getFiles()[0], position, text, this.getMetadata().key, this.conf.severity);
issues.push(issue);
}
else {
numbers.add(num);
}
if (this.getConfig().numericParameters === true) {
const placeholderCount = message.getPlaceholderCount();
if (placeholderCount > 4) {
const text = `More than 4 placeholders in mesasge ${message.getNumber()}`;
const position = new position_1.Position(1, 1);
const issue = issue_1.Issue.atPosition(obj.getFiles()[0], position, text, this.getMetadata().key, this.conf.severity);
issues.push(issue);
}
for (let i = 1; i <= placeholderCount; i++) {
const placeholder = "&" + i;
if (message.getMessage().includes(placeholder) === false) {
const text = `Expected placeholder ${placeholder} in message ${message.getNumber()}`;
const position = new position_1.Position(1, 1);
const issue = issue_1.Issue.atPosition(obj.getFiles()[0], position, text, this.getMetadata().key, this.conf.severity);
issues.push(issue);
break;
}
}
}
}
return issues;
}
}
exports.MSAGConsistency = MSAGConsistency;
//# sourceMappingURL=msag_consistency.js.map