@abaplint/core 2.81.4 → 2.82.0
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.
|
@@ -6,7 +6,7 @@ const _combi_1 = require("./_combi");
|
|
|
6
6
|
const _statement_1 = require("../../2_statements/statements/_statement");
|
|
7
7
|
class Types {
|
|
8
8
|
getMatcher() {
|
|
9
|
-
return (0, _combi_1.beginEnd)((0, _combi_1.sta)(Statements.TypeBegin), (0, _combi_1.star)((0, _combi_1.alt)((0, _combi_1.sta)(Statements.Type), (0, _combi_1.sub)(Types), (0, _combi_1.sta)(_statement_1.MacroCall), (0, _combi_1.sta)(Statements.IncludeType))), (0, _combi_1.sta)(Statements.TypeEnd));
|
|
9
|
+
return (0, _combi_1.beginEnd)((0, _combi_1.sta)(Statements.TypeBegin), (0, _combi_1.star)((0, _combi_1.alt)((0, _combi_1.sta)(Statements.Type), (0, _combi_1.sub)(Types), (0, _combi_1.sta)(_statement_1.MacroCall), (0, _combi_1.sta)(Statements.Include), (0, _combi_1.sta)(Statements.IncludeType))), (0, _combi_1.sta)(Statements.TypeEnd));
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
exports.Types = Types;
|
package/build/src/registry.js
CHANGED
package/build/src/rules/index.js
CHANGED
|
@@ -124,6 +124,7 @@ __exportStar(require("./space_before_colon"), exports);
|
|
|
124
124
|
__exportStar(require("./space_before_dot"), exports);
|
|
125
125
|
__exportStar(require("./sql_escape_host_variables"), exports);
|
|
126
126
|
__exportStar(require("./start_at_tab"), exports);
|
|
127
|
+
__exportStar(require("./static_call_via_instance"), exports);
|
|
127
128
|
__exportStar(require("./superclass_final"), exports);
|
|
128
129
|
__exportStar(require("./sy_modification"), exports);
|
|
129
130
|
__exportStar(require("./tabl_enhancement_category"), exports);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StaticCallViaInstance = exports.StaticCallViaInstanceConf = void 0;
|
|
4
|
+
/* eslint-disable max-len */
|
|
5
|
+
const issue_1 = require("../issue");
|
|
6
|
+
const _abap_rule_1 = require("./_abap_rule");
|
|
7
|
+
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
8
|
+
const _irule_1 = require("./_irule");
|
|
9
|
+
const syntax_1 = require("../abap/5_syntax/syntax");
|
|
10
|
+
const _reference_1 = require("../abap/5_syntax/_reference");
|
|
11
|
+
const types_1 = require("../abap/types");
|
|
12
|
+
class StaticCallViaInstanceConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
13
|
+
}
|
|
14
|
+
exports.StaticCallViaInstanceConf = StaticCallViaInstanceConf;
|
|
15
|
+
class StaticCallViaInstance extends _abap_rule_1.ABAPRule {
|
|
16
|
+
constructor() {
|
|
17
|
+
super(...arguments);
|
|
18
|
+
this.conf = new StaticCallViaInstanceConf();
|
|
19
|
+
}
|
|
20
|
+
getMetadata() {
|
|
21
|
+
return {
|
|
22
|
+
key: "static_call_via_instance",
|
|
23
|
+
title: "Static call via instance variable",
|
|
24
|
+
shortDescription: `Static method call via instance variable`,
|
|
25
|
+
extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#dont-call-static-methods-through-instance-variables`,
|
|
26
|
+
tags: [_irule_1.RuleTag.Styleguide],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
getConfig() {
|
|
30
|
+
return this.conf;
|
|
31
|
+
}
|
|
32
|
+
setConfig(conf) {
|
|
33
|
+
this.conf = conf;
|
|
34
|
+
}
|
|
35
|
+
runParsed(file, obj) {
|
|
36
|
+
const issues = [];
|
|
37
|
+
const staticMethodCalls = this.listMethodCalls(file.getFilename(), new syntax_1.SyntaxLogic(this.reg, obj).run().spaghetti.getTop());
|
|
38
|
+
const tokens = file.getTokens();
|
|
39
|
+
for (let i = 0; i < tokens.length - 1; i++) {
|
|
40
|
+
const token = tokens[i];
|
|
41
|
+
if (token.getStr() !== "->") {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const next = tokens[i + 1];
|
|
45
|
+
for (const s of staticMethodCalls) {
|
|
46
|
+
if (s.equals(next.getStart())) {
|
|
47
|
+
const message = "Avoid calling static method via instance";
|
|
48
|
+
issue_1.Issue.atToken(file, token, message, this.getMetadata().key);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return issues;
|
|
54
|
+
}
|
|
55
|
+
listMethodCalls(filename, node) {
|
|
56
|
+
const ret = [];
|
|
57
|
+
for (const r of node.getData().references) {
|
|
58
|
+
if (r.referenceType !== _reference_1.ReferenceType.MethodReference || r.position.getFilename() !== filename) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (r.resolved instanceof types_1.MethodDefinition && r.resolved.isStatic() === true) {
|
|
62
|
+
ret.push(r.position.getStart());
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
for (const child of node.getChildren()) {
|
|
66
|
+
ret.push(...this.listMethodCalls(filename, child));
|
|
67
|
+
}
|
|
68
|
+
return ret;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.StaticCallViaInstance = StaticCallViaInstance;
|
|
72
|
+
//# sourceMappingURL=static_call_via_instance.js.map
|