@abaplint/core
Version:
abaplint - Core API
90 lines (88 loc) • 3.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BeginSingleInclude = exports.BeginSingleIncludeConf = void 0;
const issue_1 = require("../issue");
const _abap_rule_1 = require("./_abap_rule");
const _basic_rule_config_1 = require("./_basic_rule_config");
const Statements = require("../abap/2_statements/statements");
const Structures = require("../abap/3_structures/structures");
const _irule_1 = require("./_irule");
class BeginSingleIncludeConf extends _basic_rule_config_1.BasicRuleConfig {
}
exports.BeginSingleIncludeConf = BeginSingleIncludeConf;
class BeginSingleInclude extends _abap_rule_1.ABAPRule {
constructor() {
super(...arguments);
this.conf = new BeginSingleIncludeConf();
}
getMetadata() {
return {
key: "begin_single_include",
title: "BEGIN contains single INCLUDE",
shortDescription: `Finds TYPE BEGIN with just one INCLUDE TYPE, and DATA with single INCLUDE STRUCTURE`,
tags: [_irule_1.RuleTag.SingleFile],
badExample: `TYPES: BEGIN OF dummy1.
INCLUDE TYPE dselc.
TYPES: END OF dummy1.
DATA BEGIN OF foo.
INCLUDE STRUCTURE syst.
DATA END OF foo.
STATICS BEGIN OF bar.
INCLUDE STRUCTURE syst.
STATICS END OF bar.`,
goodExample: `DATA BEGIN OF foo.
DATA field TYPE i.
INCLUDE STRUCTURE dselc.
DATA END OF foo.`,
};
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
runParsed(file) {
const issues = [];
const stru = file.getStructure();
if (stru === undefined) {
return [];
}
for (const t of stru.findAllStructures(Structures.Types)) {
if (t.getChildren().length !== 3) {
continue;
}
if (t.findFirstStatement(Statements.IncludeType)) {
const token = t.getFirstToken();
const message = "TYPE BEGIN with single INCLUDE";
const issue = issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity);
issues.push(issue);
}
}
for (const t of stru.findAllStructures(Structures.Data)) {
if (t.getChildren().length !== 3) {
continue;
}
if (t.findFirstStatement(Statements.IncludeType)) {
const token = t.getFirstToken();
const message = "DATA BEGIN with single INCLUDE";
const issue = issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity);
issues.push(issue);
}
}
for (const t of stru.findAllStructures(Structures.Statics)) {
if (t.getChildren().length !== 3) {
continue;
}
if (t.findFirstStatement(Statements.IncludeType)) {
const token = t.getFirstToken();
const message = "STATICS BEGIN with single INCLUDE";
const issue = issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity);
issues.push(issue);
}
}
return issues;
}
}
exports.BeginSingleInclude = BeginSingleInclude;
//# sourceMappingURL=begin_single_include.js.map