@abaplint/core 2.93.0 → 2.93.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,17 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ParserError = exports.ParserErrorConf = void 0;
4
4
  const issue_1 = require("../issue");
5
5
  const _statement_1 = require("../abap/2_statements/statements/_statement");
6
- const _abap_rule_1 = require("./_abap_rule");
7
6
  const _basic_rule_config_1 = require("./_basic_rule_config");
8
7
  const statement_parser_1 = require("../abap/2_statements/statement_parser");
9
8
  const _irule_1 = require("./_irule");
10
9
  const version_1 = require("../version");
10
+ const _abap_object_1 = require("../objects/_abap_object");
11
11
  class ParserErrorConf extends _basic_rule_config_1.BasicRuleConfig {
12
12
  }
13
13
  exports.ParserErrorConf = ParserErrorConf;
14
- class ParserError extends _abap_rule_1.ABAPRule {
14
+ class ParserError {
15
15
  constructor() {
16
- super(...arguments);
17
16
  this.conf = new ParserErrorConf();
18
17
  }
19
18
  getMetadata() {
@@ -26,36 +25,45 @@ See recognized syntax at https://syntax.abaplint.org`,
26
25
  tags: [_irule_1.RuleTag.Syntax, _irule_1.RuleTag.SingleFile],
27
26
  };
28
27
  }
28
+ initialize(reg) {
29
+ this.reg = reg;
30
+ return this;
31
+ }
29
32
  getConfig() {
30
33
  return this.conf;
31
34
  }
32
35
  setConfig(conf) {
33
36
  this.conf = conf;
34
37
  }
35
- runParsed(file) {
38
+ run(obj) {
36
39
  const issues = [];
37
- for (const statement of file.getStatements()) {
38
- if (!(statement.get() instanceof _statement_1.Unknown)) {
39
- continue;
40
- }
41
- if (statement.getTokens().length > statement_parser_1.STATEMENT_MAX_TOKENS) {
42
- const message = "Statement too long, refactor statement";
43
- const issue = issue_1.Issue.atToken(file, statement.getTokens()[0], message, this.getMetadata().key, this.conf.severity);
44
- issues.push(issue);
45
- }
46
- else {
47
- const tok = statement.getFirstToken();
48
- const message = "Statement does not exist in ABAP" + this.reg.getConfig().getVersion() + "(or a parser error), \"" + tok.getStr() + "\"";
49
- const issue = issue_1.Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity);
50
- issues.push(issue);
51
- }
52
- }
53
- if (this.reg.getConfig().getVersion() === version_1.Version.v700) {
54
- for (const statement of file.getStatements()) {
55
- if (statement.getPragmas().length > 0) {
56
- const message = "Pragmas not allowed in v700";
57
- const issue = issue_1.Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity);
58
- issues.push(issue);
40
+ issues.push(...obj.getParsingIssues());
41
+ if (obj instanceof _abap_object_1.ABAPObject) {
42
+ for (const file of obj.getABAPFiles()) {
43
+ for (const statement of file.getStatements()) {
44
+ if (!(statement.get() instanceof _statement_1.Unknown)) {
45
+ continue;
46
+ }
47
+ if (statement.getTokens().length > statement_parser_1.STATEMENT_MAX_TOKENS) {
48
+ const message = "Statement too long, refactor statement";
49
+ const issue = issue_1.Issue.atToken(file, statement.getTokens()[0], message, this.getMetadata().key, this.conf.severity);
50
+ issues.push(issue);
51
+ }
52
+ else {
53
+ const tok = statement.getFirstToken();
54
+ const message = "Statement does not exist in ABAP" + this.reg.getConfig().getVersion() + "(or a parser error), \"" + tok.getStr() + "\"";
55
+ const issue = issue_1.Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity);
56
+ issues.push(issue);
57
+ }
58
+ }
59
+ if (this.reg.getConfig().getVersion() === version_1.Version.v700) {
60
+ for (const statement of file.getStatements()) {
61
+ if (statement.getPragmas().length > 0) {
62
+ const message = "Pragmas not allowed in v700";
63
+ const issue = issue_1.Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity);
64
+ issues.push(issue);
65
+ }
66
+ }
59
67
  }
60
68
  }
61
69
  }
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RulesRunner = void 0;
4
+ const syntax_1 = require("./abap/5_syntax/syntax");
5
+ const artifacts_rules_1 = require("./artifacts_rules");
6
+ const _abap_object_1 = require("./objects/_abap_object");
7
+ const skip_logic_1 = require("./skip_logic");
8
+ const excludeHelper_1 = require("./utils/excludeHelper");
9
+ class RulesRunner {
10
+ constructor(reg) {
11
+ this.reg = reg;
12
+ }
13
+ objectsToCheck(objects) {
14
+ const check = [];
15
+ const skipLogic = new skip_logic_1.SkipLogic(this.reg);
16
+ for (const obj of objects) {
17
+ if (skipLogic.skip(obj) || this.reg.isDependency(obj)) {
18
+ continue;
19
+ }
20
+ check.push(obj);
21
+ }
22
+ return check;
23
+ }
24
+ runRules(objects, input) {
25
+ var _a, _b, _c, _d, _e, _f;
26
+ const rulePerformance = {};
27
+ const issues = [];
28
+ const rules = this.reg.getConfig().getEnabledRules();
29
+ const check = this.objectsToCheck(objects);
30
+ // note: SyntaxLogic is cached, logic is run as first step in order
31
+ // not to penalize the performance of the first rule using SyntaxLogic information
32
+ (_a = input === null || input === void 0 ? void 0 : input.progress) === null || _a === void 0 ? void 0 : _a.set(check.length, "Run Syntax");
33
+ for (const obj of check) {
34
+ (_b = input === null || input === void 0 ? void 0 : input.progress) === null || _b === void 0 ? void 0 : _b.tick("Run Syntax - " + obj.getName());
35
+ if (obj instanceof _abap_object_1.ABAPObject) {
36
+ new syntax_1.SyntaxLogic(this.reg, obj).run();
37
+ }
38
+ }
39
+ (_c = input === null || input === void 0 ? void 0 : input.progress) === null || _c === void 0 ? void 0 : _c.set(rules.length, "Initialize Rules");
40
+ for (const rule of rules) {
41
+ (_d = input === null || input === void 0 ? void 0 : input.progress) === null || _d === void 0 ? void 0 : _d.tick("Initialize Rules - " + rule.getMetadata().key);
42
+ if (rule.initialize === undefined) {
43
+ throw new Error(rule.getMetadata().key + " missing initialize method");
44
+ }
45
+ rule.initialize(this.reg);
46
+ rulePerformance[rule.getMetadata().key] = 0;
47
+ }
48
+ (_e = input === null || input === void 0 ? void 0 : input.progress) === null || _e === void 0 ? void 0 : _e.set(check.length, "Finding Issues");
49
+ for (const obj of check) {
50
+ (_f = input === null || input === void 0 ? void 0 : input.progress) === null || _f === void 0 ? void 0 : _f.tick("Finding Issues - " + obj.getType() + " " + obj.getName());
51
+ for (const rule of rules) {
52
+ const before = Date.now();
53
+ issues.push(...rule.run(obj));
54
+ const runtime = Date.now() - before;
55
+ rulePerformance[rule.getMetadata().key] = rulePerformance[rule.getMetadata().key] + runtime;
56
+ }
57
+ }
58
+ if ((input === null || input === void 0 ? void 0 : input.outputPerformance) === true) {
59
+ const perf = [];
60
+ for (const p in rulePerformance) {
61
+ if (rulePerformance[p] > 100) { // ignore rules if it takes less than 100ms
62
+ perf.push({ name: p, time: rulePerformance[p] });
63
+ }
64
+ }
65
+ perf.sort((a, b) => { return b.time - a.time; });
66
+ for (const p of perf) {
67
+ process.stderr.write("\t" + p.time + "ms\t" + p.name + "\n");
68
+ }
69
+ }
70
+ return this.excludeIssues(issues);
71
+ }
72
+ excludeIssues(issues) {
73
+ var _a;
74
+ const ret = issues;
75
+ const globalNoIssues = this.reg.getConfig().getGlobal().noIssues || [];
76
+ const globalNoIssuesPatterns = globalNoIssues.map(x => new RegExp(x, "i"));
77
+ if (globalNoIssuesPatterns.length > 0) {
78
+ for (let i = ret.length - 1; i >= 0; i--) {
79
+ const filename = ret[i].getFilename();
80
+ if (excludeHelper_1.ExcludeHelper.isExcluded(filename, globalNoIssuesPatterns)) {
81
+ ret.splice(i, 1);
82
+ }
83
+ }
84
+ }
85
+ // exclude issues, as now we know both the filename and issue key
86
+ for (const rule of artifacts_rules_1.ArtifactsRules.getRules()) {
87
+ const key = rule.getMetadata().key;
88
+ const ruleExclude = (_a = this.reg.getConfig().readByKey(key, "exclude")) !== null && _a !== void 0 ? _a : [];
89
+ if (ruleExclude.length === 0) {
90
+ continue;
91
+ }
92
+ const ruleExcludePatterns = ruleExclude.map(x => new RegExp(x, "i"));
93
+ for (let i = ret.length - 1; i >= 0; i--) {
94
+ if (ret[i].getKey() !== key) {
95
+ continue;
96
+ }
97
+ const filename = ret[i].getFilename();
98
+ if (excludeHelper_1.ExcludeHelper.isExcluded(filename, ruleExcludePatterns)) {
99
+ ret.splice(i, 1);
100
+ }
101
+ }
102
+ }
103
+ return ret;
104
+ }
105
+ }
106
+ exports.RulesRunner = RulesRunner;
107
+ //# sourceMappingURL=rules_runner.js.map