@abaplint/core 2.120.73 → 2.120.75
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/abaplint.d.ts +6 -1
- package/build/src/abap/2_statements/combi.js +143 -51
- package/build/src/abap/2_statements/expressions/method_param_optional.js +3 -1
- package/build/src/abap/5_syntax/basic_types.js +67 -23
- package/build/src/abap/5_syntax/statements/append.js +6 -0
- package/build/src/abap/types/method_definition.js +22 -0
- package/build/src/abap/types/method_parameters.js +57 -0
- package/build/src/ddic.js +1 -1
- package/build/src/objects/data_definition.js +9 -1
- package/build/src/objects/domain.js +4 -1
- package/build/src/registry.js +1 -1
- package/build/src/rules/abapdoc_html_tag.js +123 -0
- package/build/src/rules/abapdoc_leading_at.js +117 -0
- package/build/src/rules/abapdoc_parameter_names.js +149 -0
- package/build/src/rules/cds_check_syntax.js +4 -4
- package/build/src/rules/change_if_to_case.js +3 -2
- package/build/src/rules/changing_sorted_line.js +235 -0
- package/build/src/rules/class_attribute_names.js +15 -6
- package/build/src/rules/delete_index_in_loop.js +163 -0
- package/build/src/rules/final_newline.js +78 -0
- package/build/src/rules/forbidden_identifier.js +4 -3
- package/build/src/rules/forbidden_void_type.js +4 -9
- package/build/src/rules/index.js +11 -0
- package/build/src/rules/inline_packed_computation.js +220 -0
- package/build/src/rules/intf_referencing_clas.js +3 -1
- package/build/src/rules/line_only_punc.js +1 -1
- package/build/src/rules/local_class_naming.js +15 -2
- package/build/src/rules/local_variable_names.js +18 -9
- package/build/src/rules/macro_naming.js +3 -2
- package/build/src/rules/method_parameter_names.js +17 -7
- package/build/src/rules/modify_only_own_db_tables.js +3 -2
- package/build/src/rules/no_exclamation_escape.js +32 -2
- package/build/src/rules/no_prefixes.js +25 -12
- package/build/src/rules/object_naming.js +18 -3
- package/build/src/rules/prefer_inline_cast.js +276 -0
- package/build/src/rules/range_row_values.js +200 -0
- package/build/src/rules/selection_screen_naming.js +21 -2
- package/build/src/rules/sicf_consistency.js +1 -2
- package/build/src/rules/sort_empty_key.js +188 -0
- package/build/src/rules/subrc_after_assign.js +220 -0
- package/build/src/rules/types_naming.js +3 -2
- package/build/src/rules/wrong_abapdoc_position.js +58 -11
- package/build/src/rules/xml_consistency.js +6 -2
- package/build/src/utils/name_validator.js +7 -3
- package/package.json +1 -1
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.SortEmptyKey = exports.SortEmptyKeyConf = void 0;
|
|
37
|
+
const Expressions = __importStar(require("../abap/2_statements/expressions"));
|
|
38
|
+
const Statements = __importStar(require("../abap/2_statements/statements"));
|
|
39
|
+
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
40
|
+
const issue_1 = require("../issue");
|
|
41
|
+
const _irule_1 = require("./_irule");
|
|
42
|
+
const syntax_1 = require("../abap/5_syntax/syntax");
|
|
43
|
+
const _abap_object_1 = require("../objects/_abap_object");
|
|
44
|
+
const basic_1 = require("../abap/types/basic");
|
|
45
|
+
const _typed_identifier_1 = require("../abap/types/_typed_identifier");
|
|
46
|
+
const tokens_1 = require("../abap/1_lexer/tokens");
|
|
47
|
+
const edit_helper_1 = require("../edit_helper");
|
|
48
|
+
class SortEmptyKeyConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
49
|
+
}
|
|
50
|
+
exports.SortEmptyKeyConf = SortEmptyKeyConf;
|
|
51
|
+
class SortEmptyKey {
|
|
52
|
+
constructor() {
|
|
53
|
+
this.conf = new SortEmptyKeyConf();
|
|
54
|
+
}
|
|
55
|
+
getMetadata() {
|
|
56
|
+
return {
|
|
57
|
+
key: "sort_empty_key",
|
|
58
|
+
title: "SORT or DELETE ADJACENT DUPLICATES on a table with an empty key",
|
|
59
|
+
shortDescription: `SORT without BY and DELETE ADJACENT DUPLICATES without COMPARING on a table with an empty primary key`,
|
|
60
|
+
extendedInformation: `Without BY or COMPARING, both statements use the primary key of the table. For a table
|
|
61
|
+
declared WITH EMPTY KEY there is nothing to sort or compare by, SORT does nothing.
|
|
62
|
+
|
|
63
|
+
The syntax check warns: "ITAB is a table with an empty primary key. Check the semantics of the statement."
|
|
64
|
+
|
|
65
|
+
Sorted and hashed tables, tables with a default or explicit key, and tables of unknown or generic type are not reported.
|
|
66
|
+
|
|
67
|
+
The quick fix adds BY table_line or COMPARING table_line, for tables with an elementary row type.`,
|
|
68
|
+
tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
|
|
69
|
+
badExample: `DATA result TYPE STANDARD TABLE OF string WITH EMPTY KEY.
|
|
70
|
+
SORT result.
|
|
71
|
+
DELETE ADJACENT DUPLICATES FROM result.`,
|
|
72
|
+
goodExample: `DATA result TYPE STANDARD TABLE OF string WITH EMPTY KEY.
|
|
73
|
+
SORT result BY table_line.
|
|
74
|
+
DELETE ADJACENT DUPLICATES FROM result COMPARING table_line.`,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
getConfig() {
|
|
78
|
+
return this.conf;
|
|
79
|
+
}
|
|
80
|
+
initialize(reg) {
|
|
81
|
+
this.reg = reg;
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
setConfig(conf) {
|
|
85
|
+
this.conf = conf;
|
|
86
|
+
}
|
|
87
|
+
run(obj) {
|
|
88
|
+
if (!(obj instanceof _abap_object_1.ABAPObject) || obj.getType() === "INTF") {
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
const issues = [];
|
|
92
|
+
let spaghetti = undefined;
|
|
93
|
+
for (const file of obj.getABAPFiles()) {
|
|
94
|
+
for (const statement of file.getStatements()) {
|
|
95
|
+
let addition;
|
|
96
|
+
if (statement.get() instanceof Statements.Sort) {
|
|
97
|
+
if (statement.findDirectTokenByText("BY") !== undefined) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
addition = "BY";
|
|
101
|
+
}
|
|
102
|
+
else if (statement.get() instanceof Statements.DeleteInternal) {
|
|
103
|
+
if (statement.findDirectTokenByText("ADJACENT") === undefined
|
|
104
|
+
|| statement.findDirectTokenByText("COMPARING") !== undefined
|
|
105
|
+
|| statement.findDirectTokenByText("USING") !== undefined) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
addition = "COMPARING";
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const target = statement.findDirectExpression(Expressions.Target);
|
|
114
|
+
if (target === undefined) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (spaghetti === undefined) {
|
|
118
|
+
spaghetti = new syntax_1.SyntaxLogic(this.reg, obj).run().spaghetti;
|
|
119
|
+
}
|
|
120
|
+
const type = this.findType(target, spaghetti, file);
|
|
121
|
+
if (!(type instanceof basic_1.TableType)
|
|
122
|
+
|| type.getOptions().keyType !== basic_1.TableKeyType.empty
|
|
123
|
+
|| type.isGeneric()
|
|
124
|
+
|| (type.getAccessType() !== undefined && type.getAccessType() !== basic_1.TableAccessType.standard)) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const verb = addition === "BY" ? "SORT without BY" : "DELETE ADJACENT DUPLICATES without COMPARING";
|
|
128
|
+
const message = `${verb} on "${target.concatTokens()}", a table with an empty primary key`;
|
|
129
|
+
const fix = this.buildFix(file, statement, type.getRowType(), addition);
|
|
130
|
+
issues.push(issue_1.Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity, fix));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return issues;
|
|
134
|
+
}
|
|
135
|
+
////////////////
|
|
136
|
+
/** The type of a target built from names, components and attributes only, else undefined */
|
|
137
|
+
findType(target, spaghetti, file) {
|
|
138
|
+
var _a;
|
|
139
|
+
let type = undefined;
|
|
140
|
+
for (const child of target.getChildren()) {
|
|
141
|
+
const get = child.get();
|
|
142
|
+
if (get instanceof Expressions.TargetField
|
|
143
|
+
|| get instanceof Expressions.TargetFieldSymbol
|
|
144
|
+
|| get instanceof Expressions.AttributeName) {
|
|
145
|
+
type = (_a = this.findReference(child.getFirstToken().getStart(), spaghetti, file)) === null || _a === void 0 ? void 0 : _a.getType();
|
|
146
|
+
}
|
|
147
|
+
else if (get instanceof Expressions.ComponentName) {
|
|
148
|
+
type = type instanceof basic_1.StructureType ? type.getComponentByName(child.concatTokens()) : undefined;
|
|
149
|
+
}
|
|
150
|
+
else if (!(get instanceof tokens_1.Dash)
|
|
151
|
+
&& !(get instanceof tokens_1.InstanceArrow)
|
|
152
|
+
&& !(get instanceof tokens_1.StaticArrow)
|
|
153
|
+
&& !(get instanceof Expressions.ClassName)) {
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
if (type === undefined && !(get instanceof Expressions.ClassName) && !(get instanceof tokens_1.StaticArrow)) {
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return type;
|
|
161
|
+
}
|
|
162
|
+
findReference(start, spaghetti, file) {
|
|
163
|
+
const scope = spaghetti.lookupPosition(start, file.getFilename());
|
|
164
|
+
for (const r of (scope === null || scope === void 0 ? void 0 : scope.getData().references) || []) {
|
|
165
|
+
if (r.position.getStart().equals(start) && r.resolved instanceof _typed_identifier_1.TypedIdentifier) {
|
|
166
|
+
return r.resolved;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
buildFix(file, statement, rowType, addition) {
|
|
172
|
+
if (rowType instanceof basic_1.StructureType
|
|
173
|
+
|| rowType instanceof basic_1.TableType
|
|
174
|
+
|| rowType instanceof basic_1.VoidType
|
|
175
|
+
|| rowType instanceof basic_1.UnknownType
|
|
176
|
+
|| rowType.isGeneric()) {
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
const tokens = statement.getTokens();
|
|
180
|
+
let last = tokens[tokens.length - 1];
|
|
181
|
+
if (last instanceof tokens_1.Punctuation) {
|
|
182
|
+
last = tokens[tokens.length - 2];
|
|
183
|
+
}
|
|
184
|
+
return edit_helper_1.EditHelper.insertAt(file, last.getEnd(), ` ${addition} table_line`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
exports.SortEmptyKey = SortEmptyKey;
|
|
188
|
+
//# sourceMappingURL=sort_empty_key.js.map
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.SubrcAfterAssign = exports.SubrcAfterAssignConf = void 0;
|
|
37
|
+
const Statements = __importStar(require("../abap/2_statements/statements"));
|
|
38
|
+
const Expressions = __importStar(require("../abap/2_statements/expressions"));
|
|
39
|
+
const issue_1 = require("../issue");
|
|
40
|
+
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
41
|
+
const _abap_rule_1 = require("./_abap_rule");
|
|
42
|
+
const _irule_1 = require("./_irule");
|
|
43
|
+
const _statement_1 = require("../abap/2_statements/statements/_statement");
|
|
44
|
+
const edit_helper_1 = require("../edit_helper");
|
|
45
|
+
const severity_1 = require("../severity");
|
|
46
|
+
class SubrcAfterAssignConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
47
|
+
constructor() {
|
|
48
|
+
super(...arguments);
|
|
49
|
+
this.severity = severity_1.Severity.Warning;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.SubrcAfterAssignConf = SubrcAfterAssignConf;
|
|
53
|
+
class SubrcAfterAssign extends _abap_rule_1.ABAPRule {
|
|
54
|
+
constructor() {
|
|
55
|
+
super(...arguments);
|
|
56
|
+
this.conf = new SubrcAfterAssignConf();
|
|
57
|
+
}
|
|
58
|
+
getMetadata() {
|
|
59
|
+
return {
|
|
60
|
+
key: "subrc_after_assign",
|
|
61
|
+
title: "sy-subrc checked after ASSIGN",
|
|
62
|
+
shortDescription: `Reports a sy-subrc check directly after an ASSIGN, use IS [NOT] ASSIGNED instead`,
|
|
63
|
+
extendedInformation: `On a 7.40 SP7 system sy-subrc was still 4 after a successful ASSIGN, left over from an earlier
|
|
64
|
+
READ TABLE, see https://github.com/abap2UI5/abap2UI5/issues/1937. Current releases set sy-subrc here.
|
|
65
|
+
IS [NOT] ASSIGNED asks the field symbol directly and does not depend on the release.
|
|
66
|
+
|
|
67
|
+
A failed ASSIGN keeps the previous binding of the field symbol. So inside a loop, or when the
|
|
68
|
+
field symbol is bound earlier in the same method, IS ASSIGNED is true after a failed ASSIGN.
|
|
69
|
+
There, add UNASSIGN <fs> before the ASSIGN. The quick fix is only offered when the field symbol
|
|
70
|
+
is declared in the method, bound only by this ASSIGN, and the ASSIGN is not in a loop.
|
|
71
|
+
|
|
72
|
+
ASSIGN COMPONENT ... OF STRUCTURE is not reported.`,
|
|
73
|
+
tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
|
|
74
|
+
badExample: `ASSIGN (lv_name) TO <attri>.
|
|
75
|
+
IF sy-subrc = 0.
|
|
76
|
+
WRITE <attri>.
|
|
77
|
+
ENDIF.`,
|
|
78
|
+
goodExample: `ASSIGN (lv_name) TO <attri>.
|
|
79
|
+
IF <attri> IS ASSIGNED.
|
|
80
|
+
WRITE <attri>.
|
|
81
|
+
ENDIF.`,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
getConfig() {
|
|
85
|
+
return this.conf;
|
|
86
|
+
}
|
|
87
|
+
setConfig(conf) {
|
|
88
|
+
this.conf = conf;
|
|
89
|
+
}
|
|
90
|
+
runParsed(file) {
|
|
91
|
+
var _a, _b;
|
|
92
|
+
const issues = [];
|
|
93
|
+
const statements = file.getStatements();
|
|
94
|
+
for (let i = 0; i < statements.length; i++) {
|
|
95
|
+
const statement = statements[i];
|
|
96
|
+
if (!(statement.get() instanceof Statements.Assign)
|
|
97
|
+
|| ((_a = statement.findDirectExpression(Expressions.AssignSource)) === null || _a === void 0 ? void 0 : _a.getFirstToken().getStr().toUpperCase()) === "COMPONENT") {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const target = statement.findDirectExpression(Expressions.FSTarget);
|
|
101
|
+
const fs = (_b = target === null || target === void 0 ? void 0 : target.findFirstExpression(Expressions.FieldSymbol)) === null || _b === void 0 ? void 0 : _b.concatTokens();
|
|
102
|
+
if (target === undefined || fs === undefined) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const check = this.nextCheck(i, statements, fs.toUpperCase());
|
|
106
|
+
if (check === undefined) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
let message = `sy-subrc checked after ASSIGN, use ${fs} IS [NOT] ASSIGNED`;
|
|
110
|
+
let fix = undefined;
|
|
111
|
+
if (this.insideLoop(i, statements) === true) {
|
|
112
|
+
message += ` with UNASSIGN ${fs} before the ASSIGN, it is inside a loop`;
|
|
113
|
+
}
|
|
114
|
+
else if (this.boundEarlier(i, statements, fs.toUpperCase()) === true) {
|
|
115
|
+
message += ` with UNASSIGN ${fs} before the ASSIGN, ${fs} is bound earlier`;
|
|
116
|
+
}
|
|
117
|
+
else if (target.findDirectExpression(Expressions.InlineFS) === undefined
|
|
118
|
+
&& this.declaredInBlock(i, statements, fs.toUpperCase()) === false) {
|
|
119
|
+
message += ` with UNASSIGN ${fs} before the ASSIGN, ${fs} is not declared in this method`;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
fix = this.buildFix(file, check, fs);
|
|
123
|
+
}
|
|
124
|
+
issues.push(issue_1.Issue.atStatement(file, check, message, this.getMetadata().key, this.conf.severity, fix));
|
|
125
|
+
}
|
|
126
|
+
return issues;
|
|
127
|
+
}
|
|
128
|
+
////////////////
|
|
129
|
+
/** the next statement, skipping comments and ENDIF like check_subrc does, if it reads sy-subrc */
|
|
130
|
+
nextCheck(index, statements, fs) {
|
|
131
|
+
for (let i = index + 1; i < statements.length; i++) {
|
|
132
|
+
const statement = statements[i];
|
|
133
|
+
if (statement.get() instanceof _statement_1.Comment
|
|
134
|
+
|| statement.get() instanceof Statements.EndIf
|
|
135
|
+
|| statement.get() instanceof Statements.EndTestSeam) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const concat = statement.concatTokens().toUpperCase();
|
|
139
|
+
if (concat.includes(fs + " IS ASSIGNED") || concat.includes(fs + " IS NOT ASSIGNED")) {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
return concat.includes("SY-SUBRC") ? statement : undefined;
|
|
143
|
+
}
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
insideLoop(index, statements) {
|
|
147
|
+
let depth = 0;
|
|
148
|
+
for (let i = index - 1; i >= 0 && this.startsBlock(statements[i]) === false; i--) {
|
|
149
|
+
const s = statements[i].get();
|
|
150
|
+
if (s instanceof Statements.EndLoop || s instanceof Statements.EndDo || s instanceof Statements.EndWhile) {
|
|
151
|
+
depth++;
|
|
152
|
+
}
|
|
153
|
+
else if (s instanceof Statements.Loop || s instanceof Statements.Do || s instanceof Statements.While) {
|
|
154
|
+
if (depth === 0) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
depth--;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
/** any earlier statement in the block with the field symbol as target, eg. ASSIGN, LOOP or READ TABLE ASSIGNING */
|
|
163
|
+
boundEarlier(index, statements, fs) {
|
|
164
|
+
var _a;
|
|
165
|
+
for (let i = index - 1; i >= 0 && this.startsBlock(statements[i]) === false; i--) {
|
|
166
|
+
for (const target of statements[i].findAllExpressions(Expressions.FSTarget)) {
|
|
167
|
+
if (((_a = target.findFirstExpression(Expressions.FieldSymbol)) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase()) === fs) {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
declaredInBlock(index, statements, fs) {
|
|
175
|
+
var _a;
|
|
176
|
+
for (let i = index - 1; i >= 0 && this.startsBlock(statements[i]) === false; i--) {
|
|
177
|
+
if (statements[i].get() instanceof Statements.FieldSymbol
|
|
178
|
+
&& ((_a = statements[i].findDirectExpression(Expressions.FieldSymbol)) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase()) === fs) {
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
startsBlock(statement) {
|
|
185
|
+
const s = statement.get();
|
|
186
|
+
return s instanceof Statements.MethodImplementation
|
|
187
|
+
|| s instanceof Statements.Form
|
|
188
|
+
|| s instanceof Statements.FunctionModule
|
|
189
|
+
|| s instanceof Statements.Module
|
|
190
|
+
|| s instanceof Statements.EndMethod
|
|
191
|
+
|| s instanceof Statements.EndForm
|
|
192
|
+
|| s instanceof Statements.EndFunction
|
|
193
|
+
|| s instanceof Statements.EndModule;
|
|
194
|
+
}
|
|
195
|
+
/** replaces "sy-subrc = 0" or "sy-subrc <> 0" in place, also inside a longer condition */
|
|
196
|
+
buildFix(file, statement, fs) {
|
|
197
|
+
const tokens = statement.getTokens();
|
|
198
|
+
for (let i = 0; i + 4 < tokens.length; i++) {
|
|
199
|
+
if (tokens[i].getStr().toUpperCase() !== "SY"
|
|
200
|
+
|| tokens[i + 1].getStr() !== "-"
|
|
201
|
+
|| tokens[i + 2].getStr().toUpperCase() !== "SUBRC") {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
if (tokens[i + 4].getStr() !== "0") {
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
const op = tokens[i + 3].getStr().toUpperCase();
|
|
208
|
+
if (op === "=" || op === "EQ") {
|
|
209
|
+
return edit_helper_1.EditHelper.replaceRange(file, tokens[i].getStart(), tokens[i + 4].getEnd(), `${fs} IS ASSIGNED`);
|
|
210
|
+
}
|
|
211
|
+
else if (op === "<>" || op === "NE") {
|
|
212
|
+
return edit_helper_1.EditHelper.replaceRange(file, tokens[i].getStart(), tokens[i + 4].getEnd(), `${fs} IS NOT ASSIGNED`);
|
|
213
|
+
}
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
exports.SubrcAfterAssign = SubrcAfterAssign;
|
|
220
|
+
//# sourceMappingURL=subrc_after_assign.js.map
|
|
@@ -53,6 +53,7 @@ class TypesNaming extends _abap_rule_1.ABAPRule {
|
|
|
53
53
|
constructor() {
|
|
54
54
|
super(...arguments);
|
|
55
55
|
this.conf = new TypesNamingConf();
|
|
56
|
+
this.regex = new RegExp(this.conf.pattern, "i");
|
|
56
57
|
}
|
|
57
58
|
getMetadata() {
|
|
58
59
|
return {
|
|
@@ -70,10 +71,10 @@ class TypesNaming extends _abap_rule_1.ABAPRule {
|
|
|
70
71
|
}
|
|
71
72
|
setConfig(conf) {
|
|
72
73
|
this.conf = conf;
|
|
74
|
+
this.regex = new RegExp(this.conf.pattern, "i");
|
|
73
75
|
}
|
|
74
76
|
runParsed(file, obj) {
|
|
75
77
|
const issues = [];
|
|
76
|
-
const testRegex = new RegExp(this.conf.pattern, "i");
|
|
77
78
|
let nesting = 0;
|
|
78
79
|
if (obj instanceof objects_1.TypePool) {
|
|
79
80
|
return [];
|
|
@@ -102,7 +103,7 @@ class TypesNaming extends _abap_rule_1.ABAPRule {
|
|
|
102
103
|
continue;
|
|
103
104
|
}
|
|
104
105
|
const token = expr.getFirstToken();
|
|
105
|
-
if (
|
|
106
|
+
if (this.regex.exec(token.getStr())) {
|
|
106
107
|
continue;
|
|
107
108
|
}
|
|
108
109
|
else {
|
|
@@ -40,6 +40,8 @@ const _abap_rule_1 = require("./_abap_rule");
|
|
|
40
40
|
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
41
41
|
const _irule_1 = require("./_irule");
|
|
42
42
|
const _statement_1 = require("../abap/2_statements/statements/_statement");
|
|
43
|
+
const edit_helper_1 = require("../edit_helper");
|
|
44
|
+
const position_1 = require("../position");
|
|
43
45
|
class WrongAbapdocPositionConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
44
46
|
}
|
|
45
47
|
exports.WrongAbapdocPositionConf = WrongAbapdocPositionConf;
|
|
@@ -59,10 +61,13 @@ elsewhere is silently ignored, leaving the declaration undocumented.
|
|
|
59
61
|
The following positions are reported,
|
|
60
62
|
* in front of a chained keyword, ie. before "CONSTANTS:" instead of after the colon,
|
|
61
63
|
* in the middle of a statement, ie. between the parameters of a METHODS definition,
|
|
62
|
-
* directly in front of ENDCLASS, ENDINTERFACE or a SECTION statement
|
|
64
|
+
* directly in front of ENDCLASS, ENDINTERFACE or a SECTION statement,
|
|
65
|
+
* separated from its declaration by a blank line or a normal comment, the system reads both as the end of the block.
|
|
63
66
|
|
|
64
|
-
Only checks ABAP Doc inside class definitions and interfaces
|
|
65
|
-
|
|
67
|
+
Only checks ABAP Doc inside class definitions and interfaces, and directly in front of them.
|
|
68
|
+
|
|
69
|
+
The quick fix for a blank line deletes the blank lines.`,
|
|
70
|
+
tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
|
|
66
71
|
badExample: `CLASS zcl_foo DEFINITION PUBLIC.
|
|
67
72
|
PUBLIC SECTION.
|
|
68
73
|
"! Navigation modes
|
|
@@ -88,6 +93,7 @@ ENDCLASS.`,
|
|
|
88
93
|
this.conf = conf;
|
|
89
94
|
}
|
|
90
95
|
runParsed(file) {
|
|
96
|
+
var _a;
|
|
91
97
|
const issues = [];
|
|
92
98
|
const statements = file.getStatements();
|
|
93
99
|
let definition = false;
|
|
@@ -102,7 +108,7 @@ ENDCLASS.`,
|
|
|
102
108
|
definition = false;
|
|
103
109
|
continue;
|
|
104
110
|
}
|
|
105
|
-
else if (
|
|
111
|
+
else if (this.isAbapdoc(statement) === false) {
|
|
106
112
|
continue;
|
|
107
113
|
}
|
|
108
114
|
else if (this.isAbapdoc(statements[i - 1]) === true
|
|
@@ -110,19 +116,57 @@ ENDCLASS.`,
|
|
|
110
116
|
continue; // only report the first row of each block
|
|
111
117
|
}
|
|
112
118
|
let next = undefined;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
119
|
+
let j = i + 1;
|
|
120
|
+
for (; j < statements.length; j++) {
|
|
121
|
+
if (!(statements[j].get() instanceof _statement_1.Comment)) {
|
|
122
|
+
next = statements[j];
|
|
123
|
+
break;
|
|
116
124
|
}
|
|
117
|
-
next = statements[j];
|
|
118
|
-
break;
|
|
119
125
|
}
|
|
120
126
|
if (next === undefined) {
|
|
121
127
|
continue;
|
|
122
128
|
}
|
|
123
|
-
|
|
129
|
+
else if (definition === false
|
|
130
|
+
&& !(next.get() instanceof Statements.ClassDefinition)
|
|
131
|
+
&& !(next.get() instanceof Statements.Interface)) {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
// comments inside "next" are listed in front of it, only look at the rows above it
|
|
135
|
+
const nextRow = this.startRow(next);
|
|
136
|
+
const trailing = ((_a = statements[i - 1]) === null || _a === void 0 ? void 0 : _a.getEnd().getRow()) === statement.getStart().getRow();
|
|
137
|
+
let last = statement;
|
|
138
|
+
let separator = undefined;
|
|
139
|
+
let fix = undefined;
|
|
140
|
+
for (const s of trailing ? [] : statements.slice(i + 1, j)) {
|
|
141
|
+
if (s.getStart().getRow() >= nextRow) {
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
else if (s.getStart().getRow() > last.getEnd().getRow() + 1) {
|
|
145
|
+
separator = "a blank line";
|
|
146
|
+
if (this.isAbapdoc(s) === true) {
|
|
147
|
+
fix = edit_helper_1.EditHelper.deleteRange(file, new position_1.Position(last.getEnd().getRow() + 1, 1), new position_1.Position(s.getStart().getRow(), 1));
|
|
148
|
+
}
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
else if (this.isAbapdoc(s) === false) {
|
|
152
|
+
separator = "a comment";
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
last = s;
|
|
156
|
+
}
|
|
157
|
+
if (separator === undefined && trailing === false && nextRow > last.getEnd().getRow() + 1) {
|
|
158
|
+
separator = "a blank line";
|
|
159
|
+
fix = edit_helper_1.EditHelper.deleteRange(file, new position_1.Position(last.getEnd().getRow() + 1, 1), new position_1.Position(nextRow, 1));
|
|
160
|
+
}
|
|
161
|
+
let message = this.check(statement, next);
|
|
162
|
+
if (message !== undefined) {
|
|
163
|
+
fix = undefined;
|
|
164
|
+
}
|
|
165
|
+
else if (separator !== undefined) {
|
|
166
|
+
message = "ABAP Doc is separated from its declaration by " + separator;
|
|
167
|
+
}
|
|
124
168
|
if (message !== undefined) {
|
|
125
|
-
issues.push(issue_1.Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity));
|
|
169
|
+
issues.push(issue_1.Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity, fix));
|
|
126
170
|
}
|
|
127
171
|
}
|
|
128
172
|
return issues;
|
|
@@ -131,6 +175,9 @@ ENDCLASS.`,
|
|
|
131
175
|
return (statement === null || statement === void 0 ? void 0 : statement.get()) instanceof _statement_1.Comment
|
|
132
176
|
&& statement.getFirstToken().getStr().startsWith(`"!`);
|
|
133
177
|
}
|
|
178
|
+
startRow(statement) {
|
|
179
|
+
return Math.min(statement.getStart().getRow(), ...statement.getPragmas().map(p => p.getRow()));
|
|
180
|
+
}
|
|
134
181
|
check(abapdoc, next) {
|
|
135
182
|
const type = next.get();
|
|
136
183
|
if (type instanceof Statements.EndClass
|
|
@@ -41,6 +41,10 @@ const _abap_object_1 = require("../objects/_abap_object");
|
|
|
41
41
|
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
42
42
|
const fast_xml_parser_1 = require("fast-xml-parser");
|
|
43
43
|
const severity_1 = require("../severity");
|
|
44
|
+
const ABAPGIT_ATTRIBUTES = [
|
|
45
|
+
["version", /<abapGit\b[^>]*\bversion="([^"]+)"/],
|
|
46
|
+
["serializer_version", /<abapGit\b[^>]*\bserializer_version="([^"]+)"/],
|
|
47
|
+
];
|
|
44
48
|
class XMLConsistencyConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
45
49
|
constructor() {
|
|
46
50
|
super(...arguments);
|
|
@@ -96,8 +100,8 @@ class XMLConsistency {
|
|
|
96
100
|
issues.push(issue_1.Issue.atRow(file, 1, "XML parser error: " + res.err.msg, this.getMetadata().key, this.conf.severity));
|
|
97
101
|
}
|
|
98
102
|
else {
|
|
99
|
-
for (const attribute of
|
|
100
|
-
const value = (_a = xml.match(
|
|
103
|
+
for (const [attribute, regex] of ABAPGIT_ATTRIBUTES) {
|
|
104
|
+
const value = (_a = xml.match(regex)) === null || _a === void 0 ? void 0 : _a[1];
|
|
101
105
|
if (value !== undefined && value.match(/^v\d\.\d\.\d$/) === null) {
|
|
102
106
|
issues.push(issue_1.Issue.atRow(file, 1, `Unexpected abapGit ${attribute} "${value}"`, this.getMetadata().key, this.conf.severity));
|
|
103
107
|
}
|
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NameValidator = void 0;
|
|
4
4
|
class NameValidator {
|
|
5
|
-
|
|
5
|
+
/** compile the configured ignorePatterns, case insensitive */
|
|
6
|
+
static compileIgnorePatterns(params) {
|
|
7
|
+
return (params.ignorePatterns || []).map(ignored => new RegExp(ignored, "i"));
|
|
8
|
+
}
|
|
9
|
+
static violatesRule(name, pattern, params, ignorePatterns) {
|
|
6
10
|
if (params.ignoreNames && params.ignoreNames.indexOf(name.toUpperCase()) >= 0) {
|
|
7
11
|
return false;
|
|
8
12
|
}
|
|
9
|
-
for (const ignored of
|
|
10
|
-
if (
|
|
13
|
+
for (const ignored of ignorePatterns) {
|
|
14
|
+
if (ignored.test(name)) {
|
|
11
15
|
return false;
|
|
12
16
|
}
|
|
13
17
|
}
|