@abaplint/core 2.120.57 → 2.120.59

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.
@@ -162,6 +162,11 @@ class Source {
162
162
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
163
163
  return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
164
164
  }
165
+ if ((foundType === null || foundType === void 0 ? void 0 : foundType.isGeneric()) && bodyType !== undefined) {
166
+ this.addIfInferred(node, input, bodyType);
167
+ this.traverseRemainingChildren(children, input);
168
+ return bodyType;
169
+ }
165
170
  this.addIfInferred(node, input, foundType);
166
171
  this.traverseRemainingChildren(children, input);
167
172
  return foundType;
@@ -75,7 +75,7 @@ class Registry {
75
75
  }
76
76
  static abaplintVersion() {
77
77
  // magic, see build script "version.js"
78
- return "2.120.57";
78
+ return "2.120.59";
79
79
  }
80
80
  getDDICReferences() {
81
81
  return this.ddicReferences;
@@ -149,7 +149,9 @@ __exportStar(require("./prefer_insert_into_table"), exports);
149
149
  __exportStar(require("./prefer_is_not"), exports);
150
150
  __exportStar(require("./prefer_pragmas"), exports);
151
151
  __exportStar(require("./prefer_abap_bool"), exports);
152
+ __exportStar(require("./prefer_abap_bool_values"), exports);
152
153
  __exportStar(require("./prefer_raise_exception_new"), exports);
154
+ __exportStar(require("./prefer_string_template"), exports);
153
155
  __exportStar(require("./prefer_returning_to_exporting"), exports);
154
156
  __exportStar(require("./prefer_xsdbool"), exports);
155
157
  __exportStar(require("./preferred_compare_operator"), exports);
@@ -189,6 +191,7 @@ __exportStar(require("./types_naming"), exports);
189
191
  __exportStar(require("./uncaught_exception"), exports);
190
192
  __exportStar(require("./unknown_types"), exports);
191
193
  __exportStar(require("./unnecessary_chaining"), exports);
194
+ __exportStar(require("./unnecessary_loop_guard"), exports);
192
195
  __exportStar(require("./unnecessary_pragma"), exports);
193
196
  __exportStar(require("./unnecessary_return"), exports);
194
197
  __exportStar(require("./unreachable_code"), exports);
@@ -201,6 +204,7 @@ __exportStar(require("./unused_variables"), exports);
201
204
  __exportStar(require("./use_bool_expression"), exports);
202
205
  __exportStar(require("./use_class_based_exceptions"), exports);
203
206
  __exportStar(require("./use_line_exists"), exports);
207
+ __exportStar(require("./use_message_class"), exports);
204
208
  __exportStar(require("./use_new"), exports);
205
209
  __exportStar(require("./when_others_last"), exports);
206
210
  __exportStar(require("./whitespace_end"), exports);
@@ -0,0 +1,256 @@
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.PreferAbapBoolValues = exports.PreferAbapBoolValuesConf = void 0;
37
+ const issue_1 = require("../issue");
38
+ const _abap_rule_1 = require("./_abap_rule");
39
+ const Expressions = __importStar(require("../abap/2_statements/expressions"));
40
+ const Statements = __importStar(require("../abap/2_statements/statements"));
41
+ const _basic_rule_config_1 = require("./_basic_rule_config");
42
+ const _irule_1 = require("./_irule");
43
+ const edit_helper_1 = require("../edit_helper");
44
+ const nodes_1 = require("../abap/nodes");
45
+ const ABAP_BOOL = "ABAP_BOOL";
46
+ const ABAP_TRUE = "abap_true";
47
+ const ABAP_FALSE = "abap_false";
48
+ const VALID_VALUES = new Set(["ABAP_TRUE", "ABAP_FALSE", "ABAP_UNDEFINED"]);
49
+ class PreferAbapBoolValuesConf extends _basic_rule_config_1.BasicRuleConfig {
50
+ }
51
+ exports.PreferAbapBoolValuesConf = PreferAbapBoolValuesConf;
52
+ class PreferAbapBoolValues extends _abap_rule_1.ABAPRule {
53
+ constructor() {
54
+ super(...arguments);
55
+ this.conf = new PreferAbapBoolValuesConf();
56
+ }
57
+ getMetadata() {
58
+ return {
59
+ key: "prefer_abap_bool_values",
60
+ title: "Prefer abap_true and abap_false",
61
+ shortDescription: `Use abap_true and abap_false instead of 'X' and ' ' for abap_bool variables`,
62
+ // eslint-disable-next-line max-len
63
+ extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#use-abap_true-abap_false-and-abap_undefined-for-abap_bool-variables`,
64
+ tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
65
+ badExample: `DATA lv_flag TYPE abap_bool.\nlv_flag = 'X'.`,
66
+ goodExample: `DATA lv_flag TYPE abap_bool.\nlv_flag = abap_true.`,
67
+ };
68
+ }
69
+ getConfig() {
70
+ return this.conf;
71
+ }
72
+ setConfig(conf) {
73
+ this.conf = conf;
74
+ }
75
+ runParsed(file) {
76
+ const issues = [];
77
+ const structure = file.getStructure();
78
+ if (structure === undefined) {
79
+ return [];
80
+ }
81
+ const boolVars = this.collectBoolVars(file);
82
+ // Check Move statements: target = source
83
+ for (const stat of structure.findAllStatements(Statements.Move)) {
84
+ const target = stat.findFirstExpression(Expressions.Target);
85
+ const source = stat.findFirstExpression(Expressions.Source);
86
+ if (target === undefined || source === undefined) {
87
+ continue;
88
+ }
89
+ const targetName = target.concatTokens().toUpperCase();
90
+ if (!boolVars.has(targetName)) {
91
+ continue;
92
+ }
93
+ this.checkSourceNode(source, file, issues);
94
+ }
95
+ // Check comparisons: IF/ELSEIF conditions
96
+ const compareStatements = [
97
+ ...structure.findAllStatements(Statements.If),
98
+ ...structure.findAllStatements(Statements.ElseIf),
99
+ ];
100
+ for (const stat of compareStatements) {
101
+ const cond = stat.findFirstExpression(Expressions.Cond);
102
+ if (cond === undefined) {
103
+ continue;
104
+ }
105
+ for (const compare of cond.findAllExpressions(Expressions.Compare)) {
106
+ this.checkCompareBoolLiteral(compare, boolVars, file, issues);
107
+ }
108
+ }
109
+ return issues;
110
+ }
111
+ collectBoolVars(file) {
112
+ var _a;
113
+ const boolVars = new Set();
114
+ const structure = file.getStructure();
115
+ if (structure === undefined) {
116
+ return boolVars;
117
+ }
118
+ const statements = [
119
+ ...structure.findAllStatements(Statements.Data),
120
+ ...structure.findAllStatements(Statements.ClassData),
121
+ ...structure.findAllStatements(Statements.FieldSymbol),
122
+ ];
123
+ for (const stat of statements) {
124
+ const typeNameExpr = stat.findFirstExpression(Expressions.TypeName);
125
+ if (typeNameExpr === undefined) {
126
+ continue;
127
+ }
128
+ if (typeNameExpr.concatTokens().toUpperCase() !== ABAP_BOOL) {
129
+ continue;
130
+ }
131
+ const nameExpr = (_a = stat.findFirstExpression(Expressions.DefinitionName)) !== null && _a !== void 0 ? _a : stat.findFirstExpression(Expressions.FieldSymbol);
132
+ if (nameExpr === undefined) {
133
+ continue;
134
+ }
135
+ boolVars.add(nameExpr.concatTokens().toUpperCase());
136
+ }
137
+ return boolVars;
138
+ }
139
+ checkSourceNode(source, file, issues) {
140
+ const firstToken = source.getFirstToken().getStr().toUpperCase();
141
+ if (firstToken === "COND") {
142
+ const condBody = source.findDirectExpression(Expressions.CondBody);
143
+ if (condBody) {
144
+ this.checkCondBodyBranches(condBody, file, issues);
145
+ }
146
+ return;
147
+ }
148
+ if (firstToken === "SWITCH") {
149
+ const switchBody = source.findDirectExpression(Expressions.SwitchBody);
150
+ if (switchBody) {
151
+ this.checkSwitchBodyBranches(switchBody, file, issues);
152
+ }
153
+ return;
154
+ }
155
+ // Plain literal assignment
156
+ const issue = this.checkLiteralSource(source, file);
157
+ if (issue) {
158
+ issues.push(issue);
159
+ }
160
+ }
161
+ checkLiteralSource(source, file) {
162
+ const constantStr = source.findFirstExpression(Expressions.ConstantString);
163
+ if (constantStr === undefined) {
164
+ return undefined;
165
+ }
166
+ const token = constantStr.getFirstToken();
167
+ const val = token.getStr();
168
+ if (val === "'X'") {
169
+ const fix = edit_helper_1.EditHelper.replaceToken(file, token, ABAP_TRUE);
170
+ return issue_1.Issue.atToken(file, token, `Use ${ABAP_TRUE} instead of 'X'`, this.getMetadata().key, this.conf.severity, fix);
171
+ }
172
+ if (val === "' '") {
173
+ const fix = edit_helper_1.EditHelper.replaceToken(file, token, ABAP_FALSE);
174
+ return issue_1.Issue.atToken(file, token, `Use ${ABAP_FALSE} instead of ' '`, this.getMetadata().key, this.conf.severity, fix);
175
+ }
176
+ return undefined;
177
+ }
178
+ checkCondBodyBranches(condBody, file, issues) {
179
+ // CondBody: WHEN <cond> THEN <source> [WHEN <cond> THEN <source>]* [ELSE <source>]
180
+ // Walk children; Source nodes after THEN/ELSE are the result values
181
+ let afterThenOrElse = false;
182
+ for (const child of condBody.getChildren()) {
183
+ const tokenStr = child.getFirstToken().getStr().toUpperCase();
184
+ if (tokenStr === "THEN" || tokenStr === "ELSE") {
185
+ afterThenOrElse = true;
186
+ continue;
187
+ }
188
+ if (tokenStr === "WHEN") {
189
+ afterThenOrElse = false;
190
+ continue;
191
+ }
192
+ if (afterThenOrElse && child instanceof nodes_1.ExpressionNode && child.get() instanceof Expressions.Source) {
193
+ const issue = this.checkLiteralSource(child, file);
194
+ if (issue) {
195
+ issues.push(issue);
196
+ }
197
+ afterThenOrElse = false;
198
+ }
199
+ }
200
+ }
201
+ checkSwitchBodyBranches(switchBody, file, issues) {
202
+ // SwitchBody: <source> WHEN <val> [OR <val>]* THEN <source> [ELSE <source>]
203
+ // First Source is the operand; Source after THEN/ELSE are result values
204
+ let firstSourceSeen = false;
205
+ let afterThenOrElse = false;
206
+ for (const child of switchBody.getChildren()) {
207
+ const tokenStr = child.getFirstToken().getStr().toUpperCase();
208
+ if (tokenStr === "THEN" || tokenStr === "ELSE") {
209
+ afterThenOrElse = true;
210
+ continue;
211
+ }
212
+ if (tokenStr === "WHEN" || tokenStr === "OR") {
213
+ afterThenOrElse = false;
214
+ continue;
215
+ }
216
+ if (child instanceof nodes_1.ExpressionNode && child.get() instanceof Expressions.Source) {
217
+ if (!firstSourceSeen) {
218
+ firstSourceSeen = true;
219
+ continue;
220
+ }
221
+ if (afterThenOrElse) {
222
+ const issue = this.checkLiteralSource(child, file);
223
+ if (issue) {
224
+ issues.push(issue);
225
+ }
226
+ afterThenOrElse = false;
227
+ }
228
+ }
229
+ }
230
+ }
231
+ checkCompareBoolLiteral(compare, boolVars, file, issues) {
232
+ // Compare: Source CompareOperator Source (or other forms)
233
+ const sources = compare.findDirectExpressions(Expressions.Source);
234
+ if (sources.length < 2) {
235
+ return;
236
+ }
237
+ const [left, right] = sources;
238
+ const leftStr = left.concatTokens().toUpperCase();
239
+ const rightStr = right.concatTokens().toUpperCase();
240
+ let literalSource;
241
+ if (boolVars.has(leftStr) && !VALID_VALUES.has(rightStr)) {
242
+ literalSource = right;
243
+ }
244
+ else if (boolVars.has(rightStr) && !VALID_VALUES.has(leftStr)) {
245
+ literalSource = left;
246
+ }
247
+ if (literalSource) {
248
+ const issue = this.checkLiteralSource(literalSource, file);
249
+ if (issue) {
250
+ issues.push(issue);
251
+ }
252
+ }
253
+ }
254
+ }
255
+ exports.PreferAbapBoolValues = PreferAbapBoolValues;
256
+ //# sourceMappingURL=prefer_abap_bool_values.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.PreferStringTemplate = exports.PreferStringTemplateConf = void 0;
37
+ const issue_1 = require("../issue");
38
+ const _abap_rule_1 = require("./_abap_rule");
39
+ const Expressions = __importStar(require("../abap/2_statements/expressions"));
40
+ const _basic_rule_config_1 = require("./_basic_rule_config");
41
+ const _irule_1 = require("./_irule");
42
+ const nodes_1 = require("../abap/nodes");
43
+ const edit_helper_1 = require("../edit_helper");
44
+ class PreferStringTemplateConf extends _basic_rule_config_1.BasicRuleConfig {
45
+ }
46
+ exports.PreferStringTemplateConf = PreferStringTemplateConf;
47
+ class PreferStringTemplate extends _abap_rule_1.ABAPRule {
48
+ constructor() {
49
+ super(...arguments);
50
+ this.conf = new PreferStringTemplateConf();
51
+ }
52
+ getMetadata() {
53
+ return {
54
+ key: "prefer_string_template",
55
+ title: "Prefer string template over &&",
56
+ shortDescription: `Use string templates instead of && to assemble text`,
57
+ extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#use--to-assemble-text`,
58
+ tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
59
+ badExample: `DATA(msg) = \`Hello \` && name && \`!\`.`,
60
+ goodExample: `DATA(msg) = |Hello { name }!|.`,
61
+ };
62
+ }
63
+ getConfig() {
64
+ return this.conf;
65
+ }
66
+ setConfig(conf) {
67
+ this.conf = conf;
68
+ }
69
+ runParsed(file) {
70
+ const issues = [];
71
+ const structure = file.getStructure();
72
+ if (structure === undefined) {
73
+ return [];
74
+ }
75
+ const allSources = structure.findAllExpressions(Expressions.Source);
76
+ // collect all Source nodes that appear as the RHS (children[2]) of a && expression
77
+ const rhsChildren = new Set();
78
+ for (const source of allSources) {
79
+ const children = source.getChildren();
80
+ if (children.length === 3 && children[1].getFirstToken().getStr() === "&&") {
81
+ rhsChildren.add(children[2]);
82
+ }
83
+ }
84
+ for (const source of allSources) {
85
+ const children = source.getChildren();
86
+ if (children.length !== 3) {
87
+ continue;
88
+ }
89
+ if (children[1].getFirstToken().getStr() !== "&&") {
90
+ continue;
91
+ }
92
+ // only process top-level && roots (not nested RHS children)
93
+ if (rhsChildren.has(source)) {
94
+ continue;
95
+ }
96
+ const operands = this.flattenChain(source);
97
+ if (!operands.some(op => { const c = op.getFirstToken().getStr()[0]; return c === "'" || c === "`"; })) {
98
+ continue;
99
+ }
100
+ const template = this.buildTemplate(operands);
101
+ const start = source.getFirstToken().getStart();
102
+ const end = source.getLastToken().getEnd();
103
+ const fix = edit_helper_1.EditHelper.replaceRange(file, start, end, template);
104
+ const token = children[1].getFirstToken();
105
+ issues.push(issue_1.Issue.atToken(file, token, "Use string template instead of &&", this.getMetadata().key, this.conf.severity, fix));
106
+ }
107
+ return issues;
108
+ }
109
+ flattenChain(node) {
110
+ const children = node.getChildren();
111
+ if (children.length === 3 && children[1].getFirstToken().getStr() === "&&") {
112
+ return [...this.flattenChain(children[0]), ...this.flattenChain(children[2])];
113
+ }
114
+ if (children.length === 1 && children[0] instanceof nodes_1.ExpressionNode) {
115
+ return this.flattenChain(children[0]);
116
+ }
117
+ return [node];
118
+ }
119
+ buildTemplate(operands) {
120
+ let inner = "";
121
+ for (const op of operands) {
122
+ const raw = op.getFirstToken().getStr();
123
+ const firstChar = raw[0];
124
+ if (firstChar === "'" || firstChar === "`") {
125
+ inner += raw.slice(1, -1);
126
+ }
127
+ else {
128
+ inner += `{ ${op.concatTokens()} }`;
129
+ }
130
+ }
131
+ return `|${inner}|`;
132
+ }
133
+ }
134
+ exports.PreferStringTemplate = PreferStringTemplate;
135
+ //# sourceMappingURL=prefer_string_template.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.UnnecessaryLoopGuard = exports.UnnecessaryLoopGuardConf = void 0;
37
+ const issue_1 = require("../issue");
38
+ const Expressions = __importStar(require("../abap/2_statements/expressions"));
39
+ const Statements = __importStar(require("../abap/2_statements/statements"));
40
+ const Structures = __importStar(require("../abap/3_structures/structures"));
41
+ const _abap_rule_1 = require("./_abap_rule");
42
+ const _basic_rule_config_1 = require("./_basic_rule_config");
43
+ const _irule_1 = require("./_irule");
44
+ const edit_helper_1 = require("../edit_helper");
45
+ class UnnecessaryLoopGuardConf extends _basic_rule_config_1.BasicRuleConfig {
46
+ }
47
+ exports.UnnecessaryLoopGuardConf = UnnecessaryLoopGuardConf;
48
+ class UnnecessaryLoopGuard extends _abap_rule_1.ABAPRule {
49
+ constructor() {
50
+ super(...arguments);
51
+ this.conf = new UnnecessaryLoopGuardConf();
52
+ }
53
+ getMetadata() {
54
+ return {
55
+ key: "unnecessary_loop_guard",
56
+ title: "Unnecessary loop guard",
57
+ shortDescription: `Detects unnecessary IS [NOT] INITIAL check before LOOP AT`,
58
+ extendedInformation: `LOOP AT iterates zero times on an empty table, so an IS [NOT] INITIAL guard is redundant.`,
59
+ tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Styleguide, _irule_1.RuleTag.Quickfix],
60
+ badExample: `IF lt_data IS NOT INITIAL.
61
+ LOOP AT lt_data INTO DATA(ls_item).
62
+ WRITE ls_item-name.
63
+ ENDLOOP.
64
+ ENDIF.`,
65
+ goodExample: `LOOP AT lt_data INTO DATA(ls_item).
66
+ WRITE ls_item-name.
67
+ ENDLOOP.`,
68
+ };
69
+ }
70
+ getConfig() {
71
+ return this.conf;
72
+ }
73
+ setConfig(conf) {
74
+ this.conf = conf;
75
+ }
76
+ runParsed(file) {
77
+ const issues = [];
78
+ const stru = file.getStructure();
79
+ if (stru === undefined) {
80
+ return issues;
81
+ }
82
+ for (const ifStru of stru.findAllStructuresRecursive(Structures.If)) {
83
+ if (ifStru.findDirectStructures(Structures.ElseIf).length > 0
84
+ || ifStru.findDirectStructures(Structures.Else).length > 0) {
85
+ continue;
86
+ }
87
+ const ifStatement = ifStru.findDirectStatement(Statements.If);
88
+ if (ifStatement === undefined) {
89
+ continue;
90
+ }
91
+ const cond = ifStatement.findDirectExpression(Expressions.Cond);
92
+ if (cond === undefined) {
93
+ continue;
94
+ }
95
+ const compareNodes = cond.findDirectExpressions(Expressions.Compare);
96
+ if (compareNodes.length !== 1) {
97
+ continue;
98
+ }
99
+ const m = compareNodes[0].concatTokens().toUpperCase().match(/^(.+?)\s+IS\s+(?:NOT\s+)?INITIAL\s*$/);
100
+ if (!m) {
101
+ continue;
102
+ }
103
+ const tableName = m[1];
104
+ const bodyStructures = ifStru.findDirectStructures(Structures.Body);
105
+ if (bodyStructures.length !== 1) {
106
+ continue;
107
+ }
108
+ const normalStructures = bodyStructures[0].findDirectStructures(Structures.Normal);
109
+ if (normalStructures.length !== 1) {
110
+ continue;
111
+ }
112
+ const loopStructures = normalStructures[0].findDirectStructures(Structures.Loop);
113
+ if (loopStructures.length !== 1) {
114
+ continue;
115
+ }
116
+ const loopStatement = loopStructures[0].findDirectStatement(Statements.Loop);
117
+ if (loopStatement === undefined) {
118
+ continue;
119
+ }
120
+ const loopSource = loopStatement.findFirstExpression(Expressions.LoopSource);
121
+ if (loopSource === undefined) {
122
+ continue;
123
+ }
124
+ if (loopSource.concatTokens().toUpperCase() !== tableName) {
125
+ continue;
126
+ }
127
+ const endifStatement = ifStru.findDirectStatement(Statements.EndIf);
128
+ const fix = edit_helper_1.EditHelper.merge(edit_helper_1.EditHelper.deleteStatement(file, ifStatement), edit_helper_1.EditHelper.deleteStatement(file, endifStatement));
129
+ issues.push(issue_1.Issue.atStatement(file, ifStatement, "Unnecessary IS [NOT] INITIAL check before LOOP AT", this.getMetadata().key, this.conf.severity, fix));
130
+ }
131
+ return issues;
132
+ }
133
+ }
134
+ exports.UnnecessaryLoopGuard = UnnecessaryLoopGuard;
135
+ //# sourceMappingURL=unnecessary_loop_guard.js.map
@@ -0,0 +1,87 @@
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.UseMessageClass = exports.UseMessageClassConf = void 0;
37
+ const issue_1 = require("../issue");
38
+ const _abap_rule_1 = require("./_abap_rule");
39
+ const Expressions = __importStar(require("../abap/2_statements/expressions"));
40
+ const Statements = __importStar(require("../abap/2_statements/statements"));
41
+ const _basic_rule_config_1 = require("./_basic_rule_config");
42
+ const _irule_1 = require("./_irule");
43
+ class UseMessageClassConf extends _basic_rule_config_1.BasicRuleConfig {
44
+ }
45
+ exports.UseMessageClassConf = UseMessageClassConf;
46
+ class UseMessageClass extends _abap_rule_1.ABAPRule {
47
+ constructor() {
48
+ super(...arguments);
49
+ this.conf = new UseMessageClassConf();
50
+ }
51
+ getMetadata() {
52
+ return {
53
+ key: "use_message_class",
54
+ title: "Use message class",
55
+ shortDescription: `Define messages in SE91 instead of using inline text or variables`,
56
+ tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile],
57
+ badExample: `MESSAGE 'Something went wrong' TYPE 'E'.`,
58
+ goodExample: `MESSAGE e001(bc_msg).`,
59
+ };
60
+ }
61
+ getConfig() {
62
+ return this.conf;
63
+ }
64
+ setConfig(conf) {
65
+ this.conf = conf;
66
+ }
67
+ runParsed(file, _obj) {
68
+ const structure = file.getStructure();
69
+ if (structure === undefined) {
70
+ return [];
71
+ }
72
+ const issues = [];
73
+ const key = this.getMetadata().key;
74
+ for (const statement of structure.findAllStatements(Statements.Message)) {
75
+ // The parser populates MessageSource only for the class-based forms (e001(bc_msg) or ID/TYPE/NUMBER).
76
+ // The text form (MESSAGE <source> TYPE <source>) uses MessageSourceSource directly with no MessageSource child.
77
+ // Absence of MessageSource is therefore a reliable discriminator between the two forms.
78
+ if (statement.findDirectExpression(Expressions.MessageSource) !== undefined) {
79
+ continue;
80
+ }
81
+ issues.push(issue_1.Issue.atStatement(file, statement, "Use a message class (SE91) instead of inline text or variable", key, this.conf.severity));
82
+ }
83
+ return issues;
84
+ }
85
+ }
86
+ exports.UseMessageClass = UseMessageClass;
87
+ //# sourceMappingURL=use_message_class.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.120.57",
3
+ "version": "2.120.59",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",