UNPKG

@abaplint/core

Version:
82 lines (78 loc) 3.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GlobalClass = exports.GlobalClassConf = void 0; const issue_1 = require("../issue"); const _abap_rule_1 = require("./_abap_rule"); const Objects = require("../objects"); const _basic_rule_config_1 = require("./_basic_rule_config"); const _irule_1 = require("./_irule"); class GlobalClassConf extends _basic_rule_config_1.BasicRuleConfig { } exports.GlobalClassConf = GlobalClassConf; class GlobalClass extends _abap_rule_1.ABAPRule { constructor() { super(...arguments); this.conf = new GlobalClassConf(); } getMetadata() { return { key: "global_class", title: "Global class checks", shortDescription: `Checks related to global classes`, extendedInformation: `* global classes must be in own files * file names must match class name * file names must match interface name * global classes must be global definitions * global interfaces must be global definitions`, tags: [_irule_1.RuleTag.Syntax], }; } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } runParsed(file, obj) { const output = []; for (const definition of file.getInfo().listClassDefinitions()) { if (definition.isLocal && obj instanceof Objects.Class && file.getFilename().match(/\.clas\.abap$/)) { const issue = issue_1.Issue.atIdentifier(definition.identifier, "Global classes must be global", this.getMetadata().key, this.conf.severity); output.push(issue); } if (definition.isGlobal && obj instanceof Objects.Class && definition.name.toUpperCase() !== obj.getName().toUpperCase()) { const issue = issue_1.Issue.atIdentifier(definition.identifier, "Class definition name must match filename", this.getMetadata().key, this.conf.severity); output.push(issue); } if (definition.isGlobal && !(obj instanceof Objects.Class)) { const issue = issue_1.Issue.atIdentifier(definition.identifier, "Class must be local", this.getMetadata().key, this.conf.severity); output.push(issue); } } for (const impl of file.getInfo().listClassImplementations()) { if (file.getFilename().match(/\.clas\.abap$/) && obj instanceof Objects.Class && impl.identifier.getName().toUpperCase() !== obj.getName().toUpperCase()) { const issue = issue_1.Issue.atIdentifier(impl.identifier, "Class implementation name must match filename", this.getMetadata().key, this.conf.severity); output.push(issue); } } for (const impl of file.getInfo().listInterfaceDefinitions()) { if (file.getFilename().match(/\.intf\.abap$/) && obj instanceof Objects.Interface && impl.identifier.getName().toUpperCase() !== obj.getName().toUpperCase()) { const issue = issue_1.Issue.atIdentifier(impl.identifier, "Interface implementation name must match filename", this.getMetadata().key, this.conf.severity); output.push(issue); } } for (const intf of file.getInfo().listInterfaceDefinitions()) { if (intf.isLocal && obj instanceof Objects.Interface && file.getFilename().match(/\.intf\.abap$/)) { const issue = issue_1.Issue.atIdentifier(intf.identifier, "Global interface must be global", this.getMetadata().key, this.conf.severity); output.push(issue); } } return output; } } exports.GlobalClass = GlobalClass; //# sourceMappingURL=global_class.js.map