@abaplint/core 2.120.107 → 2.120.109
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 +1 -0
- package/build/src/abap/5_syntax/_key_compare.js +66 -0
- package/build/src/abap/5_syntax/statements/insert_internal.js +8 -0
- package/build/src/abap/5_syntax/statements/loop.js +2 -27
- package/build/src/abap/types/class_definition.js +52 -1
- package/build/src/registry.js +1 -1
- package/build/src/rules/_procedure_analysis.js +1 -0
- package/build/src/rules/character_field_literal_blanks.js +264 -0
- package/build/src/rules/constant_condition.js +201 -3
- package/build/src/rules/field_symbol_never_assigned.js +194 -0
- package/build/src/rules/identical_conditions.js +76 -2
- package/build/src/rules/index.js +7 -0
- package/build/src/rules/inline_generic_source.js +170 -0
- package/build/src/rules/loop_target_misuse.js +301 -0
- package/build/src/rules/redundant_conversion.js +99 -2
- package/build/src/rules/sequential_read_sorted.js +318 -0
- package/build/src/rules/stale_subrc.js +176 -0
- package/build/src/rules/unit_test_assertions.js +263 -0
- package/build/src/rules/xml_consistency.js +24 -0
- package/package.json +1 -1
|
@@ -35,11 +35,20 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.ConstantCondition = exports.ConstantConditionConf = void 0;
|
|
37
37
|
const Expressions = __importStar(require("../abap/2_statements/expressions"));
|
|
38
|
+
const Statements = __importStar(require("../abap/2_statements/statements"));
|
|
39
|
+
const nodes_1 = require("../abap/nodes");
|
|
38
40
|
const basic_1 = require("../abap/types/basic");
|
|
41
|
+
const _typed_identifier_1 = require("../abap/types/_typed_identifier");
|
|
42
|
+
const issue_1 = require("../issue");
|
|
39
43
|
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
40
44
|
const _irule_1 = require("./_irule");
|
|
41
45
|
const _procedure_analysis_1 = require("./_procedure_analysis");
|
|
42
46
|
class ConstantConditionConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
47
|
+
constructor() {
|
|
48
|
+
super(...arguments);
|
|
49
|
+
/** Report x <> a OR x <> b, always true, and x = a AND x = b, always false, for different character values a and b */
|
|
50
|
+
this.exclusiveValues = true;
|
|
51
|
+
}
|
|
43
52
|
}
|
|
44
53
|
exports.ConstantConditionConf = ConstantConditionConf;
|
|
45
54
|
class ConstantCondition {
|
|
@@ -50,7 +59,8 @@ class ConstantCondition {
|
|
|
50
59
|
return {
|
|
51
60
|
key: "constant_condition",
|
|
52
61
|
title: "Constant condition",
|
|
53
|
-
shortDescription: `Finds IF and ELSEIF conditions on local variables whose value is known
|
|
62
|
+
shortDescription: `Finds IF and ELSEIF conditions on local variables whose value is known, and conditions that compare
|
|
63
|
+
a field with two different values and are always true or always false`,
|
|
54
64
|
extendedInformation: `Reports two cases, for local variables of a METHOD, FORM or FUNCTION.
|
|
55
65
|
|
|
56
66
|
1. DATA(c) = <constant>. where the constant is a character literal like 'X', or a character constant like
|
|
@@ -69,15 +79,31 @@ an ELSEIF branch that is always taken turns into ELSE. Nothing is reported if a
|
|
|
69
79
|
data that is used outside of it.
|
|
70
80
|
|
|
71
81
|
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
72
|
-
INCLUDE, test seams, enhancements or native SQL. No release requirement
|
|
82
|
+
INCLUDE, test seams, enhancements or native SQL. No release requirement.
|
|
83
|
+
|
|
84
|
+
Option exclusiveValues: reports x <> a OR x <> b, which is always true, and x = a AND x = b, which is always
|
|
85
|
+
false, in any condition of a METHOD, FORM or FUNCTION, also with dynamic code. Also with NE and EQ, with NOT,
|
|
86
|
+
with the operands swapped, and with more conditions joined by the same operator. x is a data object of type c,
|
|
87
|
+
generic c or string, without calls, offsets or table expressions. a and b are character literals or character
|
|
88
|
+
constants, also components of constant structures of a class or interface, with different values. Usually one
|
|
89
|
+
of the operators or one of the values is wrong, there is no quick fix.
|
|
90
|
+
Not reported: conditions that mix AND and OR or contain a call, values that are not known, like constants of
|
|
91
|
+
classes outside the registry, other types of x, which can convert different values to the same one, ASSERT,
|
|
92
|
+
and SQL conditions, where a NULL value makes both comparisons unknown.`,
|
|
73
93
|
tags: [_irule_1.RuleTag.Quickfix],
|
|
74
94
|
badExample: `DATA(lv_active) = abap_true.
|
|
75
95
|
IF lv_active = abap_true.
|
|
76
96
|
run( ).
|
|
77
97
|
ELSE.
|
|
78
98
|
skip( ).
|
|
99
|
+
ENDIF.
|
|
100
|
+
IF lv_kind <> 'N' OR lv_kind <> 'P'.
|
|
101
|
+
skip( ).
|
|
102
|
+
ENDIF.`,
|
|
103
|
+
goodExample: `run( ).
|
|
104
|
+
IF lv_kind <> 'N' AND lv_kind <> 'P'.
|
|
105
|
+
skip( ).
|
|
79
106
|
ENDIF.`,
|
|
80
|
-
goodExample: `run( ).`,
|
|
81
107
|
};
|
|
82
108
|
}
|
|
83
109
|
getConfig() {
|
|
@@ -97,6 +123,9 @@ ENDIF.`,
|
|
|
97
123
|
}
|
|
98
124
|
const issues = [];
|
|
99
125
|
for (const procedure of analysis.procedures) {
|
|
126
|
+
if (this.conf.exclusiveValues) {
|
|
127
|
+
issues.push(...this.exclusiveValues(procedure));
|
|
128
|
+
}
|
|
100
129
|
if (procedure.supported === false) {
|
|
101
130
|
continue;
|
|
102
131
|
}
|
|
@@ -198,6 +227,175 @@ ENDIF.`,
|
|
|
198
227
|
return source.countTokens() === 1 && source.findDirectExpression(Expressions.FieldChain) !== undefined
|
|
199
228
|
&& source.getFirstToken().getStart().equals(read.token.getStart());
|
|
200
229
|
}
|
|
230
|
+
/** x <> a OR x <> b, x = a AND x = b */
|
|
231
|
+
exclusiveValues(procedure) {
|
|
232
|
+
const issues = [];
|
|
233
|
+
for (const statement of procedure.statements) {
|
|
234
|
+
if (statement.get() instanceof Statements.Assert) {
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
for (const cond of statement.findAllExpressionsRecursive(Expressions.Cond)) {
|
|
238
|
+
const operators = cond.getChildren().filter(c => c instanceof nodes_1.TokenNode).map(c => c.getFirstToken().getStr().toUpperCase());
|
|
239
|
+
const operator = operators[0];
|
|
240
|
+
if ((operator !== "OR" && operator !== "AND") || operators.some(o => o !== operator) || this.hasCall(cond)) {
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
const seen = [];
|
|
244
|
+
for (const child of cond.getChildren()) {
|
|
245
|
+
const comparison = child instanceof nodes_1.ExpressionNode && child.get() instanceof Expressions.Compare
|
|
246
|
+
? this.valueComparison(procedure, child) : undefined;
|
|
247
|
+
if (comparison === undefined || comparison.equal !== (operator === "AND")) {
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
const other = seen.find(s => s.subject === comparison.subject && !(0, _procedure_analysis_1.sameCharacters)(s.value, comparison.value));
|
|
251
|
+
if (other !== undefined) {
|
|
252
|
+
const message = "Condition is always " + (operator === "OR" ? "true" : "false") + ", "
|
|
253
|
+
+ this.subjectText(comparison) + " cannot be both "
|
|
254
|
+
+ other.constant.concatTokens() + " and " + comparison.constant.concatTokens();
|
|
255
|
+
issues.push(issue_1.Issue.atRange(procedure.file, other.compare.getFirstToken().getStart(), comparison.compare.getLastToken().getEnd(), message, this.getMetadata().key, this.conf.severity));
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
seen.push(comparison);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return issues;
|
|
263
|
+
}
|
|
264
|
+
hasCall(node) {
|
|
265
|
+
return node.findFirstExpression(Expressions.MethodCall) !== undefined
|
|
266
|
+
|| node.findFirstExpression(Expressions.MethodCallChain) !== undefined
|
|
267
|
+
|| node.findFirstExpression(Expressions.NewObject) !== undefined;
|
|
268
|
+
}
|
|
269
|
+
/** x = a, x <> a, a = x, NOT x = a etc, x character-like and a a known character value */
|
|
270
|
+
valueComparison(procedure, compare) {
|
|
271
|
+
const children = compare.getChildren();
|
|
272
|
+
const negated = children[0] instanceof nodes_1.TokenNode && children[0].getFirstToken().getStr().toUpperCase() === "NOT";
|
|
273
|
+
const rest = children.slice(negated ? 1 : 0);
|
|
274
|
+
if (rest.length !== 3 || !(rest[0] instanceof nodes_1.ExpressionNode) || !(rest[2] instanceof nodes_1.ExpressionNode)
|
|
275
|
+
|| !(rest[1].get() instanceof Expressions.CompareOperator)) {
|
|
276
|
+
return undefined;
|
|
277
|
+
}
|
|
278
|
+
const operator = rest[1].concatTokens().toUpperCase().replace(/ /g, "");
|
|
279
|
+
let equal;
|
|
280
|
+
if (operator === "=" || operator === "EQ") {
|
|
281
|
+
equal = true;
|
|
282
|
+
}
|
|
283
|
+
else if (operator === "<>" || operator === "><" || operator === "NE") {
|
|
284
|
+
equal = false;
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
return undefined;
|
|
288
|
+
}
|
|
289
|
+
for (const [subject, constant] of [[rest[0], rest[2]], [rest[2], rest[0]]]) {
|
|
290
|
+
const value = this.constantValue(procedure, constant);
|
|
291
|
+
const type = value === undefined ? undefined : this.subjectType(procedure, subject);
|
|
292
|
+
if (value !== undefined
|
|
293
|
+
&& (type instanceof basic_1.CharacterType || type instanceof basic_1.CGenericType || type instanceof basic_1.StringType)) {
|
|
294
|
+
const text = subject.getTokens().map(t => t.getStr().toUpperCase()).join(" ");
|
|
295
|
+
return { subject: text, value, equal: equal !== negated, compare, constant };
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return undefined;
|
|
299
|
+
}
|
|
300
|
+
subjectText(comparison) {
|
|
301
|
+
var _a;
|
|
302
|
+
var _b;
|
|
303
|
+
return (_b = (_a = comparison.compare.getChildren().find(c => c instanceof nodes_1.ExpressionNode && c !== comparison.constant
|
|
304
|
+
&& c.get() instanceof Expressions.Source)) === null || _a === void 0 ? void 0 : _a.concatTokens()) !== null && _b !== void 0 ? _b : comparison.subject;
|
|
305
|
+
}
|
|
306
|
+
/** type of a field, field symbol, attribute or component chain, without calls, offsets or table expressions */
|
|
307
|
+
subjectType(procedure, source) {
|
|
308
|
+
var _a;
|
|
309
|
+
var _b;
|
|
310
|
+
const chain = source.getChildren().length === 1 ? source.findDirectExpression(Expressions.FieldChain) : undefined;
|
|
311
|
+
const children = (_b = chain === null || chain === void 0 ? void 0 : chain.getChildren()) !== null && _b !== void 0 ? _b : [];
|
|
312
|
+
let identifier;
|
|
313
|
+
let next;
|
|
314
|
+
if (children[0] instanceof nodes_1.ExpressionNode
|
|
315
|
+
&& (children[0].get() instanceof Expressions.SourceField || children[0].get() instanceof Expressions.SourceFieldSymbol)) {
|
|
316
|
+
identifier = procedure.identifierAt(children[0].getFirstToken());
|
|
317
|
+
next = 1;
|
|
318
|
+
}
|
|
319
|
+
else if (children[0] instanceof nodes_1.ExpressionNode && children[0].get() instanceof Expressions.ClassName
|
|
320
|
+
&& ((_a = children[1]) === null || _a === void 0 ? void 0 : _a.getFirstToken().getStr()) === "=>" && children[2] instanceof nodes_1.ExpressionNode) {
|
|
321
|
+
identifier = procedure.identifierAt(children[2].getFirstToken());
|
|
322
|
+
next = 3;
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
return undefined;
|
|
326
|
+
}
|
|
327
|
+
let type = identifier instanceof _typed_identifier_1.TypedIdentifier ? identifier.getType() : undefined;
|
|
328
|
+
for (let i = next; i < children.length; i += 2) {
|
|
329
|
+
const separator = children[i];
|
|
330
|
+
const name = children[i + 1];
|
|
331
|
+
if (!(separator instanceof nodes_1.TokenNode) || !(name instanceof nodes_1.ExpressionNode) || type === undefined) {
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
334
|
+
else if (separator.getFirstToken().getStr() === "->" && name.get() instanceof Expressions.AttributeName) {
|
|
335
|
+
const attribute = procedure.identifierAt(name.getFirstToken());
|
|
336
|
+
type = attribute instanceof _typed_identifier_1.TypedIdentifier ? attribute.getType() : undefined;
|
|
337
|
+
}
|
|
338
|
+
else if (separator.getFirstToken().getStr() === "-" && name.get() instanceof Expressions.ComponentName
|
|
339
|
+
&& type instanceof basic_1.StructureType) {
|
|
340
|
+
type = type.getComponentByName(name.getFirstToken().getStr());
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
return undefined;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return type;
|
|
347
|
+
}
|
|
348
|
+
/** value of a character literal, a character constant or a character component of a constant structure */
|
|
349
|
+
constantValue(procedure, source) {
|
|
350
|
+
var _a;
|
|
351
|
+
var _b;
|
|
352
|
+
if (source.findDirectExpression(Expressions.Constant) !== undefined) {
|
|
353
|
+
return (0, _procedure_analysis_1.characterConstant)(procedure, source);
|
|
354
|
+
}
|
|
355
|
+
const chain = source.getChildren().length === 1 ? source.findDirectExpression(Expressions.FieldChain) : undefined;
|
|
356
|
+
const children = (_b = chain === null || chain === void 0 ? void 0 : chain.getChildren()) !== null && _b !== void 0 ? _b : [];
|
|
357
|
+
let identifier;
|
|
358
|
+
let next;
|
|
359
|
+
if (children[0] instanceof nodes_1.ExpressionNode && children[0].get() instanceof Expressions.SourceField) {
|
|
360
|
+
identifier = procedure.identifierAt(children[0].getFirstToken());
|
|
361
|
+
next = 1;
|
|
362
|
+
}
|
|
363
|
+
else if (children[0] instanceof nodes_1.ExpressionNode && children[0].get() instanceof Expressions.ClassName
|
|
364
|
+
&& ((_a = children[1]) === null || _a === void 0 ? void 0 : _a.getFirstToken().getStr()) === "=>" && children[2] instanceof nodes_1.ExpressionNode
|
|
365
|
+
&& children[2].get() instanceof Expressions.AttributeName) {
|
|
366
|
+
identifier = procedure.identifierAt(children[2].getFirstToken());
|
|
367
|
+
next = 3;
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
return undefined;
|
|
371
|
+
}
|
|
372
|
+
if (!(identifier instanceof _typed_identifier_1.TypedIdentifier) || !(0, _procedure_analysis_1.isImmutable)(identifier)) {
|
|
373
|
+
return undefined;
|
|
374
|
+
}
|
|
375
|
+
let type = identifier.getType();
|
|
376
|
+
let value = identifier.getValue();
|
|
377
|
+
if (children.length === next + 2) {
|
|
378
|
+
const name = children[next + 1];
|
|
379
|
+
if (children[next].getFirstToken().getStr() !== "-" || !(name instanceof nodes_1.ExpressionNode)
|
|
380
|
+
|| !(name.get() instanceof Expressions.ComponentName) || !(type instanceof basic_1.StructureType)
|
|
381
|
+
|| typeof value !== "object") {
|
|
382
|
+
return undefined;
|
|
383
|
+
}
|
|
384
|
+
const component = name.getFirstToken().getStr().toLowerCase();
|
|
385
|
+
type = type.getComponentByName(component);
|
|
386
|
+
const key = Object.keys(value).find(k => k.toLowerCase() === component);
|
|
387
|
+
value = key === undefined ? undefined : value[key];
|
|
388
|
+
}
|
|
389
|
+
else if (children.length !== next) {
|
|
390
|
+
return undefined;
|
|
391
|
+
}
|
|
392
|
+
const text = typeof value === "string" ? (0, _procedure_analysis_1.textLiteral)(value) : undefined;
|
|
393
|
+
if (!(type instanceof basic_1.CharacterType) || text === undefined) {
|
|
394
|
+
return undefined;
|
|
395
|
+
}
|
|
396
|
+
// the value is cut to the length of the constant
|
|
397
|
+
return text.substring(0, type.getLength());
|
|
398
|
+
}
|
|
201
399
|
}
|
|
202
400
|
exports.ConstantCondition = ConstantCondition;
|
|
203
401
|
//# sourceMappingURL=constant_condition.js.map
|
|
@@ -0,0 +1,194 @@
|
|
|
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.FieldSymbolNeverAssigned = exports.FieldSymbolNeverAssignedConf = 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 token_node_1 = require("../abap/nodes/token_node");
|
|
44
|
+
const _statement_1 = require("../abap/2_statements/statements/_statement");
|
|
45
|
+
class FieldSymbolNeverAssignedConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
46
|
+
}
|
|
47
|
+
exports.FieldSymbolNeverAssignedConf = FieldSymbolNeverAssignedConf;
|
|
48
|
+
class FieldSymbolNeverAssigned extends _abap_rule_1.ABAPRule {
|
|
49
|
+
constructor() {
|
|
50
|
+
super(...arguments);
|
|
51
|
+
this.conf = new FieldSymbolNeverAssignedConf();
|
|
52
|
+
}
|
|
53
|
+
getMetadata() {
|
|
54
|
+
return {
|
|
55
|
+
key: "field_symbol_never_assigned",
|
|
56
|
+
title: "Field symbol never assigned",
|
|
57
|
+
shortDescription: `Reports a local field symbol that is used, but never assigned in its method, form or function module`,
|
|
58
|
+
extendedInformation: `A field symbol declared with FIELD-SYMBOLS in a method, form or function module can only be
|
|
59
|
+
assigned in that procedure. If no ASSIGN ... TO <fs> or ... ASSIGNING <fs> of it exists there,
|
|
60
|
+
reading or writing it raises the runtime error GETWA_NOT_ASSIGNED. This is typically a copy-paste
|
|
61
|
+
error, where a statement uses a field symbol other than the one assigned before it.
|
|
62
|
+
|
|
63
|
+
Assignments are ASSIGN, ASSIGN LOCAL COPY, and ASSIGNING of LOOP, READ TABLE, INSERT, APPEND,
|
|
64
|
+
MODIFY and COLLECT, anywhere in the procedure. The order of the statements is not checked.
|
|
65
|
+
|
|
66
|
+
Not reported: field symbols only used in IS [NOT] ASSIGNED or UNASSIGN, field symbols declared
|
|
67
|
+
with DEFAULT, inline declarations, global field symbols, and procedures that contain a macro
|
|
68
|
+
call, an INCLUDE or a statement that cannot be parsed.`,
|
|
69
|
+
tags: [_irule_1.RuleTag.SingleFile],
|
|
70
|
+
badExample: `FIELD-SYMBOLS <type> TYPE ty_type.
|
|
71
|
+
FIELD-SYMBOLS <attr> TYPE ty_attr.
|
|
72
|
+
LOOP AT types ASSIGNING <type>.
|
|
73
|
+
CLEAR <attr>-author.
|
|
74
|
+
ENDLOOP.`,
|
|
75
|
+
goodExample: `FIELD-SYMBOLS <type> TYPE ty_type.
|
|
76
|
+
LOOP AT types ASSIGNING <type>.
|
|
77
|
+
CLEAR <type>-author.
|
|
78
|
+
ENDLOOP.`,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
getConfig() {
|
|
82
|
+
return this.conf;
|
|
83
|
+
}
|
|
84
|
+
setConfig(conf) {
|
|
85
|
+
this.conf = conf;
|
|
86
|
+
}
|
|
87
|
+
runParsed(file) {
|
|
88
|
+
const issues = [];
|
|
89
|
+
const statements = file.getStatements();
|
|
90
|
+
let start = undefined;
|
|
91
|
+
for (let i = 0; i < statements.length; i++) {
|
|
92
|
+
const s = statements[i].get();
|
|
93
|
+
if (s instanceof Statements.MethodImplementation
|
|
94
|
+
|| s instanceof Statements.Form
|
|
95
|
+
|| s instanceof Statements.FunctionModule) {
|
|
96
|
+
start = i;
|
|
97
|
+
}
|
|
98
|
+
else if (start !== undefined
|
|
99
|
+
&& (s instanceof Statements.EndMethod
|
|
100
|
+
|| s instanceof Statements.EndForm
|
|
101
|
+
|| s instanceof Statements.EndFunction)) {
|
|
102
|
+
issues.push(...this.checkProcedure(file, statements.slice(start, i + 1)));
|
|
103
|
+
start = undefined;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return issues;
|
|
107
|
+
}
|
|
108
|
+
////////////////
|
|
109
|
+
checkProcedure(file, statements) {
|
|
110
|
+
var _a;
|
|
111
|
+
const declared = new Map();
|
|
112
|
+
const assigned = new Set();
|
|
113
|
+
const used = new Map();
|
|
114
|
+
for (const statement of statements) {
|
|
115
|
+
const s = statement.get();
|
|
116
|
+
if (s instanceof _statement_1.Unknown
|
|
117
|
+
|| s instanceof _statement_1.MacroCall
|
|
118
|
+
|| s instanceof Statements.Include) {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
else if (s instanceof Statements.FieldSymbol) {
|
|
122
|
+
const name = (_a = statement.findDirectExpression(Expressions.FieldSymbol)) === null || _a === void 0 ? void 0 : _a.concatTokens();
|
|
123
|
+
if (name !== undefined && statement.findDirectTokenByText("DEFAULT") === undefined) {
|
|
124
|
+
declared.set(name.toUpperCase(), name);
|
|
125
|
+
}
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
else if (s instanceof Statements.Unassign) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
this.walk(statement, assigned, used);
|
|
132
|
+
}
|
|
133
|
+
const issues = [];
|
|
134
|
+
const procedure = this.procedureName(statements[0]);
|
|
135
|
+
for (const [upper, name] of declared) {
|
|
136
|
+
const token = used.get(upper);
|
|
137
|
+
if (token === undefined || assigned.has(upper)) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const message = `Field symbol ${name} is never assigned in this ${procedure}`;
|
|
141
|
+
issues.push(issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity));
|
|
142
|
+
}
|
|
143
|
+
return issues;
|
|
144
|
+
}
|
|
145
|
+
/** collects the assigned field symbols, and the first use of each other field symbol */
|
|
146
|
+
walk(node, assigned, used) {
|
|
147
|
+
var _a;
|
|
148
|
+
for (const child of node.getChildren()) {
|
|
149
|
+
if (child instanceof token_node_1.TokenNode) {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const e = child.get();
|
|
153
|
+
if (e instanceof Expressions.FSTarget
|
|
154
|
+
|| e instanceof Expressions.InlineFS
|
|
155
|
+
|| (e instanceof Expressions.TargetFieldSymbol && this.isBinding(node))) {
|
|
156
|
+
const name = (_a = child.findFirstExpression(Expressions.FieldSymbol)) === null || _a === void 0 ? void 0 : _a.concatTokens();
|
|
157
|
+
if (name !== undefined) {
|
|
158
|
+
assigned.add(name.toUpperCase());
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else if (e instanceof Expressions.Compare && child.findDirectTokenByText("ASSIGNED") !== undefined) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
else if (e instanceof Expressions.FieldSymbol) {
|
|
165
|
+
const upper = child.concatTokens().toUpperCase();
|
|
166
|
+
if (used.has(upper) === false) {
|
|
167
|
+
used.set(upper, child.getFirstToken());
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
this.walk(child, assigned, used);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/** TargetFieldSymbol directly in these binds the field symbol, elsewhere it is a write to the assigned data */
|
|
176
|
+
isBinding(parent) {
|
|
177
|
+
const p = parent.get();
|
|
178
|
+
return p instanceof Statements.AssignLocalCopy
|
|
179
|
+
|| p instanceof Expressions.For
|
|
180
|
+
|| p instanceof Expressions.InlineLoopDefinition;
|
|
181
|
+
}
|
|
182
|
+
procedureName(statement) {
|
|
183
|
+
const s = statement.get();
|
|
184
|
+
if (s instanceof Statements.Form) {
|
|
185
|
+
return "form";
|
|
186
|
+
}
|
|
187
|
+
else if (s instanceof Statements.FunctionModule) {
|
|
188
|
+
return "function module";
|
|
189
|
+
}
|
|
190
|
+
return "method";
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
exports.FieldSymbolNeverAssigned = FieldSymbolNeverAssigned;
|
|
194
|
+
//# sourceMappingURL=field_symbol_never_assigned.js.map
|
|
@@ -55,6 +55,11 @@ class Conditions {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
class IdenticalConditionsConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
58
|
+
constructor() {
|
|
59
|
+
super(...arguments);
|
|
60
|
+
/** Report a comparison of an operand with itself, like a = a or a <> a */
|
|
61
|
+
this.selfComparison = true;
|
|
62
|
+
}
|
|
58
63
|
}
|
|
59
64
|
exports.IdenticalConditionsConf = IdenticalConditionsConf;
|
|
60
65
|
class IdenticalConditions extends _abap_rule_1.ABAPRule {
|
|
@@ -69,19 +74,30 @@ class IdenticalConditions extends _abap_rule_1.ABAPRule {
|
|
|
69
74
|
shortDescription: `Find identical conditions in IF + CASE + WHILE etc
|
|
70
75
|
|
|
71
76
|
Prerequsites: code is pretty printed with identical cAsE`,
|
|
77
|
+
extendedInformation: `Option selfComparison: reports a comparison with =, <>, <, >, <= or >= (and EQ, NE, LT, GT, LE, GE)
|
|
78
|
+
whose two operands are the same data object, like a = a or ls_new-id <> ls_new-id. The comparison is always true or
|
|
79
|
+
always false, usually one side should be another field.
|
|
80
|
+
|
|
81
|
+
Only operands that are data objects are compared: fields, components, attributes, field symbols, dereferences,
|
|
82
|
+
offset/length and table expressions without calls. Not reported: method calls and built-in functions, which can
|
|
83
|
+
return different values, literals like 1 = 1, ASSERT, and SQL conditions.`,
|
|
72
84
|
tags: [_irule_1.RuleTag.SingleFile],
|
|
73
85
|
badExample: `IF foo = bar OR 1 = a OR foo = bar.
|
|
74
86
|
ENDIF.
|
|
75
87
|
CASE bar.
|
|
76
88
|
WHEN '1'.
|
|
77
89
|
WHEN 'A' OR '1'.
|
|
78
|
-
ENDCASE
|
|
90
|
+
ENDCASE.
|
|
91
|
+
IF ls_new-id = ls_new-id.
|
|
92
|
+
ENDIF.`,
|
|
79
93
|
goodExample: `IF foo = bar OR 1 = a.
|
|
80
94
|
ENDIF.
|
|
81
95
|
CASE bar.
|
|
82
96
|
WHEN '1'.
|
|
83
97
|
WHEN 'A'.
|
|
84
|
-
ENDCASE
|
|
98
|
+
ENDCASE.
|
|
99
|
+
IF ls_new-id = ls_old-id.
|
|
100
|
+
ENDIF.`,
|
|
85
101
|
};
|
|
86
102
|
}
|
|
87
103
|
getConfig() {
|
|
@@ -105,9 +121,67 @@ ENDCASE.`,
|
|
|
105
121
|
for (const i of structure.findAllExpressions(Expressions.Cond)) {
|
|
106
122
|
issues = issues.concat(this.analyzeCond(file, i));
|
|
107
123
|
}
|
|
124
|
+
if (this.conf.selfComparison) {
|
|
125
|
+
issues = issues.concat(this.analyzeSelfComparison(file));
|
|
126
|
+
}
|
|
108
127
|
return issues;
|
|
109
128
|
}
|
|
110
129
|
////////////////
|
|
130
|
+
analyzeSelfComparison(file) {
|
|
131
|
+
const issues = [];
|
|
132
|
+
for (const statement of file.getStatements()) {
|
|
133
|
+
if (statement.get() instanceof Statements.Assert) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
for (const compare of statement.findAllExpressionsRecursive(Expressions.Compare)) {
|
|
137
|
+
const children = compare.getChildren();
|
|
138
|
+
const negated = children[0] instanceof nodes_1.TokenNode && children[0].getFirstToken().getStr().toUpperCase() === "NOT";
|
|
139
|
+
const rest = children.slice(negated ? 1 : 0);
|
|
140
|
+
if (rest.length !== 3
|
|
141
|
+
|| !(rest[0] instanceof nodes_1.ExpressionNode) || !(rest[0].get() instanceof Expressions.Source)
|
|
142
|
+
|| !(rest[1] instanceof nodes_1.ExpressionNode) || !(rest[1].get() instanceof Expressions.CompareOperator)
|
|
143
|
+
|| !(rest[2] instanceof nodes_1.ExpressionNode) || !(rest[2].get() instanceof Expressions.Source)) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const operator = rest[1].concatTokens().toUpperCase().replace(/ /g, "");
|
|
147
|
+
const value = this.selfValue(operator);
|
|
148
|
+
const left = this.dataObject(rest[0]);
|
|
149
|
+
if (value === undefined || left === undefined || left !== this.dataObject(rest[2])) {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const result = value !== negated ? "true" : "false";
|
|
153
|
+
const message = "Comparison is always " + result + ", " + rest[0].concatTokens() + " is compared with itself";
|
|
154
|
+
issues.push(issue_1.Issue.atRange(file, compare.getFirstToken().getStart(), compare.getLastToken().getEnd(), message, this.getMetadata().key, this.conf.severity));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return issues;
|
|
158
|
+
}
|
|
159
|
+
/** result of comparing a value with itself, undefined for operators like CO or CP */
|
|
160
|
+
selfValue(operator) {
|
|
161
|
+
if (["=", "EQ", "<=", "=<", "LE", ">=", "=>", "GE"].includes(operator)) {
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
else if (["<>", "><", "NE", "<", "LT", ">", "GT"].includes(operator)) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
/** the text of an operand that is a data object without calls, names in upper case, literals as they are */
|
|
170
|
+
dataObject(source) {
|
|
171
|
+
const children = source.getChildren();
|
|
172
|
+
if (!(children[0] instanceof nodes_1.ExpressionNode) || !(children[0].get() instanceof Expressions.FieldChain)
|
|
173
|
+
|| (children.length === 2 && !(children[1].get() instanceof Expressions.Dereference))
|
|
174
|
+
|| children.length > 2
|
|
175
|
+
|| source.findFirstExpression(Expressions.MethodCall) !== undefined
|
|
176
|
+
|| source.findFirstExpression(Expressions.MethodCallChain) !== undefined
|
|
177
|
+
|| source.findFirstExpression(Expressions.NewObject) !== undefined) {
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
return source.getTokens().map(t => {
|
|
181
|
+
const str = t.getStr();
|
|
182
|
+
return str.startsWith("'") || str.startsWith("`") || str.startsWith("|") || str.startsWith("}") ? str : str.toUpperCase();
|
|
183
|
+
}).join(" ");
|
|
184
|
+
}
|
|
111
185
|
analyzeCond(file, node) {
|
|
112
186
|
const conditions = new Conditions();
|
|
113
187
|
let operator = "";
|
package/build/src/rules/index.js
CHANGED
|
@@ -50,6 +50,7 @@ __exportStar(require("./cds_parser_error"), exports);
|
|
|
50
50
|
__exportStar(require("./chain_mainly_declarations"), exports);
|
|
51
51
|
__exportStar(require("./change_if_to_case"), exports);
|
|
52
52
|
__exportStar(require("./changing_sorted_line"), exports);
|
|
53
|
+
__exportStar(require("./character_field_literal_blanks"), exports);
|
|
53
54
|
__exportStar(require("./check_abstract"), exports);
|
|
54
55
|
__exportStar(require("./check_comments"), exports);
|
|
55
56
|
__exportStar(require("./check_ddic"), exports);
|
|
@@ -91,6 +92,7 @@ __exportStar(require("./else_after_all_returns"), exports);
|
|
|
91
92
|
__exportStar(require("./exit_or_check"), exports);
|
|
92
93
|
__exportStar(require("./expand_macros"), exports);
|
|
93
94
|
__exportStar(require("./exporting"), exports);
|
|
95
|
+
__exportStar(require("./field_symbol_never_assigned"), exports);
|
|
94
96
|
__exportStar(require("./final_newline"), exports);
|
|
95
97
|
__exportStar(require("./fm_global_parameters_obsolete"), exports);
|
|
96
98
|
__exportStar(require("./forbidden_identifier"), exports);
|
|
@@ -116,6 +118,7 @@ __exportStar(require("./in_statement_indentation"), exports);
|
|
|
116
118
|
__exportStar(require("./indentation"), exports);
|
|
117
119
|
__exportStar(require("./index_completely_contained"), exports);
|
|
118
120
|
__exportStar(require("./inline_data_old_versions"), exports);
|
|
121
|
+
__exportStar(require("./inline_generic_source"), exports);
|
|
119
122
|
__exportStar(require("./inline_packed_computation"), exports);
|
|
120
123
|
__exportStar(require("./intf_referencing_clas"), exports);
|
|
121
124
|
__exportStar(require("./invalid_table_index"), exports);
|
|
@@ -129,6 +132,7 @@ __exportStar(require("./line_only_punc"), exports);
|
|
|
129
132
|
__exportStar(require("./local_class_naming"), exports);
|
|
130
133
|
__exportStar(require("./local_testclass_consistency"), exports);
|
|
131
134
|
__exportStar(require("./local_variable_names"), exports);
|
|
135
|
+
__exportStar(require("./loop_target_misuse"), exports);
|
|
132
136
|
__exportStar(require("./macro_naming"), exports);
|
|
133
137
|
__exportStar(require("./main_file_contents"), exports);
|
|
134
138
|
__exportStar(require("./many_parentheses"), exports);
|
|
@@ -197,6 +201,7 @@ __exportStar(require("./select_single_full_key"), exports);
|
|
|
197
201
|
__exportStar(require("./selection_screen_naming"), exports);
|
|
198
202
|
__exportStar(require("./selection_screen_texts_missing"), exports);
|
|
199
203
|
__exportStar(require("./sequential_blank"), exports);
|
|
204
|
+
__exportStar(require("./sequential_read_sorted"), exports);
|
|
200
205
|
__exportStar(require("./short_case"), exports);
|
|
201
206
|
__exportStar(require("./sicf_consistency"), exports);
|
|
202
207
|
__exportStar(require("./single_use_expression_temp"), exports);
|
|
@@ -207,6 +212,7 @@ __exportStar(require("./space_before_colon"), exports);
|
|
|
207
212
|
__exportStar(require("./space_before_dot"), exports);
|
|
208
213
|
__exportStar(require("./sql_escape_host_variables"), exports);
|
|
209
214
|
__exportStar(require("./sql_value_conversion"), exports);
|
|
215
|
+
__exportStar(require("./stale_subrc"), exports);
|
|
210
216
|
__exportStar(require("./start_at_tab"), exports);
|
|
211
217
|
__exportStar(require("./static_call_via_instance"), exports);
|
|
212
218
|
__exportStar(require("./strict_sql"), exports);
|
|
@@ -222,6 +228,7 @@ __exportStar(require("./try_without_catch"), exports);
|
|
|
222
228
|
__exportStar(require("./type_form_parameters"), exports);
|
|
223
229
|
__exportStar(require("./types_naming"), exports);
|
|
224
230
|
__exportStar(require("./uncaught_exception"), exports);
|
|
231
|
+
__exportStar(require("./unit_test_assertions"), exports);
|
|
225
232
|
__exportStar(require("./unknown_types"), exports);
|
|
226
233
|
__exportStar(require("./unnecessary_chaining"), exports);
|
|
227
234
|
__exportStar(require("./unnecessary_copy"), exports);
|