@abaplint/core 2.104.6 → 2.105.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.
package/build/src/registry.js
CHANGED
package/build/src/rules/index.js
CHANGED
|
@@ -108,6 +108,7 @@ __exportStar(require("./no_aliases"), exports);
|
|
|
108
108
|
__exportStar(require("./no_chained_assignment"), exports);
|
|
109
109
|
__exportStar(require("./no_external_form_calls"), exports);
|
|
110
110
|
__exportStar(require("./no_inline_in_optional_branches"), exports);
|
|
111
|
+
__exportStar(require("./no_prefixes"), exports);
|
|
111
112
|
__exportStar(require("./no_public_attributes"), exports);
|
|
112
113
|
__exportStar(require("./no_yoda_conditions"), exports);
|
|
113
114
|
__exportStar(require("./nrob_consistency"), exports);
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NoPrefixes = exports.NoPrefixesConf = void 0;
|
|
4
|
+
const issue_1 = require("../issue");
|
|
5
|
+
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
6
|
+
const _abap_rule_1 = require("./_abap_rule");
|
|
7
|
+
const Expressions = require("../abap/2_statements/expressions");
|
|
8
|
+
const Statements = require("../abap/2_statements/statements");
|
|
9
|
+
const _irule_1 = require("./_irule");
|
|
10
|
+
class NoPrefixesConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
/** DATA, CLASS-DATA, DATA BEGIN OF, CLASS-DATA BEGIN OF, FINAL(), DATA(), case insensitive regex */
|
|
14
|
+
this.data = "^[lg]._";
|
|
15
|
+
/** STATICS, STATICS BEGIN OF, case insensitive regex */
|
|
16
|
+
this.statics = "";
|
|
17
|
+
/** FIELD-SYMBOLS and inline FIELD-SYMBOLS(), case insensitive regex */
|
|
18
|
+
this.fieldSymbols = "^<l._";
|
|
19
|
+
/** CONSTANTS, CONSTANTS BEGIN OF, case insensitive regex */
|
|
20
|
+
this.constants = "^[lg]c_";
|
|
21
|
+
/** TYPES, ENUM, MESH, case insensitive regex */
|
|
22
|
+
this.types = "^ty_";
|
|
23
|
+
/** importing, exporting, returning and changing parameters, case insensitive regex */
|
|
24
|
+
this.methodParameters = "^[ierc]._";
|
|
25
|
+
// todo, public localClass: string = "";
|
|
26
|
+
// todo, public localInterface: string = "";
|
|
27
|
+
// todo, public functionModuleParameters: string = "";
|
|
28
|
+
// todo, public parameters: string = "";
|
|
29
|
+
// todo, public selectOptions: string = "";
|
|
30
|
+
// todo, public formParameters: string = "";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.NoPrefixesConf = NoPrefixesConf;
|
|
34
|
+
const MESSAGE = "Avoid hungarian notation";
|
|
35
|
+
class NoPrefixes extends _abap_rule_1.ABAPRule {
|
|
36
|
+
constructor() {
|
|
37
|
+
super(...arguments);
|
|
38
|
+
this.conf = new NoPrefixesConf();
|
|
39
|
+
}
|
|
40
|
+
getMetadata() {
|
|
41
|
+
return {
|
|
42
|
+
key: "no_prefixes",
|
|
43
|
+
title: "No Prefixes",
|
|
44
|
+
shortDescription: `Dont use hungarian notation`,
|
|
45
|
+
extendedInformation: `
|
|
46
|
+
https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#avoid-encodings-esp-hungarian-notation-and-prefixes
|
|
47
|
+
|
|
48
|
+
https://github.com/SAP/styleguides/blob/main/clean-abap/sub-sections/AvoidEncodings.md`,
|
|
49
|
+
tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Styleguide],
|
|
50
|
+
badExample: `DATA lv_foo TYPE i.`,
|
|
51
|
+
goodExample: `DATA foo TYPE i.`,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
getConfig() {
|
|
55
|
+
return this.conf;
|
|
56
|
+
}
|
|
57
|
+
setConfig(conf) {
|
|
58
|
+
this.conf = conf;
|
|
59
|
+
}
|
|
60
|
+
runParsed(file) {
|
|
61
|
+
const ret = [];
|
|
62
|
+
const config = this.getConfig();
|
|
63
|
+
const structure = file.getStructure();
|
|
64
|
+
if (structure === undefined) {
|
|
65
|
+
// syntax error, skip
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
if (config.data !== undefined && config.data !== "") {
|
|
69
|
+
ret.push(...this.checkData(structure, new RegExp(config.data, "i"), file));
|
|
70
|
+
}
|
|
71
|
+
if (config.statics !== undefined && config.statics !== "") {
|
|
72
|
+
ret.push(...this.checkStatics(structure, new RegExp(config.statics, "i"), file));
|
|
73
|
+
}
|
|
74
|
+
if (config.fieldSymbols !== undefined && config.fieldSymbols !== "") {
|
|
75
|
+
ret.push(...this.checkFieldSymbols(structure, new RegExp(config.fieldSymbols, "i"), file));
|
|
76
|
+
}
|
|
77
|
+
if (config.constants !== undefined && config.constants !== "") {
|
|
78
|
+
ret.push(...this.checkConstants(structure, new RegExp(config.constants, "i"), file));
|
|
79
|
+
}
|
|
80
|
+
if (config.types !== undefined && config.types !== "") {
|
|
81
|
+
ret.push(...this.checkTypes(structure, new RegExp(config.types, "i"), file));
|
|
82
|
+
}
|
|
83
|
+
if (config.methodParameters !== undefined && config.methodParameters !== "") {
|
|
84
|
+
ret.push(...this.checkMethodParameters(structure, new RegExp(config.methodParameters, "i"), file));
|
|
85
|
+
}
|
|
86
|
+
return ret;
|
|
87
|
+
}
|
|
88
|
+
checkData(topNode, regex, file) {
|
|
89
|
+
var _a, _b, _c;
|
|
90
|
+
const ret = [];
|
|
91
|
+
for (const data of topNode.findAllStatements(Statements.Data).concat(topNode.findAllStatements(Statements.DataBegin)).concat(topNode.findAllStatements(Statements.ClassDataBegin)).concat(topNode.findAllStatements(Statements.ClassData))) {
|
|
92
|
+
let name = ((_a = data.findFirstExpression(Expressions.DefinitionName)) === null || _a === void 0 ? void 0 : _a.concatTokens()) || "";
|
|
93
|
+
if (name === "") {
|
|
94
|
+
name = ((_b = data.findFirstExpression(Expressions.NamespaceSimpleName)) === null || _b === void 0 ? void 0 : _b.concatTokens()) || "";
|
|
95
|
+
}
|
|
96
|
+
if (name !== "" && name.match(regex)) {
|
|
97
|
+
const issue = issue_1.Issue.atToken(file, data.getFirstToken(), MESSAGE, this.getMetadata().key, this.conf.severity);
|
|
98
|
+
ret.push(issue);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
for (const data of topNode.findAllExpressions(Expressions.InlineData)) {
|
|
102
|
+
const name = ((_c = data.findFirstExpression(Expressions.TargetField)) === null || _c === void 0 ? void 0 : _c.concatTokens()) || "";
|
|
103
|
+
if (name !== "" && name.match(regex)) {
|
|
104
|
+
const issue = issue_1.Issue.atToken(file, data.getFirstToken(), MESSAGE, this.getMetadata().key, this.conf.severity);
|
|
105
|
+
ret.push(issue);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return ret;
|
|
109
|
+
}
|
|
110
|
+
checkStatics(topNode, regex, file) {
|
|
111
|
+
var _a;
|
|
112
|
+
const ret = [];
|
|
113
|
+
for (const data of topNode.findAllStatements(Statements.Static).concat(topNode.findAllStatements(Statements.StaticBegin))) {
|
|
114
|
+
const name = ((_a = data.findFirstExpression(Expressions.DefinitionName)) === null || _a === void 0 ? void 0 : _a.concatTokens()) || "";
|
|
115
|
+
if (name !== "" && name.match(regex)) {
|
|
116
|
+
const issue = issue_1.Issue.atToken(file, data.getFirstToken(), MESSAGE, this.getMetadata().key, this.conf.severity);
|
|
117
|
+
ret.push(issue);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return ret;
|
|
121
|
+
}
|
|
122
|
+
checkFieldSymbols(topNode, regex, file) {
|
|
123
|
+
var _a, _b;
|
|
124
|
+
const ret = [];
|
|
125
|
+
for (const data of topNode.findAllStatements(Statements.FieldSymbol)) {
|
|
126
|
+
const name = ((_a = data.findFirstExpression(Expressions.FieldSymbol)) === null || _a === void 0 ? void 0 : _a.concatTokens()) || "";
|
|
127
|
+
if (name !== "" && name.match(regex)) {
|
|
128
|
+
const issue = issue_1.Issue.atToken(file, data.getFirstToken(), MESSAGE, this.getMetadata().key, this.conf.severity);
|
|
129
|
+
ret.push(issue);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
for (const data of topNode.findAllExpressions(Expressions.InlineFS)) {
|
|
133
|
+
const name = ((_b = data.findFirstExpression(Expressions.FieldSymbol)) === null || _b === void 0 ? void 0 : _b.concatTokens()) || "";
|
|
134
|
+
if (name !== "" && name.match(regex)) {
|
|
135
|
+
const issue = issue_1.Issue.atToken(file, data.getFirstToken(), MESSAGE, this.getMetadata().key, this.conf.severity);
|
|
136
|
+
ret.push(issue);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return ret;
|
|
140
|
+
}
|
|
141
|
+
checkConstants(topNode, regex, file) {
|
|
142
|
+
var _a;
|
|
143
|
+
const ret = [];
|
|
144
|
+
for (const data of topNode.findAllStatements(Statements.Constant).concat(topNode.findAllStatements(Statements.ConstantBegin))) {
|
|
145
|
+
const name = ((_a = data.findFirstExpression(Expressions.DefinitionName)) === null || _a === void 0 ? void 0 : _a.concatTokens()) || "";
|
|
146
|
+
if (name !== "" && name.match(regex)) {
|
|
147
|
+
const issue = issue_1.Issue.atToken(file, data.getFirstToken(), MESSAGE, this.getMetadata().key, this.conf.severity);
|
|
148
|
+
ret.push(issue);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return ret;
|
|
152
|
+
}
|
|
153
|
+
checkTypes(topNode, regex, file) {
|
|
154
|
+
var _a;
|
|
155
|
+
const ret = [];
|
|
156
|
+
for (const data of topNode.findAllStatements(Statements.Type).concat(topNode.findAllStatements(Statements.TypeEnum)).concat(topNode.findAllStatements(Statements.TypeEnumBegin)).concat(topNode.findAllStatements(Statements.TypeMesh)).concat(topNode.findAllStatements(Statements.TypeMeshBegin)).concat(topNode.findAllStatements(Statements.TypeBegin))) {
|
|
157
|
+
const name = ((_a = data.findFirstExpression(Expressions.NamespaceSimpleName)) === null || _a === void 0 ? void 0 : _a.concatTokens()) || "";
|
|
158
|
+
if (name !== "" && name.match(regex)) {
|
|
159
|
+
const issue = issue_1.Issue.atToken(file, data.getFirstToken(), MESSAGE, this.getMetadata().key, this.conf.severity);
|
|
160
|
+
ret.push(issue);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return ret;
|
|
164
|
+
}
|
|
165
|
+
checkMethodParameters(topNode, regex, file) {
|
|
166
|
+
const ret = [];
|
|
167
|
+
for (const method of topNode.findAllStatements(Statements.MethodDef)) {
|
|
168
|
+
for (const def of method.findAllExpressions(Expressions.MethodParamName)) {
|
|
169
|
+
const name = def.concatTokens();
|
|
170
|
+
if (name !== "" && name.match(regex)) {
|
|
171
|
+
const issue = issue_1.Issue.atToken(file, method.getFirstToken(), MESSAGE, this.getMetadata().key, this.conf.severity);
|
|
172
|
+
ret.push(issue);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return ret;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
exports.NoPrefixes = NoPrefixes;
|
|
180
|
+
//# sourceMappingURL=no_prefixes.js.map
|