Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11816x 11816x 11816x 11816x 11816x 46855x 46855x 46855x 46855x 46855x 46855x 46855x 46855x 46855x 11816x 11816x 11279x 11279x 11816x 11816x 253x 253x 11816x 11816x 279x 279x 12x 12x 267x 267x 267x 267x 279x 9x 9x 9x 9x 5x 5x 4x 4x 4x 267x 267x 267x 11816x 11816x | import {Issue} from "../issue";
import {ABAPRule} from "./_abap_rule";
import * as Expressions from "../abap/2_statements/expressions";
import * as Statements from "../abap/2_statements/statements";
import {BasicRuleConfig} from "./_basic_rule_config";
import {IRuleMetadata, RuleTag} from "./_irule";
import {ABAPFile} from "../abap/abap_file";
import {ABAPObject} from "../objects/_abap_object";
export class UseMessageClassConf extends BasicRuleConfig {
}
export class UseMessageClass extends ABAPRule {
private conf = new UseMessageClassConf();
public getMetadata(): IRuleMetadata {
return {
key: "use_message_class",
title: "Use message class",
shortDescription: `Define messages in SE91 instead of using inline text or variables`,
tags: [RuleTag.Styleguide, RuleTag.SingleFile],
badExample: `MESSAGE 'Something went wrong' TYPE 'E'.`,
goodExample: `MESSAGE e001(bc_msg).`,
};
}
public getConfig() {
return this.conf;
}
public setConfig(conf: UseMessageClassConf) {
this.conf = conf;
}
public runParsed(file: ABAPFile, _obj: ABAPObject): Issue[] {
const structure = file.getStructure();
if (structure === undefined) {
return [];
}
const issues: Issue[] = [];
const key = this.getMetadata().key;
for (const statement of structure.findAllStatements(Statements.Message)) {
// The parser populates MessageSource only for the class-based forms (e001(bc_msg) or ID/TYPE/NUMBER).
// The text form (MESSAGE <source> TYPE <source>) uses MessageSourceSource directly with no MessageSource child.
// Absence of MessageSource is therefore a reliable discriminator between the two forms.
if (statement.findDirectExpression(Expressions.MessageSource) !== undefined) {
continue;
}
issues.push(Issue.atStatement(file, statement, "Use a message class (SE91) instead of inline text or variable", key, this.conf.severity));
}
return issues;
}
}
|