UNPKG

@abaplint/core

Version:
145 lines 5.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Config = void 0; const version_1 = require("./version"); const artifacts_rules_1 = require("./artifacts_rules"); const JSON5 = require("json5"); // assumption: this class is immutable class Config { static getDefault(ver) { const rules = {}; const sorted = artifacts_rules_1.ArtifactsRules.getRules().sort((a, b) => { return a.getMetadata().key.localeCompare(b.getMetadata().key); }); for (const rule of sorted) { rules[rule.getMetadata().key] = rule.getConfig(); } let version = version_1.defaultVersion; if (ver) { version = ver; } // defaults: dont skip anything, report everything. The user can decide to skip stuff // its difficult to debug errors not being reported const config = { global: { files: "/src/**/*.*", exclude: [], noIssues: [], skipGeneratedBOPFInterfaces: false, skipGeneratedFunctionGroups: false, skipGeneratedGatewayClasses: false, skipGeneratedPersistentClasses: false, skipGeneratedProxyClasses: false, skipGeneratedProxyInterfaces: false, useApackDependencies: false, skipIncludesWithoutMain: false, }, dependencies: [{ url: "https://github.com/abaplint/deps", folder: "/deps", files: "/src/**/*.*", }], syntax: { version, errorNamespace: "^(Z|Y|LCL\_|TY\_|LIF\_)", globalConstants: [], globalMacros: [], }, rules: rules, }; return new Config(JSON.stringify(config)); } getEnabledRules() { var _a; const rules = []; for (const rule of artifacts_rules_1.ArtifactsRules.getRules()) { const ruleConfig = (_a = this.config["rules"]) === null || _a === void 0 ? void 0 : _a[rule.getMetadata().key]; const ruleExists = ruleConfig !== undefined; if (ruleExists) { if (ruleConfig === false) { // "rule": false continue; } else if (ruleConfig === true) { // "rule": true rules.push(rule); } else if (typeof ruleConfig === "object") { // "rule": { ...config } rule.setConfig(ruleConfig); rules.push(rule); } } } return rules; } constructor(json) { // huh, hack if (JSON5.parse === undefined) { // @ts-ignore JSON5.parse = JSON5.default.parse; } this.config = JSON5.parse(json); if (this.config.global === undefined) { this.config.global = Config.getDefault().getGlobal(); } if (this.config.syntax === undefined) { this.config.syntax = Config.getDefault().getSyntaxSetttings(); } if (this.config.syntax.globalMacros === undefined) { this.config.syntax.globalMacros = []; } if (this.config.syntax.globalConstants === undefined) { this.config.syntax.globalConstants = []; } else { // remove duplicates, this.config.syntax.globalConstants = [...new Set(this.config.syntax.globalConstants)]; } if (this.config.global.skipIncludesWithoutMain === undefined) { this.config.global.skipIncludesWithoutMain = false; } this.checkVersion(); } get() { return this.config; } readByKey(rule, key) { if (this.config["rules"]) { return this.config["rules"][rule] ? this.config["rules"][rule][key] : undefined; } else { return undefined; } } readByRule(rule) { return this.config["rules"][rule]; } getGlobal() { return this.config.global; } getSyntaxSetttings() { return this.config.syntax; } getVersion() { if (this.config.global === undefined || this.config.syntax.version === undefined) { return version_1.defaultVersion; } return this.config.syntax.version; } checkVersion() { if (this.config.syntax.version === undefined) { return; // handled in getVersion } let match = false; const vers = version_1.Version; for (const v in version_1.Version) { if (vers[v] === this.config.syntax.version) { match = true; break; } } if (match === false) { this.config.syntax.version = version_1.defaultVersion; } } } exports.Config = Config; //# sourceMappingURL=config.js.map