UNPKG

@abaplint/core

Version:
108 lines (107 loc) 4.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MainFileContents = exports.MainFileContentsConf = void 0; const issue_1 = require("../issue"); const _basic_rule_config_1 = require("./_basic_rule_config"); const Objects = require("../objects"); const _abap_object_1 = require("../objects/_abap_object"); const Statements = require("../abap/2_statements/statements"); const Expressions = require("../abap/2_statements/expressions"); const position_1 = require("../position"); const _statement_1 = require("../abap/2_statements/statements/_statement"); const version_1 = require("../version"); class MainFileContentsConf extends _basic_rule_config_1.BasicRuleConfig { } exports.MainFileContentsConf = MainFileContentsConf; class MainFileContents { constructor() { this.conf = new MainFileContentsConf(); } getMetadata() { return { key: "main_file_contents", title: "Main file contents", shortDescription: `Checks related to report declarations.`, extendedInformation: `Does not run if the target version is Cloud * PROGs must begin with "REPORT <name>." or "PROGRAM <name>. * TYPEs must begin with "TYPE-POOL <name>." `, }; } getDescription(details) { return "Main file must have specific contents: " + details; } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } initialize(reg) { this.reg = reg; return this; } run(obj) { if (!(obj instanceof _abap_object_1.ABAPObject) || this.reg.getConfig().getVersion() === version_1.Version.Cloud) { return []; } const main = obj.getMainABAPFile(); if (main === undefined) { return []; } const stru = main.getStructure(); if (stru === undefined) { return []; } if (obj instanceof Objects.Program && obj.isInclude() === false && obj.isModulePool() === false) { let count = 0; let first = main.getStatements()[count]; while (first !== undefined && first.get() instanceof _statement_1.Comment) { count = count + 1; first = main.getStatements()[count]; } if (first === undefined || !(first.get() instanceof Statements.Report || first.get() instanceof Statements.Program)) { const position = new position_1.Position(1, 1); const issue = issue_1.Issue.atPosition(main, position, this.getDescription("Report must begin with REPORT or PROGRAM"), this.getMetadata().key, this.conf.severity); return [issue]; } const name = first.findFirstExpression(Expressions.ReportName); if (name === undefined) { const token = first.getFirstToken(); const issue = issue_1.Issue.atToken(main, token, this.getDescription("Add report name to REPORT or PROGRAM statement"), this.getMetadata().key, this.conf.severity); return [issue]; } else if (name.getFirstToken().getStr().toUpperCase() !== obj.getName()) { const token = name.getFirstToken(); const issue = issue_1.Issue.atToken(main, token, this.getDescription("REPORT or PROGRAM name must match filename"), this.getMetadata().key, this.conf.severity); return [issue]; } } else if (obj instanceof Objects.TypePool) { let count = 0; let first = main.getStatements()[count]; while (first !== undefined && first.get() instanceof _statement_1.Comment) { count = count + 1; first = main.getStatements()[count]; } if (first === undefined || !(first.get() instanceof Statements.TypePool)) { const position = new position_1.Position(1, 1); const issue = issue_1.Issue.atPosition(main, position, this.getDescription("Type pool must begin with TYPE-POOL"), this.getMetadata().key, this.conf.severity); return [issue]; } const name = first.getChildren()[3]; if (name.getFirstToken().getStr().toUpperCase() !== obj.getName()) { const token = name.getFirstToken(); const issue = issue_1.Issue.atToken(main, token, this.getDescription("TYPE-POOL name must match filename"), this.getMetadata().key, this.conf.severity); return [issue]; } } return []; } } exports.MainFileContents = MainFileContents; //# sourceMappingURL=main_file_contents.js.map