@abaplint/core 2.120.79 → 2.120.81
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 -1
- package/build/src/abap/5_syntax/_builtin.js +23 -23
- package/build/src/abap/5_syntax/_type_utils.js +3 -1
- package/build/src/abap/5_syntax/expressions/method_call_chain.js +1 -1
- package/build/src/abap/nodes/_abstract_node.js +20 -7
- package/build/src/registry.js +1 -1
- package/build/src/rules/_procedure_analysis.js +1204 -0
- package/build/src/rules/alias_never_reassigned.js +132 -0
- package/build/src/rules/boolean_flag_via_if.js +175 -0
- package/build/src/rules/bound_check_after_create.js +262 -0
- package/build/src/rules/clear_after_declaration.js +77 -0
- package/build/src/rules/constant_condition.js +202 -0
- package/build/src/rules/copy_chain.js +162 -0
- package/build/src/rules/copy_of_initial_variable.js +135 -0
- package/build/src/rules/index.js +10 -0
- package/build/src/rules/single_use_expression_temp.js +202 -0
- package/build/src/rules/try_cast_empty_catch.js +159 -0
- package/build/src/rules/unnecessary_copy.js +133 -0
- package/package.json +1 -1
|
@@ -0,0 +1,202 @@
|
|
|
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.ConstantCondition = exports.ConstantConditionConf = void 0;
|
|
37
|
+
const Expressions = __importStar(require("../abap/2_statements/expressions"));
|
|
38
|
+
const basic_1 = require("../abap/types/basic");
|
|
39
|
+
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
40
|
+
const _irule_1 = require("./_irule");
|
|
41
|
+
const _procedure_analysis_1 = require("./_procedure_analysis");
|
|
42
|
+
class ConstantConditionConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
43
|
+
}
|
|
44
|
+
exports.ConstantConditionConf = ConstantConditionConf;
|
|
45
|
+
class ConstantCondition {
|
|
46
|
+
constructor() {
|
|
47
|
+
this.conf = new ConstantConditionConf();
|
|
48
|
+
}
|
|
49
|
+
getMetadata() {
|
|
50
|
+
return {
|
|
51
|
+
key: "constant_condition",
|
|
52
|
+
title: "Constant condition",
|
|
53
|
+
shortDescription: `Finds IF and ELSEIF conditions on local variables whose value is known`,
|
|
54
|
+
extendedInformation: `Reports two cases, for local variables of a METHOD, FORM or FUNCTION.
|
|
55
|
+
|
|
56
|
+
1. DATA(c) = <constant>. where the constant is a character literal like 'X', or a character constant like
|
|
57
|
+
abap_true, abap_false or space, and the only other reference to c is the condition of an IF or ELSEIF:
|
|
58
|
+
c = <constant>, c <> <constant>, EQ, NE, c IS INITIAL, c IS NOT INITIAL, optionally with NOT.
|
|
59
|
+
The declaration must be executed before the condition on every path: the IF is in the block of the
|
|
60
|
+
declaration or a nested block. The quick fix deletes the declaration.
|
|
61
|
+
|
|
62
|
+
2. DATA v TYPE ... without VALUE, where v is never changed, except by CLEAR v., and its address is never taken,
|
|
63
|
+
in a condition v IS [NOT] INITIAL or v IS [NOT] BOUND. The declaration is kept.
|
|
64
|
+
|
|
65
|
+
The quick fix removes the IF branch that is never taken, or keeps the branch that is always taken and
|
|
66
|
+
removes the rest, also in ELSEIF chains: a first IF branch that is never taken turns the next ELSEIF into IF,
|
|
67
|
+
an ELSEIF branch that is always taken turns into ELSE. Nothing is reported if a removed branch declares
|
|
68
|
+
data that is used outside of it.
|
|
69
|
+
|
|
70
|
+
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
71
|
+
INCLUDE, test seams, enhancements or native SQL. No release requirement.`,
|
|
72
|
+
tags: [_irule_1.RuleTag.Quickfix],
|
|
73
|
+
badExample: `DATA(lv_active) = abap_true.
|
|
74
|
+
IF lv_active = abap_true.
|
|
75
|
+
run( ).
|
|
76
|
+
ELSE.
|
|
77
|
+
skip( ).
|
|
78
|
+
ENDIF.`,
|
|
79
|
+
goodExample: `run( ).`,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
getConfig() {
|
|
83
|
+
return this.conf;
|
|
84
|
+
}
|
|
85
|
+
setConfig(conf) {
|
|
86
|
+
this.conf = conf;
|
|
87
|
+
}
|
|
88
|
+
initialize(reg) {
|
|
89
|
+
this.reg = reg;
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
run(obj) {
|
|
93
|
+
const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
|
|
94
|
+
if (analysis === undefined) {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
const issues = [];
|
|
98
|
+
for (const procedure of analysis.procedures) {
|
|
99
|
+
if (procedure.supported === false) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const candidates = [];
|
|
103
|
+
for (const variable of procedure.locals()) {
|
|
104
|
+
if (variable.inline) {
|
|
105
|
+
this.constantVariable(procedure, variable, candidates);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
this.initialVariable(procedure, variable, candidates);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
issues.push(...(0, _procedure_analysis_1.foldIssues)(procedure.file, candidates, this.getMetadata().key, this.conf.severity));
|
|
112
|
+
}
|
|
113
|
+
return issues;
|
|
114
|
+
}
|
|
115
|
+
/** DATA(c) = abap_true. IF c = abap_true. */
|
|
116
|
+
constantVariable(procedure, variable, candidates) {
|
|
117
|
+
const declaration = variable.declaration;
|
|
118
|
+
const move = (0, _procedure_analysis_1.plainMove)(declaration);
|
|
119
|
+
const read = variable.occurrences[0];
|
|
120
|
+
if (move === undefined || move.operator !== "="
|
|
121
|
+
|| move.target.getChildren().length !== 1
|
|
122
|
+
|| move.target.findDirectExpression(Expressions.InlineData) === undefined
|
|
123
|
+
|| !(variable.identifier.getType() instanceof basic_1.CharacterType)
|
|
124
|
+
|| variable.occurrences.length !== 1 || read.kind !== _procedure_analysis_1.OccurrenceKind.Read
|
|
125
|
+
|| !procedure.dominates(declaration, read.statement)) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const value = (0, _procedure_analysis_1.characterConstant)(procedure, move.source);
|
|
129
|
+
const result = value === undefined ? undefined : this.evaluate(procedure, read, value);
|
|
130
|
+
if (result === undefined) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const structure = procedure.ifStructure(read.statement);
|
|
134
|
+
const fold = structure === undefined ? undefined : (0, _procedure_analysis_1.foldIf)(procedure, structure, read.statement, result);
|
|
135
|
+
if (structure === undefined || fold === undefined) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
candidates.push({
|
|
139
|
+
structure,
|
|
140
|
+
statement: read.statement,
|
|
141
|
+
message: "Condition is always " + (result ? "true" : "false") + ", " + variable.identifier.getName() + " is constant",
|
|
142
|
+
fix: (0, _procedure_analysis_1.mergeEdits)(procedure.file, [fold, (0, _procedure_analysis_1.deleteStatement)(procedure.file, declaration)]),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/** DATA v TYPE ... never changed: IF v IS INITIAL / IS BOUND */
|
|
146
|
+
initialVariable(procedure, variable, candidates) {
|
|
147
|
+
if (!(0, _procedure_analysis_1.plainData)(variable.declaration) || variable.escapes()
|
|
148
|
+
|| variable.writes().some(w => { var _a; return ((_a = (0, _procedure_analysis_1.plainClear)(w.statement)) === null || _a === void 0 ? void 0 : _a.getStart().equals(w.token.getStart())) !== true; })) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
for (const read of variable.reads()) {
|
|
152
|
+
const predicate = (0, _procedure_analysis_1.simplePredicate)(read.statement);
|
|
153
|
+
if (predicate === undefined || !this.isOperand(predicate.left, read)
|
|
154
|
+
|| (predicate.kind !== _procedure_analysis_1.PredicateKind.Initial && predicate.kind !== _procedure_analysis_1.PredicateKind.Bound)) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
// initial: IS INITIAL is true, IS BOUND is false
|
|
158
|
+
const result = (predicate.kind === _procedure_analysis_1.PredicateKind.Initial) !== predicate.negated;
|
|
159
|
+
const structure = procedure.ifStructure(read.statement);
|
|
160
|
+
const fix = structure === undefined ? undefined : (0, _procedure_analysis_1.foldIf)(procedure, structure, read.statement, result);
|
|
161
|
+
if (structure === undefined || fix === undefined) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
candidates.push({
|
|
165
|
+
structure,
|
|
166
|
+
statement: read.statement,
|
|
167
|
+
message: "Condition is always " + (result ? "true" : "false") + ", " + variable.identifier.getName() + " is never changed",
|
|
168
|
+
fix,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
evaluate(procedure, read, value) {
|
|
173
|
+
const predicate = (0, _procedure_analysis_1.simplePredicate)(read.statement);
|
|
174
|
+
if (predicate === undefined) {
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
if (predicate.kind === _procedure_analysis_1.PredicateKind.Initial && this.isOperand(predicate.left, read)) {
|
|
178
|
+
return (0, _procedure_analysis_1.sameCharacters)(value, "") !== predicate.negated;
|
|
179
|
+
}
|
|
180
|
+
else if (predicate.kind === _procedure_analysis_1.PredicateKind.Equal) {
|
|
181
|
+
let other = predicate.right;
|
|
182
|
+
if (!this.isOperand(predicate.left, read)) {
|
|
183
|
+
if (!this.isOperand(predicate.right, read)) {
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
other = predicate.left;
|
|
187
|
+
}
|
|
188
|
+
const compared = (0, _procedure_analysis_1.characterConstant)(procedure, other);
|
|
189
|
+
if (compared === undefined) {
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
return (0, _procedure_analysis_1.sameCharacters)(value, compared) !== predicate.negated;
|
|
193
|
+
}
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
isOperand(source, read) {
|
|
197
|
+
return source.countTokens() === 1 && source.findDirectExpression(Expressions.FieldChain) !== undefined
|
|
198
|
+
&& source.getFirstToken().getStart().equals(read.token.getStart());
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
exports.ConstantCondition = ConstantCondition;
|
|
202
|
+
//# sourceMappingURL=constant_condition.js.map
|
|
@@ -0,0 +1,162 @@
|
|
|
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.CopyChain = exports.CopyChainConf = void 0;
|
|
37
|
+
const Expressions = __importStar(require("../abap/2_statements/expressions"));
|
|
38
|
+
const edit_helper_1 = require("../edit_helper");
|
|
39
|
+
const issue_1 = require("../issue");
|
|
40
|
+
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
41
|
+
const _irule_1 = require("./_irule");
|
|
42
|
+
const _procedure_analysis_1 = require("./_procedure_analysis");
|
|
43
|
+
class CopyChainConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
44
|
+
}
|
|
45
|
+
exports.CopyChainConf = CopyChainConf;
|
|
46
|
+
class CopyChain {
|
|
47
|
+
constructor() {
|
|
48
|
+
this.conf = new CopyChainConf();
|
|
49
|
+
}
|
|
50
|
+
getMetadata() {
|
|
51
|
+
return {
|
|
52
|
+
key: "copy_chain",
|
|
53
|
+
title: "Copy chain",
|
|
54
|
+
shortDescription: `Finds a local variable that only passes a value on from one variable to another`,
|
|
55
|
+
extendedInformation: `Reports DATA v TYPE ... [CLEAR v.] v = src. ... y = v. when all of the following hold:
|
|
56
|
+
|
|
57
|
+
* v is a local variable of a METHOD, FORM or FUNCTION, declared with DATA without VALUE
|
|
58
|
+
* v has exactly one write besides CLEAR: v = src., and all CLEARs are before it
|
|
59
|
+
* v has exactly one read, the complete source of y = v.
|
|
60
|
+
* src is a local variable, its address is never taken, and it is not written from v = src. until y = v.
|
|
61
|
+
* v = src. is executed before y = v. on every path: y = v. is in the same block or a nested block,
|
|
62
|
+
and both are in the same loop
|
|
63
|
+
* v and src are both reference types, or have identical types; for other types the copy into v can convert,
|
|
64
|
+
e.g. truncate a string into a c field. For DATA(y) = v. the types must be identical, else y changes its type
|
|
65
|
+
* the declaration, the CLEARs and v = src. are not chained
|
|
66
|
+
|
|
67
|
+
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
68
|
+
INCLUDE, test seams, enhancements or native SQL.
|
|
69
|
+
|
|
70
|
+
The quick fix deletes the declaration, the CLEARs and v = src., and changes the read to y = src.
|
|
71
|
+
No release requirement.`,
|
|
72
|
+
tags: [_irule_1.RuleTag.Quickfix],
|
|
73
|
+
badExample: `DATA lo_copy TYPE REF TO zcl_node.
|
|
74
|
+
lo_copy = lo_node.
|
|
75
|
+
ro_result = lo_copy.`,
|
|
76
|
+
goodExample: `ro_result = lo_node.`,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
getConfig() {
|
|
80
|
+
return this.conf;
|
|
81
|
+
}
|
|
82
|
+
setConfig(conf) {
|
|
83
|
+
this.conf = conf;
|
|
84
|
+
}
|
|
85
|
+
initialize(reg) {
|
|
86
|
+
this.reg = reg;
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
run(obj) {
|
|
90
|
+
var _a, _b, _c;
|
|
91
|
+
const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
|
|
92
|
+
if (analysis === undefined) {
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
const issues = [];
|
|
96
|
+
for (const procedure of analysis.procedures) {
|
|
97
|
+
if (procedure.supported === false) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
for (const variable of procedure.locals()) {
|
|
101
|
+
const declaration = variable.declaration;
|
|
102
|
+
if (variable.inline || !(0, _procedure_analysis_1.plainData)(declaration) || declaration.getColon() !== undefined
|
|
103
|
+
|| variable.escapes()) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const clears = [];
|
|
107
|
+
const writes = [];
|
|
108
|
+
for (const write of variable.writes()) {
|
|
109
|
+
if (((_a = (0, _procedure_analysis_1.plainClear)(write.statement)) === null || _a === void 0 ? void 0 : _a.getStart().equals(write.token.getStart())) === true
|
|
110
|
+
&& write.statement.getColon() === undefined) {
|
|
111
|
+
clears.push(write);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
writes.push(write);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const reads = variable.reads();
|
|
118
|
+
if (writes.length !== 1 || reads.length !== 1) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const write = writes[0];
|
|
122
|
+
const read = reads[0];
|
|
123
|
+
const assign = (0, _procedure_analysis_1.plainMove)(write.statement);
|
|
124
|
+
const use = (0, _procedure_analysis_1.plainMove)(read.statement);
|
|
125
|
+
if (assign === undefined || use === undefined || assign.operator !== "=" || use.operator !== "="
|
|
126
|
+
|| ((_b = (0, _procedure_analysis_1.singleTarget)(assign.target)) === null || _b === void 0 ? void 0 : _b.getStart().equals(write.token.getStart())) !== true
|
|
127
|
+
|| ((_c = (0, _procedure_analysis_1.singleField)(use.source)) === null || _c === void 0 ? void 0 : _c.getStart().equals(read.token.getStart())) !== true
|
|
128
|
+
|| clears.some(c => c.index > write.index)
|
|
129
|
+
|| !procedure.dominates(write.statement, read.statement)
|
|
130
|
+
|| !procedure.sameLoop(write.statement, read.statement)) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const source = (0, _procedure_analysis_1.dataSource)(procedure, assign.source);
|
|
134
|
+
if (source === undefined || source.kind !== _procedure_analysis_1.SourceKind.Local || source.base === variable
|
|
135
|
+
|| (0, _procedure_analysis_1.singleField)(assign.source) === undefined
|
|
136
|
+
|| !(0, _procedure_analysis_1.unchangedBetween)(procedure, source, write.statement, read.statement)) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
// an inline declaration DATA(y) = v. would get the type of src instead of the type of v
|
|
140
|
+
const type = variable.identifier.getType();
|
|
141
|
+
const inline = use.target.findFirstExpression(Expressions.InlineData) !== undefined;
|
|
142
|
+
if (!(0, _procedure_analysis_1.identicalTypes)(type, source.type) && (inline || !(0, _procedure_analysis_1.isReferenceType)(type) || !(0, _procedure_analysis_1.isReferenceType)(source.type))) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const edits = [
|
|
146
|
+
(0, _procedure_analysis_1.deleteStatement)(procedure.file, declaration),
|
|
147
|
+
(0, _procedure_analysis_1.deleteStatement)(procedure.file, write.statement),
|
|
148
|
+
edit_helper_1.EditHelper.replaceToken(procedure.file, read.token, source.text)
|
|
149
|
+
];
|
|
150
|
+
for (const clear of clears) {
|
|
151
|
+
edits.push((0, _procedure_analysis_1.deleteStatement)(procedure.file, clear.statement));
|
|
152
|
+
}
|
|
153
|
+
const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, edits);
|
|
154
|
+
const message = "Copy chain via " + variable.identifier.getName() + ", assign " + source.text + " directly";
|
|
155
|
+
issues.push(issue_1.Issue.atStatement(procedure.file, read.statement, message, this.getMetadata().key, this.conf.severity, fix));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return issues;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.CopyChain = CopyChain;
|
|
162
|
+
//# sourceMappingURL=copy_chain.js.map
|
|
@@ -0,0 +1,135 @@
|
|
|
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.CopyOfInitialVariable = exports.CopyOfInitialVariableConf = void 0;
|
|
37
|
+
const Expressions = __importStar(require("../abap/2_statements/expressions"));
|
|
38
|
+
const edit_helper_1 = require("../edit_helper");
|
|
39
|
+
const issue_1 = require("../issue");
|
|
40
|
+
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
41
|
+
const _irule_1 = require("./_irule");
|
|
42
|
+
const _procedure_analysis_1 = require("./_procedure_analysis");
|
|
43
|
+
class CopyOfInitialVariableConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
44
|
+
}
|
|
45
|
+
exports.CopyOfInitialVariableConf = CopyOfInitialVariableConf;
|
|
46
|
+
class CopyOfInitialVariable {
|
|
47
|
+
constructor() {
|
|
48
|
+
this.conf = new CopyOfInitialVariableConf();
|
|
49
|
+
}
|
|
50
|
+
getMetadata() {
|
|
51
|
+
return {
|
|
52
|
+
key: "copy_of_initial_variable",
|
|
53
|
+
title: "Copy of initial variable",
|
|
54
|
+
shortDescription: `Finds assignments from a local variable that is always initial`,
|
|
55
|
+
extendedInformation: `Reports DATA v TYPE ... [CLEAR v.] x = v. when all of the following hold:
|
|
56
|
+
|
|
57
|
+
* v is a local variable of a METHOD, FORM or FUNCTION, declared with DATA without VALUE
|
|
58
|
+
* v is never changed, except by CLEAR v., and its address is never taken
|
|
59
|
+
* v has exactly one read, the complete source of x = v., where x is not an inline declaration
|
|
60
|
+
* x and v are both reference types, or have identical types. Initial values convert differently between
|
|
61
|
+
types, e.g. an initial d becomes '00000000' in a string
|
|
62
|
+
* the declaration and the CLEARs are not chained
|
|
63
|
+
|
|
64
|
+
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
65
|
+
INCLUDE, test seams, enhancements or native SQL.
|
|
66
|
+
|
|
67
|
+
The quick fix deletes the declaration and the CLEARs, and replaces x = v. with CLEAR x.
|
|
68
|
+
No release requirement.`,
|
|
69
|
+
tags: [_irule_1.RuleTag.Quickfix],
|
|
70
|
+
badExample: `DATA lo_empty TYPE REF TO zcl_node.
|
|
71
|
+
ro_result = lo_empty.`,
|
|
72
|
+
goodExample: `CLEAR ro_result.`,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
getConfig() {
|
|
76
|
+
return this.conf;
|
|
77
|
+
}
|
|
78
|
+
setConfig(conf) {
|
|
79
|
+
this.conf = conf;
|
|
80
|
+
}
|
|
81
|
+
initialize(reg) {
|
|
82
|
+
this.reg = reg;
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
run(obj) {
|
|
86
|
+
var _a;
|
|
87
|
+
const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
|
|
88
|
+
if (analysis === undefined) {
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
const issues = [];
|
|
92
|
+
for (const procedure of analysis.procedures) {
|
|
93
|
+
if (procedure.supported === false) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
for (const variable of procedure.locals()) {
|
|
97
|
+
const declaration = variable.declaration;
|
|
98
|
+
const reads = variable.reads();
|
|
99
|
+
const writes = variable.writes();
|
|
100
|
+
if (variable.inline || !(0, _procedure_analysis_1.plainData)(declaration) || declaration.getColon() !== undefined
|
|
101
|
+
|| variable.escapes() || reads.length !== 1
|
|
102
|
+
|| writes.some(w => { var _a; return ((_a = (0, _procedure_analysis_1.plainClear)(w.statement)) === null || _a === void 0 ? void 0 : _a.getStart().equals(w.token.getStart())) !== true
|
|
103
|
+
|| w.statement.getColon() !== undefined; })) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const read = reads[0];
|
|
107
|
+
const move = (0, _procedure_analysis_1.plainMove)(read.statement);
|
|
108
|
+
if (move === undefined || move.operator !== "="
|
|
109
|
+
|| ((_a = (0, _procedure_analysis_1.singleField)(move.source)) === null || _a === void 0 ? void 0 : _a.getStart().equals(read.token.getStart())) !== true
|
|
110
|
+
|| move.target.findFirstExpression(Expressions.InlineData) !== undefined) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const type = variable.identifier.getType();
|
|
114
|
+
const target = (0, _procedure_analysis_1.targetType)(procedure, move.target);
|
|
115
|
+
if (target === undefined
|
|
116
|
+
|| (!((0, _procedure_analysis_1.isReferenceType)(type) && (0, _procedure_analysis_1.isReferenceType)(target)) && !(0, _procedure_analysis_1.identicalTypes)(type, target))) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const edits = [
|
|
120
|
+
(0, _procedure_analysis_1.deleteStatement)(procedure.file, declaration),
|
|
121
|
+
edit_helper_1.EditHelper.replaceRange(procedure.file, read.statement.getStart(), read.statement.getEnd(), "CLEAR " + (0, _procedure_analysis_1.nodeText)(procedure.file, move.target) + ".")
|
|
122
|
+
];
|
|
123
|
+
for (const write of writes) {
|
|
124
|
+
edits.push((0, _procedure_analysis_1.deleteStatement)(procedure.file, write.statement));
|
|
125
|
+
}
|
|
126
|
+
const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, edits);
|
|
127
|
+
const message = variable.identifier.getName() + " is always initial, use CLEAR";
|
|
128
|
+
issues.push(issue_1.Issue.atStatement(procedure.file, read.statement, message, this.getMetadata().key, this.conf.severity, fix));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return issues;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.CopyOfInitialVariable = CopyOfInitialVariable;
|
|
135
|
+
//# sourceMappingURL=copy_of_initial_variable.js.map
|
package/build/src/rules/index.js
CHANGED
|
@@ -21,6 +21,7 @@ __exportStar(require("./abapdoc_leading_at"), exports);
|
|
|
21
21
|
__exportStar(require("./abapdoc_parameter_names"), exports);
|
|
22
22
|
__exportStar(require("./add_test_attributes"), exports);
|
|
23
23
|
__exportStar(require("./aff_and_xml"), exports);
|
|
24
|
+
__exportStar(require("./alias_never_reassigned"), exports);
|
|
24
25
|
__exportStar(require("./align_parameters"), exports);
|
|
25
26
|
__exportStar(require("./align_pseudo_comments"), exports);
|
|
26
27
|
__exportStar(require("./align_type_expressions"), exports);
|
|
@@ -30,6 +31,8 @@ __exportStar(require("./ambiguous_statement"), exports);
|
|
|
30
31
|
__exportStar(require("./avoid_use"), exports);
|
|
31
32
|
__exportStar(require("./begin_end_names"), exports);
|
|
32
33
|
__exportStar(require("./begin_single_include"), exports);
|
|
34
|
+
__exportStar(require("./boolean_flag_via_if"), exports);
|
|
35
|
+
__exportStar(require("./bound_check_after_create"), exports);
|
|
33
36
|
__exportStar(require("./call_transaction_authority_check"), exports);
|
|
34
37
|
__exportStar(require("./catch_and_raise"), exports);
|
|
35
38
|
__exportStar(require("./cds_association_name"), exports);
|
|
@@ -50,6 +53,7 @@ __exportStar(require("./check_subrc"), exports);
|
|
|
50
53
|
__exportStar(require("./check_syntax"), exports);
|
|
51
54
|
__exportStar(require("./check_text_elements"), exports);
|
|
52
55
|
__exportStar(require("./check_transformation_exists"), exports);
|
|
56
|
+
__exportStar(require("./clear_after_declaration"), exports);
|
|
53
57
|
__exportStar(require("./clear_exporting_parameters"), exports);
|
|
54
58
|
__exportStar(require("./class_attribute_names"), exports);
|
|
55
59
|
__exportStar(require("./classic_exceptions_overlap"), exports);
|
|
@@ -57,8 +61,11 @@ __exportStar(require("./cloud_types"), exports);
|
|
|
57
61
|
__exportStar(require("./colon_missing_space"), exports);
|
|
58
62
|
__exportStar(require("./commented_code"), exports);
|
|
59
63
|
__exportStar(require("./constant_classes"), exports);
|
|
64
|
+
__exportStar(require("./constant_condition"), exports);
|
|
60
65
|
__exportStar(require("./constructor_visibility_public"), exports);
|
|
61
66
|
__exportStar(require("./contains_tab"), exports);
|
|
67
|
+
__exportStar(require("./copy_chain"), exports);
|
|
68
|
+
__exportStar(require("./copy_of_initial_variable"), exports);
|
|
62
69
|
__exportStar(require("./cyclic_oo"), exports);
|
|
63
70
|
__exportStar(require("./cyclomatic_complexity"), exports);
|
|
64
71
|
__exportStar(require("./dangerous_statement"), exports);
|
|
@@ -184,6 +191,7 @@ __exportStar(require("./selection_screen_texts_missing"), exports);
|
|
|
184
191
|
__exportStar(require("./sequential_blank"), exports);
|
|
185
192
|
__exportStar(require("./short_case"), exports);
|
|
186
193
|
__exportStar(require("./sicf_consistency"), exports);
|
|
194
|
+
__exportStar(require("./single_use_expression_temp"), exports);
|
|
187
195
|
__exportStar(require("./slow_parameter_passing"), exports);
|
|
188
196
|
__exportStar(require("./smim_consistency"), exports);
|
|
189
197
|
__exportStar(require("./sort_empty_key"), exports);
|
|
@@ -201,12 +209,14 @@ __exportStar(require("./sy_modification"), exports);
|
|
|
201
209
|
__exportStar(require("./sy_read_restriction"), exports);
|
|
202
210
|
__exportStar(require("./tabl_enhancement_category"), exports);
|
|
203
211
|
__exportStar(require("./tables_declared_locally"), exports);
|
|
212
|
+
__exportStar(require("./try_cast_empty_catch"), exports);
|
|
204
213
|
__exportStar(require("./try_without_catch"), exports);
|
|
205
214
|
__exportStar(require("./type_form_parameters"), exports);
|
|
206
215
|
__exportStar(require("./types_naming"), exports);
|
|
207
216
|
__exportStar(require("./uncaught_exception"), exports);
|
|
208
217
|
__exportStar(require("./unknown_types"), exports);
|
|
209
218
|
__exportStar(require("./unnecessary_chaining"), exports);
|
|
219
|
+
__exportStar(require("./unnecessary_copy"), exports);
|
|
210
220
|
__exportStar(require("./unnecessary_loop_guard"), exports);
|
|
211
221
|
__exportStar(require("./unnecessary_pragma"), exports);
|
|
212
222
|
__exportStar(require("./unnecessary_return"), exports);
|