@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
package/build/abaplint.d.ts
CHANGED
|
@@ -1257,6 +1257,7 @@ declare class ClassDefinition_3 extends Identifier implements IClassDefinition {
|
|
|
1257
1257
|
isSharedMemory(): boolean;
|
|
1258
1258
|
getCreateVisibility(): Visibility;
|
|
1259
1259
|
private checkClassNameLength;
|
|
1260
|
+
private checkLocalTypesInPublicSections;
|
|
1260
1261
|
private findSuper;
|
|
1261
1262
|
private checkMethodNameLength;
|
|
1262
1263
|
private checkClassConstructor;
|
|
@@ -0,0 +1,66 @@
|
|
|
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.hasKeyCompare = hasKeyCompare;
|
|
37
|
+
const Expressions = __importStar(require("../2_statements/expressions"));
|
|
38
|
+
const nodes_1 = require("../nodes");
|
|
39
|
+
/** True if a conjunct of the WHERE condition reachable through AND only, ie. not under OR or NOT,
|
|
40
|
+
* compares the key component with = or IS INITIAL. Without such a comparison of its first component,
|
|
41
|
+
* a sorted key cannot be used to optimize the WHERE condition */
|
|
42
|
+
function hasKeyCompare(cond, component) {
|
|
43
|
+
if (cond.findDirectTokenByText("OR") !== undefined) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
for (const child of cond.getChildren()) {
|
|
47
|
+
if (child.get() instanceof Expressions.ComponentCompare && child instanceof nodes_1.ExpressionNode) {
|
|
48
|
+
const concat = child.concatTokens().toUpperCase().replace(/\s+/g, " ");
|
|
49
|
+
if (concat.startsWith(component + " = ")
|
|
50
|
+
|| concat.startsWith(component + " EQ ")
|
|
51
|
+
|| concat === component + " IS INITIAL") {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else if (child.get() instanceof Expressions.ComponentCondSub
|
|
56
|
+
&& child instanceof nodes_1.ExpressionNode
|
|
57
|
+
&& child.findDirectTokenByText("NOT") === undefined) {
|
|
58
|
+
const sub = child.findDirectExpression(Expressions.ComponentCond);
|
|
59
|
+
if (sub !== undefined && hasKeyCompare(sub, component)) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=_key_compare.js.map
|
|
@@ -45,6 +45,7 @@ const _type_utils_1 = require("../_type_utils");
|
|
|
45
45
|
const _syntax_input_1 = require("../_syntax_input");
|
|
46
46
|
class InsertInternal {
|
|
47
47
|
runSyntax(node, input) {
|
|
48
|
+
var _a;
|
|
48
49
|
let targetType;
|
|
49
50
|
const t = node.findDirectExpression(Expressions.Target);
|
|
50
51
|
if (t) {
|
|
@@ -107,6 +108,13 @@ class InsertInternal {
|
|
|
107
108
|
// yea, well, INSERT doesnt convert the values automatically, like everything else?
|
|
108
109
|
error = true;
|
|
109
110
|
}
|
|
111
|
+
else if (sourceType instanceof basic_1.CharacterType
|
|
112
|
+
&& targetType instanceof basic_1.CharacterType
|
|
113
|
+
&& ((_a = sourceType.getAbstractTypeData()) === null || _a === void 0 ? void 0 : _a.derivedFromConstant) === true
|
|
114
|
+
&& sourceType.getLength() !== targetType.getLength()) {
|
|
115
|
+
// character literal of different length than the row type
|
|
116
|
+
error = true;
|
|
117
|
+
}
|
|
110
118
|
if (error === true) {
|
|
111
119
|
const message = "Types not compatible";
|
|
112
120
|
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
|
|
@@ -35,7 +35,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.Loop = void 0;
|
|
37
37
|
const Expressions = __importStar(require("../../2_statements/expressions"));
|
|
38
|
-
const nodes_1 = require("../../nodes");
|
|
39
38
|
const basic_1 = require("../../types/basic");
|
|
40
39
|
const target_1 = require("../expressions/target");
|
|
41
40
|
const source_1 = require("../expressions/source");
|
|
@@ -47,6 +46,7 @@ const dynamic_1 = require("../expressions/dynamic");
|
|
|
47
46
|
const loop_group_by_1 = require("../expressions/loop_group_by");
|
|
48
47
|
const _syntax_input_1 = require("../_syntax_input");
|
|
49
48
|
const version_1 = require("../../../version");
|
|
49
|
+
const _key_compare_1 = require("../_key_compare");
|
|
50
50
|
class Loop {
|
|
51
51
|
runSyntax(node, input) {
|
|
52
52
|
var _a, _b;
|
|
@@ -151,7 +151,7 @@ class Loop {
|
|
|
151
151
|
// the first component of a sorted secondary key must be compared with = or IS INITIAL
|
|
152
152
|
// in a part of the condition joined by AND, otherwise the WHERE cannot be optimized
|
|
153
153
|
const first = key.keyFields[0].toUpperCase();
|
|
154
|
-
if (
|
|
154
|
+
if ((0, _key_compare_1.hasKeyCompare)(cond, first) === false) {
|
|
155
155
|
const message = "Loop, WHERE cannot be optimized for secondary key " + name +
|
|
156
156
|
", key component " + first + " needs a comparison with = or IS INITIAL joined by AND";
|
|
157
157
|
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
|
|
@@ -198,31 +198,6 @@ class Loop {
|
|
|
198
198
|
loop_group_by_1.LoopGroupBy.runSyntax(group, input);
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
|
-
// true if a conjunct reachable through AND only, ie. not under OR or NOT, compares the component with = or IS INITIAL
|
|
202
|
-
hasKeyCompare(cond, component) {
|
|
203
|
-
if (cond.findDirectTokenByText("OR") !== undefined) {
|
|
204
|
-
return false;
|
|
205
|
-
}
|
|
206
|
-
for (const child of cond.getChildren()) {
|
|
207
|
-
if (child.get() instanceof Expressions.ComponentCompare && child instanceof nodes_1.ExpressionNode) {
|
|
208
|
-
const concat = child.concatTokens().toUpperCase().replace(/\s+/g, " ");
|
|
209
|
-
if (concat.startsWith(component + " = ")
|
|
210
|
-
|| concat.startsWith(component + " EQ ")
|
|
211
|
-
|| concat === component + " IS INITIAL") {
|
|
212
|
-
return true;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
else if (child.get() instanceof Expressions.ComponentCondSub
|
|
216
|
-
&& child instanceof nodes_1.ExpressionNode
|
|
217
|
-
&& child.findDirectTokenByText("NOT") === undefined) {
|
|
218
|
-
const sub = child.findDirectExpression(Expressions.ComponentCond);
|
|
219
|
-
if (sub !== undefined && this.hasKeyCompare(sub, component)) {
|
|
220
|
-
return true;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
201
|
}
|
|
227
202
|
exports.Loop = Loop;
|
|
228
203
|
//# sourceMappingURL=loop.js.map
|
|
@@ -80,7 +80,7 @@ class ClassDefinition extends _identifier_1.Identifier {
|
|
|
80
80
|
this.events.push(new event_definition_1.EventDefinition(e, visibility_1.Visibility.Public, input)); // todo, all these are not Public
|
|
81
81
|
}
|
|
82
82
|
this.methodDefs = new method_definitions_1.MethodDefinitions(node, input);
|
|
83
|
-
input.scope.pop(node.getLastToken().getEnd());
|
|
83
|
+
const scope = input.scope.pop(node.getLastToken().getEnd());
|
|
84
84
|
const concat = def.concatTokens().toUpperCase();
|
|
85
85
|
this.testing = concat.includes(" FOR TESTING");
|
|
86
86
|
this.sharedMemory = concat.includes(" SHARED MEMORY ENABLED");
|
|
@@ -102,6 +102,7 @@ class ClassDefinition extends _identifier_1.Identifier {
|
|
|
102
102
|
this.checkClassNameLength(input);
|
|
103
103
|
this.checkMethodNameLength(input);
|
|
104
104
|
this.checkClassConstructor(input);
|
|
105
|
+
this.checkLocalTypesInPublicSections(input, node, scope.getTop());
|
|
105
106
|
}
|
|
106
107
|
getFriends() {
|
|
107
108
|
return this.friends;
|
|
@@ -156,6 +157,56 @@ class ClassDefinition extends _identifier_1.Identifier {
|
|
|
156
157
|
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, this.getToken(), message));
|
|
157
158
|
}
|
|
158
159
|
}
|
|
160
|
+
// the local types, classes and interfaces of a class pool can only be used in the PRIVATE SECTION of the global class
|
|
161
|
+
checkLocalTypesInPublicSections(input, node, scope) {
|
|
162
|
+
if (this.globalValue === false || input.filename.toLowerCase().endsWith(".clas.abap") === false) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const prefix = input.filename.toLowerCase().replace(/abap$/, "");
|
|
166
|
+
const isLocal = (filename) => {
|
|
167
|
+
const lower = filename.toLowerCase();
|
|
168
|
+
return lower.startsWith(prefix)
|
|
169
|
+
&& (lower.endsWith(".clas.locals_def.abap") || lower.endsWith(".clas.locals_imp.abap"));
|
|
170
|
+
};
|
|
171
|
+
const references = [];
|
|
172
|
+
const collect = (n) => {
|
|
173
|
+
for (const r of n.getData().references) {
|
|
174
|
+
if ((r.referenceType === _reference_1.ReferenceType.TypeReference || r.referenceType === _reference_1.ReferenceType.ObjectOrientedReference)
|
|
175
|
+
&& r.position.getFilename() === input.filename
|
|
176
|
+
&& r.position.getName().includes("~") === false // lif~meth of an ALIASES, the INTERFACES statement is reported
|
|
177
|
+
&& r.resolved !== undefined
|
|
178
|
+
&& isLocal(r.resolved.getFilename())) {
|
|
179
|
+
references.push(r);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
n.getChildren().forEach(collect);
|
|
183
|
+
};
|
|
184
|
+
collect(scope);
|
|
185
|
+
if (references.length === 0) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const sections = [
|
|
189
|
+
{ section: node.findDirectStructure(Structures.PublicSection), name: "PUBLIC" },
|
|
190
|
+
];
|
|
191
|
+
// a FINAL class has no subclasses, so the PROTECTED SECTION is effectively private
|
|
192
|
+
if (this.finalValue === false) {
|
|
193
|
+
sections.push({ section: node.findDirectStructure(Structures.ProtectedSection), name: "PROTECTED" });
|
|
194
|
+
}
|
|
195
|
+
for (const { section, name } of sections) {
|
|
196
|
+
for (const statement of (section === null || section === void 0 ? void 0 : section.findAllStatementNodes()) || []) {
|
|
197
|
+
// compare with the tokens, the statements of a chain share the first tokens
|
|
198
|
+
const tokens = statement.getTokens();
|
|
199
|
+
const found = references
|
|
200
|
+
.filter(r => tokens.some(t => t.getStart().equals(r.position.getStart())))
|
|
201
|
+
.sort((a, b) => a.position.getStart().isBefore(b.position.getStart()) ? -1 : 1)[0];
|
|
202
|
+
if (found !== undefined) {
|
|
203
|
+
const message = "\"" + found.position.getName().toUpperCase() +
|
|
204
|
+
"\" is local to the class pool and cannot be used in the " + name + " SECTION of the global class";
|
|
205
|
+
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, found.position.getToken(), message));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
159
210
|
findSuper(def, input) {
|
|
160
211
|
var _a;
|
|
161
212
|
const token = (_a = def === null || def === void 0 ? void 0 : def.findDirectExpression(expressions_1.SuperClassName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
|
package/build/src/registry.js
CHANGED
|
@@ -50,6 +50,7 @@ exports.isReferenceType = isReferenceType;
|
|
|
50
50
|
exports.identicalTypes = identicalTypes;
|
|
51
51
|
exports.simplePredicate = simplePredicate;
|
|
52
52
|
exports.characterConstant = characterConstant;
|
|
53
|
+
exports.textLiteral = textLiteral;
|
|
53
54
|
exports.sameCharacters = sameCharacters;
|
|
54
55
|
exports.isCondition = isCondition;
|
|
55
56
|
exports.dataSource = dataSource;
|
|
@@ -0,0 +1,264 @@
|
|
|
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.CharacterFieldLiteralBlanks = exports.CharacterFieldLiteralBlanksConf = 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 nodes_1 = require("../abap/nodes");
|
|
44
|
+
const edit_helper_1 = require("../edit_helper");
|
|
45
|
+
const severity_1 = require("../severity");
|
|
46
|
+
class CharacterFieldLiteralBlanksConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
47
|
+
constructor() {
|
|
48
|
+
super(...arguments);
|
|
49
|
+
this.severity = severity_1.Severity.Warning;
|
|
50
|
+
/** Report a FIND or REPLACE search pattern that is a character field literal containing only blanks, or space,
|
|
51
|
+
* the pattern is empty: ALL OCCURRENCES raises an exception, FIRST OCCURRENCE matches before the first character */
|
|
52
|
+
this.searchPattern = true;
|
|
53
|
+
/** Report a character field literal ending with a blank as an operand of &&, of CONCATENATE without
|
|
54
|
+
* RESPECTING BLANKS, or as an embedded expression in a string template, the trailing blanks are dropped */
|
|
55
|
+
this.concatenation = true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.CharacterFieldLiteralBlanksConf = CharacterFieldLiteralBlanksConf;
|
|
59
|
+
class CharacterFieldLiteralBlanks extends _abap_rule_1.ABAPRule {
|
|
60
|
+
constructor() {
|
|
61
|
+
super(...arguments);
|
|
62
|
+
this.conf = new CharacterFieldLiteralBlanksConf();
|
|
63
|
+
}
|
|
64
|
+
getMetadata() {
|
|
65
|
+
return {
|
|
66
|
+
key: "character_field_literal_blanks",
|
|
67
|
+
title: "Ignored blanks in character field literals",
|
|
68
|
+
shortDescription: `Reports character field literals ('...') whose blanks are ignored where the code relies on them`,
|
|
69
|
+
extendedInformation: `A character field literal '...' (called text field literal in the ABAP
|
|
70
|
+
documentation) has type c, and trailing blanks of type c operands are ignored in many positions.
|
|
71
|
+
A text string literal \`...\` has type string and keeps them.
|
|
72
|
+
|
|
73
|
+
Option searchPattern: a FIND or REPLACE search pattern (SUBSTRING, character mode) that is a character field
|
|
74
|
+
literal containing only blanks, '' or space. The pattern is empty: FIND/REPLACE ALL OCCURRENCES raises
|
|
75
|
+
CX_SY_FIND_INFINITE_LOOP/CX_SY_REPLACE_INFINITE_LOOP, the first occurrence is found before the first character.
|
|
76
|
+
https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abapfind_pattern.htm
|
|
77
|
+
|
|
78
|
+
Option concatenation: a character field literal ending with a blank as an operand of &&, as an operand of
|
|
79
|
+
CONCATENATE without RESPECTING BLANKS, or as the whole embedded expression of a string template without
|
|
80
|
+
formatting options. The trailing blanks are dropped, 'Hello ' && name gives "HelloJohn". space is reported
|
|
81
|
+
the same way.
|
|
82
|
+
https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abenstring_operators.htm
|
|
83
|
+
|
|
84
|
+
The quick fix replaces the literal with a text string literal with the same content.
|
|
85
|
+
|
|
86
|
+
Not reported: text string literals, CONCATENATE ... RESPECTING BLANKS, the separator of SEPARATED BY
|
|
87
|
+
(its trailing blanks are kept), the literal operator &, literals with a text symbol, PCRE and REGEX
|
|
88
|
+
patterns, byte mode, comparisons and parameters.`,
|
|
89
|
+
tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
|
|
90
|
+
badExample: `REPLACE ALL OCCURRENCES OF ' ' IN lv_text WITH ''.
|
|
91
|
+
lv_text = 'Hello ' && lv_name.`,
|
|
92
|
+
goodExample: `REPLACE ALL OCCURRENCES OF \` \` IN lv_text WITH ''.
|
|
93
|
+
lv_text = \`Hello \` && lv_name.`,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
getConfig() {
|
|
97
|
+
return this.conf;
|
|
98
|
+
}
|
|
99
|
+
setConfig(conf) {
|
|
100
|
+
this.conf = conf;
|
|
101
|
+
}
|
|
102
|
+
runParsed(file) {
|
|
103
|
+
const issues = [];
|
|
104
|
+
for (const statement of file.getStatements()) {
|
|
105
|
+
if (this.conf.searchPattern === true) {
|
|
106
|
+
const issue = this.checkSearchPattern(file, statement);
|
|
107
|
+
if (issue !== undefined) {
|
|
108
|
+
issues.push(issue);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (this.conf.concatenation === true) {
|
|
112
|
+
issues.push(...this.checkConcatenation(file, statement));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return issues;
|
|
116
|
+
}
|
|
117
|
+
////////////////
|
|
118
|
+
checkSearchPattern(file, statement) {
|
|
119
|
+
const s = statement.get();
|
|
120
|
+
const isFind = s instanceof Statements.Find;
|
|
121
|
+
if ((isFind === false && !(s instanceof Statements.Replace))
|
|
122
|
+
|| statement.findDirectTokenByText("IN") === undefined
|
|
123
|
+
|| statement.findDirectTokenByText("BYTE") !== undefined) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
const pattern = this.findPattern(statement);
|
|
127
|
+
if (pattern === undefined || pattern.getChildren().length !== 1) {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
const token = this.blankOperand(pattern);
|
|
131
|
+
if (token === undefined || this.content(token).trim() !== "") {
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
const name = isFind ? "FIND" : "REPLACE";
|
|
135
|
+
const table = statement.findDirectTokenByText("TABLE") !== undefined;
|
|
136
|
+
let effect = "it is found before the first character";
|
|
137
|
+
if (statement.findDirectTokenByText("ALL") !== undefined) {
|
|
138
|
+
effect = isFind && table
|
|
139
|
+
? "FIND ALL OCCURRENCES IN TABLE with an empty pattern is not possible"
|
|
140
|
+
: `${name} ALL OCCURRENCES raises CX_SY_${name}_INFINITE_LOOP`;
|
|
141
|
+
}
|
|
142
|
+
const message = `Search pattern ${token.getStr()} is empty, blanks of character field literals are ignored, ${effect}`;
|
|
143
|
+
return issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity, this.buildFix(file, token));
|
|
144
|
+
}
|
|
145
|
+
/** the substring pattern of FIND or REPLACE, undefined for PCRE and REGEX and for REPLACE SECTION */
|
|
146
|
+
findPattern(statement) {
|
|
147
|
+
const children = statement.getChildren();
|
|
148
|
+
for (let i = 1; i < children.length; i++) {
|
|
149
|
+
const child = children[i];
|
|
150
|
+
if (child instanceof nodes_1.TokenNode && child.concatTokens().toUpperCase() === "IN") {
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
else if (!(child instanceof nodes_1.ExpressionNode) || !(child.get() instanceof Expressions.Source)) {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const before = children[i - 1];
|
|
157
|
+
if (before instanceof nodes_1.ExpressionNode && before.get() instanceof Expressions.FindType) {
|
|
158
|
+
return before.concatTokens().toUpperCase() === "SUBSTRING" ? child : undefined;
|
|
159
|
+
}
|
|
160
|
+
else if (before instanceof nodes_1.TokenNode && CharacterFieldLiteralBlanks.beforePattern.has(before.concatTokens().toUpperCase())) {
|
|
161
|
+
return child;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
checkConcatenation(file, statement) {
|
|
167
|
+
const operands = [];
|
|
168
|
+
const sources = statement.findAllExpressionsRecursive(Expressions.Source);
|
|
169
|
+
// left operands of &&
|
|
170
|
+
for (const source of sources) {
|
|
171
|
+
if (source.findDirectTokenByText("&&") !== undefined) {
|
|
172
|
+
operands.push(source);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// right operands of && and &&=
|
|
176
|
+
for (const node of [statement, ...sources]) {
|
|
177
|
+
const children = node.getChildren();
|
|
178
|
+
for (let i = 1; i < children.length; i++) {
|
|
179
|
+
const before = children[i - 1].concatTokens();
|
|
180
|
+
const child = children[i];
|
|
181
|
+
if ((before === "&&" || before === "&&=")
|
|
182
|
+
&& child instanceof nodes_1.ExpressionNode
|
|
183
|
+
&& child.get() instanceof Expressions.Source) {
|
|
184
|
+
operands.push(child);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// embedded expressions without formatting options
|
|
189
|
+
for (const embedded of statement.findAllExpressionsRecursive(Expressions.StringTemplateSource)) {
|
|
190
|
+
const source = embedded.findDirectExpression(Expressions.Source);
|
|
191
|
+
if (source !== undefined
|
|
192
|
+
&& source.getChildren().length === 1
|
|
193
|
+
&& embedded.findDirectExpression(Expressions.StringTemplateFormatting) === undefined) {
|
|
194
|
+
operands.push(source);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// CONCATENATE without RESPECTING BLANKS, the separator keeps its blanks
|
|
198
|
+
if (statement.get() instanceof Statements.Concatenate
|
|
199
|
+
&& statement.findDirectTokenByText("RESPECTING") === undefined
|
|
200
|
+
&& statement.findDirectTokenByText("BYTE") === undefined) {
|
|
201
|
+
for (const child of statement.getChildren()) {
|
|
202
|
+
if (child instanceof nodes_1.TokenNode && child.concatTokens().toUpperCase() === "INTO") {
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
else if (child instanceof nodes_1.ExpressionNode && child.get() instanceof Expressions.SimpleSource3) {
|
|
206
|
+
operands.push(child);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const issues = [];
|
|
211
|
+
const reported = new Set();
|
|
212
|
+
for (const operand of operands) {
|
|
213
|
+
const token = this.blankOperand(operand);
|
|
214
|
+
if (token === undefined || reported.has(token)) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
const content = this.content(token);
|
|
218
|
+
if (content === "" || content.endsWith(" ") === false) {
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
reported.add(token);
|
|
222
|
+
const message = token.getStr().startsWith("'")
|
|
223
|
+
? `Trailing blanks of ${token.getStr()} are ignored here, use a text string literal`
|
|
224
|
+
: `${token.getStr()} is ignored here, use \` \``;
|
|
225
|
+
issues.push(issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity, this.buildFix(file, token)));
|
|
226
|
+
}
|
|
227
|
+
return issues;
|
|
228
|
+
}
|
|
229
|
+
/** the token of a character field literal or of space at the start of the operand */
|
|
230
|
+
blankOperand(operand) {
|
|
231
|
+
var _a;
|
|
232
|
+
const first = operand.getChildren()[0];
|
|
233
|
+
if (!(first instanceof nodes_1.ExpressionNode)) {
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
if (first.get() instanceof Expressions.Constant) {
|
|
237
|
+
const str = (_a = first.findDirectExpression(Expressions.ConstantString)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
|
|
238
|
+
return (str === null || str === void 0 ? void 0 : str.getStr().startsWith("'")) ? str : undefined;
|
|
239
|
+
}
|
|
240
|
+
else if (first.get() instanceof Expressions.FieldChain && first.concatTokens().toUpperCase() === "SPACE") {
|
|
241
|
+
return first.getFirstToken();
|
|
242
|
+
}
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
/** the value of a character field literal, " " for space */
|
|
246
|
+
content(token) {
|
|
247
|
+
const str = token.getStr();
|
|
248
|
+
if (str.startsWith("'") === false) {
|
|
249
|
+
return " ";
|
|
250
|
+
}
|
|
251
|
+
return str.substring(1, str.length - 1).replace(/''/g, "'");
|
|
252
|
+
}
|
|
253
|
+
buildFix(file, token) {
|
|
254
|
+
const content = this.content(token);
|
|
255
|
+
if (content === "") {
|
|
256
|
+
return undefined;
|
|
257
|
+
}
|
|
258
|
+
return edit_helper_1.EditHelper.replaceToken(file, token, "`" + content.replace(/`/g, "``") + "`");
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
exports.CharacterFieldLiteralBlanks = CharacterFieldLiteralBlanks;
|
|
262
|
+
// tokens directly before the pattern of FIND and REPLACE, when no FindType is given
|
|
263
|
+
CharacterFieldLiteralBlanks.beforePattern = new Set(["FIND", "REPLACE", "OF", "OCCURRENCE", "OCCURRENCES", "OCCURENCE", "OCCURENCES"]);
|
|
264
|
+
//# sourceMappingURL=character_field_literal_blanks.js.map
|