@abaplint/cli 2.120.108 → 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/cli.js +1258 -5
- package/package.json +2 -2
package/build/cli.js
CHANGED
|
@@ -73998,7 +73998,7 @@ class Registry {
|
|
|
73998
73998
|
}
|
|
73999
73999
|
static abaplintVersion() {
|
|
74000
74000
|
// magic, see build script "version.js"
|
|
74001
|
-
return "2.120.
|
|
74001
|
+
return "2.120.109";
|
|
74002
74002
|
}
|
|
74003
74003
|
getDDICReferences() {
|
|
74004
74004
|
return this.ddicReferences;
|
|
@@ -81401,6 +81401,280 @@ exports.ChangingSortedLine = ChangingSortedLine;
|
|
|
81401
81401
|
|
|
81402
81402
|
/***/ },
|
|
81403
81403
|
|
|
81404
|
+
/***/ "../core/build/src/rules/character_field_literal_blanks.js"
|
|
81405
|
+
/*!*****************************************************************!*\
|
|
81406
|
+
!*** ../core/build/src/rules/character_field_literal_blanks.js ***!
|
|
81407
|
+
\*****************************************************************/
|
|
81408
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
81409
|
+
|
|
81410
|
+
"use strict";
|
|
81411
|
+
|
|
81412
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
81413
|
+
if (k2 === undefined) k2 = k;
|
|
81414
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
81415
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
81416
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
81417
|
+
}
|
|
81418
|
+
Object.defineProperty(o, k2, desc);
|
|
81419
|
+
}) : (function(o, m, k, k2) {
|
|
81420
|
+
if (k2 === undefined) k2 = k;
|
|
81421
|
+
o[k2] = m[k];
|
|
81422
|
+
}));
|
|
81423
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
81424
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
81425
|
+
}) : function(o, v) {
|
|
81426
|
+
o["default"] = v;
|
|
81427
|
+
});
|
|
81428
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
81429
|
+
var ownKeys = function(o) {
|
|
81430
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
81431
|
+
var ar = [];
|
|
81432
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
81433
|
+
return ar;
|
|
81434
|
+
};
|
|
81435
|
+
return ownKeys(o);
|
|
81436
|
+
};
|
|
81437
|
+
return function (mod) {
|
|
81438
|
+
if (mod && mod.__esModule) return mod;
|
|
81439
|
+
var result = {};
|
|
81440
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
81441
|
+
__setModuleDefault(result, mod);
|
|
81442
|
+
return result;
|
|
81443
|
+
};
|
|
81444
|
+
})();
|
|
81445
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
81446
|
+
exports.CharacterFieldLiteralBlanks = exports.CharacterFieldLiteralBlanksConf = void 0;
|
|
81447
|
+
const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
|
|
81448
|
+
const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
|
|
81449
|
+
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
81450
|
+
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
81451
|
+
const _abap_rule_1 = __webpack_require__(/*! ./_abap_rule */ "../core/build/src/rules/_abap_rule.js");
|
|
81452
|
+
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
81453
|
+
const nodes_1 = __webpack_require__(/*! ../abap/nodes */ "../core/build/src/abap/nodes/index.js");
|
|
81454
|
+
const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
|
|
81455
|
+
const severity_1 = __webpack_require__(/*! ../severity */ "../core/build/src/severity.js");
|
|
81456
|
+
class CharacterFieldLiteralBlanksConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
81457
|
+
constructor() {
|
|
81458
|
+
super(...arguments);
|
|
81459
|
+
this.severity = severity_1.Severity.Warning;
|
|
81460
|
+
/** Report a FIND or REPLACE search pattern that is a character field literal containing only blanks, or space,
|
|
81461
|
+
* the pattern is empty: ALL OCCURRENCES raises an exception, FIRST OCCURRENCE matches before the first character */
|
|
81462
|
+
this.searchPattern = true;
|
|
81463
|
+
/** Report a character field literal ending with a blank as an operand of &&, of CONCATENATE without
|
|
81464
|
+
* RESPECTING BLANKS, or as an embedded expression in a string template, the trailing blanks are dropped */
|
|
81465
|
+
this.concatenation = true;
|
|
81466
|
+
}
|
|
81467
|
+
}
|
|
81468
|
+
exports.CharacterFieldLiteralBlanksConf = CharacterFieldLiteralBlanksConf;
|
|
81469
|
+
class CharacterFieldLiteralBlanks extends _abap_rule_1.ABAPRule {
|
|
81470
|
+
constructor() {
|
|
81471
|
+
super(...arguments);
|
|
81472
|
+
this.conf = new CharacterFieldLiteralBlanksConf();
|
|
81473
|
+
}
|
|
81474
|
+
getMetadata() {
|
|
81475
|
+
return {
|
|
81476
|
+
key: "character_field_literal_blanks",
|
|
81477
|
+
title: "Ignored blanks in character field literals",
|
|
81478
|
+
shortDescription: `Reports character field literals ('...') whose blanks are ignored where the code relies on them`,
|
|
81479
|
+
extendedInformation: `A character field literal '...' (called text field literal in the ABAP
|
|
81480
|
+
documentation) has type c, and trailing blanks of type c operands are ignored in many positions.
|
|
81481
|
+
A text string literal \`...\` has type string and keeps them.
|
|
81482
|
+
|
|
81483
|
+
Option searchPattern: a FIND or REPLACE search pattern (SUBSTRING, character mode) that is a character field
|
|
81484
|
+
literal containing only blanks, '' or space. The pattern is empty: FIND/REPLACE ALL OCCURRENCES raises
|
|
81485
|
+
CX_SY_FIND_INFINITE_LOOP/CX_SY_REPLACE_INFINITE_LOOP, the first occurrence is found before the first character.
|
|
81486
|
+
https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abapfind_pattern.htm
|
|
81487
|
+
|
|
81488
|
+
Option concatenation: a character field literal ending with a blank as an operand of &&, as an operand of
|
|
81489
|
+
CONCATENATE without RESPECTING BLANKS, or as the whole embedded expression of a string template without
|
|
81490
|
+
formatting options. The trailing blanks are dropped, 'Hello ' && name gives "HelloJohn". space is reported
|
|
81491
|
+
the same way.
|
|
81492
|
+
https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abenstring_operators.htm
|
|
81493
|
+
|
|
81494
|
+
The quick fix replaces the literal with a text string literal with the same content.
|
|
81495
|
+
|
|
81496
|
+
Not reported: text string literals, CONCATENATE ... RESPECTING BLANKS, the separator of SEPARATED BY
|
|
81497
|
+
(its trailing blanks are kept), the literal operator &, literals with a text symbol, PCRE and REGEX
|
|
81498
|
+
patterns, byte mode, comparisons and parameters.`,
|
|
81499
|
+
tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
|
|
81500
|
+
badExample: `REPLACE ALL OCCURRENCES OF ' ' IN lv_text WITH ''.
|
|
81501
|
+
lv_text = 'Hello ' && lv_name.`,
|
|
81502
|
+
goodExample: `REPLACE ALL OCCURRENCES OF \` \` IN lv_text WITH ''.
|
|
81503
|
+
lv_text = \`Hello \` && lv_name.`,
|
|
81504
|
+
};
|
|
81505
|
+
}
|
|
81506
|
+
getConfig() {
|
|
81507
|
+
return this.conf;
|
|
81508
|
+
}
|
|
81509
|
+
setConfig(conf) {
|
|
81510
|
+
this.conf = conf;
|
|
81511
|
+
}
|
|
81512
|
+
runParsed(file) {
|
|
81513
|
+
const issues = [];
|
|
81514
|
+
for (const statement of file.getStatements()) {
|
|
81515
|
+
if (this.conf.searchPattern === true) {
|
|
81516
|
+
const issue = this.checkSearchPattern(file, statement);
|
|
81517
|
+
if (issue !== undefined) {
|
|
81518
|
+
issues.push(issue);
|
|
81519
|
+
}
|
|
81520
|
+
}
|
|
81521
|
+
if (this.conf.concatenation === true) {
|
|
81522
|
+
issues.push(...this.checkConcatenation(file, statement));
|
|
81523
|
+
}
|
|
81524
|
+
}
|
|
81525
|
+
return issues;
|
|
81526
|
+
}
|
|
81527
|
+
////////////////
|
|
81528
|
+
checkSearchPattern(file, statement) {
|
|
81529
|
+
const s = statement.get();
|
|
81530
|
+
const isFind = s instanceof Statements.Find;
|
|
81531
|
+
if ((isFind === false && !(s instanceof Statements.Replace))
|
|
81532
|
+
|| statement.findDirectTokenByText("IN") === undefined
|
|
81533
|
+
|| statement.findDirectTokenByText("BYTE") !== undefined) {
|
|
81534
|
+
return undefined;
|
|
81535
|
+
}
|
|
81536
|
+
const pattern = this.findPattern(statement);
|
|
81537
|
+
if (pattern === undefined || pattern.getChildren().length !== 1) {
|
|
81538
|
+
return undefined;
|
|
81539
|
+
}
|
|
81540
|
+
const token = this.blankOperand(pattern);
|
|
81541
|
+
if (token === undefined || this.content(token).trim() !== "") {
|
|
81542
|
+
return undefined;
|
|
81543
|
+
}
|
|
81544
|
+
const name = isFind ? "FIND" : "REPLACE";
|
|
81545
|
+
const table = statement.findDirectTokenByText("TABLE") !== undefined;
|
|
81546
|
+
let effect = "it is found before the first character";
|
|
81547
|
+
if (statement.findDirectTokenByText("ALL") !== undefined) {
|
|
81548
|
+
effect = isFind && table
|
|
81549
|
+
? "FIND ALL OCCURRENCES IN TABLE with an empty pattern is not possible"
|
|
81550
|
+
: `${name} ALL OCCURRENCES raises CX_SY_${name}_INFINITE_LOOP`;
|
|
81551
|
+
}
|
|
81552
|
+
const message = `Search pattern ${token.getStr()} is empty, blanks of character field literals are ignored, ${effect}`;
|
|
81553
|
+
return issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity, this.buildFix(file, token));
|
|
81554
|
+
}
|
|
81555
|
+
/** the substring pattern of FIND or REPLACE, undefined for PCRE and REGEX and for REPLACE SECTION */
|
|
81556
|
+
findPattern(statement) {
|
|
81557
|
+
const children = statement.getChildren();
|
|
81558
|
+
for (let i = 1; i < children.length; i++) {
|
|
81559
|
+
const child = children[i];
|
|
81560
|
+
if (child instanceof nodes_1.TokenNode && child.concatTokens().toUpperCase() === "IN") {
|
|
81561
|
+
return undefined;
|
|
81562
|
+
}
|
|
81563
|
+
else if (!(child instanceof nodes_1.ExpressionNode) || !(child.get() instanceof Expressions.Source)) {
|
|
81564
|
+
continue;
|
|
81565
|
+
}
|
|
81566
|
+
const before = children[i - 1];
|
|
81567
|
+
if (before instanceof nodes_1.ExpressionNode && before.get() instanceof Expressions.FindType) {
|
|
81568
|
+
return before.concatTokens().toUpperCase() === "SUBSTRING" ? child : undefined;
|
|
81569
|
+
}
|
|
81570
|
+
else if (before instanceof nodes_1.TokenNode && CharacterFieldLiteralBlanks.beforePattern.has(before.concatTokens().toUpperCase())) {
|
|
81571
|
+
return child;
|
|
81572
|
+
}
|
|
81573
|
+
}
|
|
81574
|
+
return undefined;
|
|
81575
|
+
}
|
|
81576
|
+
checkConcatenation(file, statement) {
|
|
81577
|
+
const operands = [];
|
|
81578
|
+
const sources = statement.findAllExpressionsRecursive(Expressions.Source);
|
|
81579
|
+
// left operands of &&
|
|
81580
|
+
for (const source of sources) {
|
|
81581
|
+
if (source.findDirectTokenByText("&&") !== undefined) {
|
|
81582
|
+
operands.push(source);
|
|
81583
|
+
}
|
|
81584
|
+
}
|
|
81585
|
+
// right operands of && and &&=
|
|
81586
|
+
for (const node of [statement, ...sources]) {
|
|
81587
|
+
const children = node.getChildren();
|
|
81588
|
+
for (let i = 1; i < children.length; i++) {
|
|
81589
|
+
const before = children[i - 1].concatTokens();
|
|
81590
|
+
const child = children[i];
|
|
81591
|
+
if ((before === "&&" || before === "&&=")
|
|
81592
|
+
&& child instanceof nodes_1.ExpressionNode
|
|
81593
|
+
&& child.get() instanceof Expressions.Source) {
|
|
81594
|
+
operands.push(child);
|
|
81595
|
+
}
|
|
81596
|
+
}
|
|
81597
|
+
}
|
|
81598
|
+
// embedded expressions without formatting options
|
|
81599
|
+
for (const embedded of statement.findAllExpressionsRecursive(Expressions.StringTemplateSource)) {
|
|
81600
|
+
const source = embedded.findDirectExpression(Expressions.Source);
|
|
81601
|
+
if (source !== undefined
|
|
81602
|
+
&& source.getChildren().length === 1
|
|
81603
|
+
&& embedded.findDirectExpression(Expressions.StringTemplateFormatting) === undefined) {
|
|
81604
|
+
operands.push(source);
|
|
81605
|
+
}
|
|
81606
|
+
}
|
|
81607
|
+
// CONCATENATE without RESPECTING BLANKS, the separator keeps its blanks
|
|
81608
|
+
if (statement.get() instanceof Statements.Concatenate
|
|
81609
|
+
&& statement.findDirectTokenByText("RESPECTING") === undefined
|
|
81610
|
+
&& statement.findDirectTokenByText("BYTE") === undefined) {
|
|
81611
|
+
for (const child of statement.getChildren()) {
|
|
81612
|
+
if (child instanceof nodes_1.TokenNode && child.concatTokens().toUpperCase() === "INTO") {
|
|
81613
|
+
break;
|
|
81614
|
+
}
|
|
81615
|
+
else if (child instanceof nodes_1.ExpressionNode && child.get() instanceof Expressions.SimpleSource3) {
|
|
81616
|
+
operands.push(child);
|
|
81617
|
+
}
|
|
81618
|
+
}
|
|
81619
|
+
}
|
|
81620
|
+
const issues = [];
|
|
81621
|
+
const reported = new Set();
|
|
81622
|
+
for (const operand of operands) {
|
|
81623
|
+
const token = this.blankOperand(operand);
|
|
81624
|
+
if (token === undefined || reported.has(token)) {
|
|
81625
|
+
continue;
|
|
81626
|
+
}
|
|
81627
|
+
const content = this.content(token);
|
|
81628
|
+
if (content === "" || content.endsWith(" ") === false) {
|
|
81629
|
+
continue;
|
|
81630
|
+
}
|
|
81631
|
+
reported.add(token);
|
|
81632
|
+
const message = token.getStr().startsWith("'")
|
|
81633
|
+
? `Trailing blanks of ${token.getStr()} are ignored here, use a text string literal`
|
|
81634
|
+
: `${token.getStr()} is ignored here, use \` \``;
|
|
81635
|
+
issues.push(issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity, this.buildFix(file, token)));
|
|
81636
|
+
}
|
|
81637
|
+
return issues;
|
|
81638
|
+
}
|
|
81639
|
+
/** the token of a character field literal or of space at the start of the operand */
|
|
81640
|
+
blankOperand(operand) {
|
|
81641
|
+
var _a;
|
|
81642
|
+
const first = operand.getChildren()[0];
|
|
81643
|
+
if (!(first instanceof nodes_1.ExpressionNode)) {
|
|
81644
|
+
return undefined;
|
|
81645
|
+
}
|
|
81646
|
+
if (first.get() instanceof Expressions.Constant) {
|
|
81647
|
+
const str = (_a = first.findDirectExpression(Expressions.ConstantString)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
|
|
81648
|
+
return (str === null || str === void 0 ? void 0 : str.getStr().startsWith("'")) ? str : undefined;
|
|
81649
|
+
}
|
|
81650
|
+
else if (first.get() instanceof Expressions.FieldChain && first.concatTokens().toUpperCase() === "SPACE") {
|
|
81651
|
+
return first.getFirstToken();
|
|
81652
|
+
}
|
|
81653
|
+
return undefined;
|
|
81654
|
+
}
|
|
81655
|
+
/** the value of a character field literal, " " for space */
|
|
81656
|
+
content(token) {
|
|
81657
|
+
const str = token.getStr();
|
|
81658
|
+
if (str.startsWith("'") === false) {
|
|
81659
|
+
return " ";
|
|
81660
|
+
}
|
|
81661
|
+
return str.substring(1, str.length - 1).replace(/''/g, "'");
|
|
81662
|
+
}
|
|
81663
|
+
buildFix(file, token) {
|
|
81664
|
+
const content = this.content(token);
|
|
81665
|
+
if (content === "") {
|
|
81666
|
+
return undefined;
|
|
81667
|
+
}
|
|
81668
|
+
return edit_helper_1.EditHelper.replaceToken(file, token, "`" + content.replace(/`/g, "``") + "`");
|
|
81669
|
+
}
|
|
81670
|
+
}
|
|
81671
|
+
exports.CharacterFieldLiteralBlanks = CharacterFieldLiteralBlanks;
|
|
81672
|
+
// tokens directly before the pattern of FIND and REPLACE, when no FindType is given
|
|
81673
|
+
CharacterFieldLiteralBlanks.beforePattern = new Set(["FIND", "REPLACE", "OF", "OCCURRENCE", "OCCURRENCES", "OCCURENCE", "OCCURENCES"]);
|
|
81674
|
+
//# sourceMappingURL=character_field_literal_blanks.js.map
|
|
81675
|
+
|
|
81676
|
+
/***/ },
|
|
81677
|
+
|
|
81404
81678
|
/***/ "../core/build/src/rules/check_abstract.js"
|
|
81405
81679
|
/*!*************************************************!*\
|
|
81406
81680
|
!*** ../core/build/src/rules/check_abstract.js ***!
|
|
@@ -90976,6 +91250,210 @@ exports.Exporting = Exporting;
|
|
|
90976
91250
|
|
|
90977
91251
|
/***/ },
|
|
90978
91252
|
|
|
91253
|
+
/***/ "../core/build/src/rules/field_symbol_never_assigned.js"
|
|
91254
|
+
/*!**************************************************************!*\
|
|
91255
|
+
!*** ../core/build/src/rules/field_symbol_never_assigned.js ***!
|
|
91256
|
+
\**************************************************************/
|
|
91257
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
91258
|
+
|
|
91259
|
+
"use strict";
|
|
91260
|
+
|
|
91261
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
91262
|
+
if (k2 === undefined) k2 = k;
|
|
91263
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
91264
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
91265
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
91266
|
+
}
|
|
91267
|
+
Object.defineProperty(o, k2, desc);
|
|
91268
|
+
}) : (function(o, m, k, k2) {
|
|
91269
|
+
if (k2 === undefined) k2 = k;
|
|
91270
|
+
o[k2] = m[k];
|
|
91271
|
+
}));
|
|
91272
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
91273
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
91274
|
+
}) : function(o, v) {
|
|
91275
|
+
o["default"] = v;
|
|
91276
|
+
});
|
|
91277
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
91278
|
+
var ownKeys = function(o) {
|
|
91279
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
91280
|
+
var ar = [];
|
|
91281
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
91282
|
+
return ar;
|
|
91283
|
+
};
|
|
91284
|
+
return ownKeys(o);
|
|
91285
|
+
};
|
|
91286
|
+
return function (mod) {
|
|
91287
|
+
if (mod && mod.__esModule) return mod;
|
|
91288
|
+
var result = {};
|
|
91289
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
91290
|
+
__setModuleDefault(result, mod);
|
|
91291
|
+
return result;
|
|
91292
|
+
};
|
|
91293
|
+
})();
|
|
91294
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
91295
|
+
exports.FieldSymbolNeverAssigned = exports.FieldSymbolNeverAssignedConf = void 0;
|
|
91296
|
+
const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
|
|
91297
|
+
const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
|
|
91298
|
+
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
91299
|
+
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
91300
|
+
const _abap_rule_1 = __webpack_require__(/*! ./_abap_rule */ "../core/build/src/rules/_abap_rule.js");
|
|
91301
|
+
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
91302
|
+
const token_node_1 = __webpack_require__(/*! ../abap/nodes/token_node */ "../core/build/src/abap/nodes/token_node.js");
|
|
91303
|
+
const _statement_1 = __webpack_require__(/*! ../abap/2_statements/statements/_statement */ "../core/build/src/abap/2_statements/statements/_statement.js");
|
|
91304
|
+
class FieldSymbolNeverAssignedConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
91305
|
+
}
|
|
91306
|
+
exports.FieldSymbolNeverAssignedConf = FieldSymbolNeverAssignedConf;
|
|
91307
|
+
class FieldSymbolNeverAssigned extends _abap_rule_1.ABAPRule {
|
|
91308
|
+
constructor() {
|
|
91309
|
+
super(...arguments);
|
|
91310
|
+
this.conf = new FieldSymbolNeverAssignedConf();
|
|
91311
|
+
}
|
|
91312
|
+
getMetadata() {
|
|
91313
|
+
return {
|
|
91314
|
+
key: "field_symbol_never_assigned",
|
|
91315
|
+
title: "Field symbol never assigned",
|
|
91316
|
+
shortDescription: `Reports a local field symbol that is used, but never assigned in its method, form or function module`,
|
|
91317
|
+
extendedInformation: `A field symbol declared with FIELD-SYMBOLS in a method, form or function module can only be
|
|
91318
|
+
assigned in that procedure. If no ASSIGN ... TO <fs> or ... ASSIGNING <fs> of it exists there,
|
|
91319
|
+
reading or writing it raises the runtime error GETWA_NOT_ASSIGNED. This is typically a copy-paste
|
|
91320
|
+
error, where a statement uses a field symbol other than the one assigned before it.
|
|
91321
|
+
|
|
91322
|
+
Assignments are ASSIGN, ASSIGN LOCAL COPY, and ASSIGNING of LOOP, READ TABLE, INSERT, APPEND,
|
|
91323
|
+
MODIFY and COLLECT, anywhere in the procedure. The order of the statements is not checked.
|
|
91324
|
+
|
|
91325
|
+
Not reported: field symbols only used in IS [NOT] ASSIGNED or UNASSIGN, field symbols declared
|
|
91326
|
+
with DEFAULT, inline declarations, global field symbols, and procedures that contain a macro
|
|
91327
|
+
call, an INCLUDE or a statement that cannot be parsed.`,
|
|
91328
|
+
tags: [_irule_1.RuleTag.SingleFile],
|
|
91329
|
+
badExample: `FIELD-SYMBOLS <type> TYPE ty_type.
|
|
91330
|
+
FIELD-SYMBOLS <attr> TYPE ty_attr.
|
|
91331
|
+
LOOP AT types ASSIGNING <type>.
|
|
91332
|
+
CLEAR <attr>-author.
|
|
91333
|
+
ENDLOOP.`,
|
|
91334
|
+
goodExample: `FIELD-SYMBOLS <type> TYPE ty_type.
|
|
91335
|
+
LOOP AT types ASSIGNING <type>.
|
|
91336
|
+
CLEAR <type>-author.
|
|
91337
|
+
ENDLOOP.`,
|
|
91338
|
+
};
|
|
91339
|
+
}
|
|
91340
|
+
getConfig() {
|
|
91341
|
+
return this.conf;
|
|
91342
|
+
}
|
|
91343
|
+
setConfig(conf) {
|
|
91344
|
+
this.conf = conf;
|
|
91345
|
+
}
|
|
91346
|
+
runParsed(file) {
|
|
91347
|
+
const issues = [];
|
|
91348
|
+
const statements = file.getStatements();
|
|
91349
|
+
let start = undefined;
|
|
91350
|
+
for (let i = 0; i < statements.length; i++) {
|
|
91351
|
+
const s = statements[i].get();
|
|
91352
|
+
if (s instanceof Statements.MethodImplementation
|
|
91353
|
+
|| s instanceof Statements.Form
|
|
91354
|
+
|| s instanceof Statements.FunctionModule) {
|
|
91355
|
+
start = i;
|
|
91356
|
+
}
|
|
91357
|
+
else if (start !== undefined
|
|
91358
|
+
&& (s instanceof Statements.EndMethod
|
|
91359
|
+
|| s instanceof Statements.EndForm
|
|
91360
|
+
|| s instanceof Statements.EndFunction)) {
|
|
91361
|
+
issues.push(...this.checkProcedure(file, statements.slice(start, i + 1)));
|
|
91362
|
+
start = undefined;
|
|
91363
|
+
}
|
|
91364
|
+
}
|
|
91365
|
+
return issues;
|
|
91366
|
+
}
|
|
91367
|
+
////////////////
|
|
91368
|
+
checkProcedure(file, statements) {
|
|
91369
|
+
var _a;
|
|
91370
|
+
const declared = new Map();
|
|
91371
|
+
const assigned = new Set();
|
|
91372
|
+
const used = new Map();
|
|
91373
|
+
for (const statement of statements) {
|
|
91374
|
+
const s = statement.get();
|
|
91375
|
+
if (s instanceof _statement_1.Unknown
|
|
91376
|
+
|| s instanceof _statement_1.MacroCall
|
|
91377
|
+
|| s instanceof Statements.Include) {
|
|
91378
|
+
return [];
|
|
91379
|
+
}
|
|
91380
|
+
else if (s instanceof Statements.FieldSymbol) {
|
|
91381
|
+
const name = (_a = statement.findDirectExpression(Expressions.FieldSymbol)) === null || _a === void 0 ? void 0 : _a.concatTokens();
|
|
91382
|
+
if (name !== undefined && statement.findDirectTokenByText("DEFAULT") === undefined) {
|
|
91383
|
+
declared.set(name.toUpperCase(), name);
|
|
91384
|
+
}
|
|
91385
|
+
continue;
|
|
91386
|
+
}
|
|
91387
|
+
else if (s instanceof Statements.Unassign) {
|
|
91388
|
+
continue;
|
|
91389
|
+
}
|
|
91390
|
+
this.walk(statement, assigned, used);
|
|
91391
|
+
}
|
|
91392
|
+
const issues = [];
|
|
91393
|
+
const procedure = this.procedureName(statements[0]);
|
|
91394
|
+
for (const [upper, name] of declared) {
|
|
91395
|
+
const token = used.get(upper);
|
|
91396
|
+
if (token === undefined || assigned.has(upper)) {
|
|
91397
|
+
continue;
|
|
91398
|
+
}
|
|
91399
|
+
const message = `Field symbol ${name} is never assigned in this ${procedure}`;
|
|
91400
|
+
issues.push(issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity));
|
|
91401
|
+
}
|
|
91402
|
+
return issues;
|
|
91403
|
+
}
|
|
91404
|
+
/** collects the assigned field symbols, and the first use of each other field symbol */
|
|
91405
|
+
walk(node, assigned, used) {
|
|
91406
|
+
var _a;
|
|
91407
|
+
for (const child of node.getChildren()) {
|
|
91408
|
+
if (child instanceof token_node_1.TokenNode) {
|
|
91409
|
+
continue;
|
|
91410
|
+
}
|
|
91411
|
+
const e = child.get();
|
|
91412
|
+
if (e instanceof Expressions.FSTarget
|
|
91413
|
+
|| e instanceof Expressions.InlineFS
|
|
91414
|
+
|| (e instanceof Expressions.TargetFieldSymbol && this.isBinding(node))) {
|
|
91415
|
+
const name = (_a = child.findFirstExpression(Expressions.FieldSymbol)) === null || _a === void 0 ? void 0 : _a.concatTokens();
|
|
91416
|
+
if (name !== undefined) {
|
|
91417
|
+
assigned.add(name.toUpperCase());
|
|
91418
|
+
}
|
|
91419
|
+
}
|
|
91420
|
+
else if (e instanceof Expressions.Compare && child.findDirectTokenByText("ASSIGNED") !== undefined) {
|
|
91421
|
+
continue;
|
|
91422
|
+
}
|
|
91423
|
+
else if (e instanceof Expressions.FieldSymbol) {
|
|
91424
|
+
const upper = child.concatTokens().toUpperCase();
|
|
91425
|
+
if (used.has(upper) === false) {
|
|
91426
|
+
used.set(upper, child.getFirstToken());
|
|
91427
|
+
}
|
|
91428
|
+
}
|
|
91429
|
+
else {
|
|
91430
|
+
this.walk(child, assigned, used);
|
|
91431
|
+
}
|
|
91432
|
+
}
|
|
91433
|
+
}
|
|
91434
|
+
/** TargetFieldSymbol directly in these binds the field symbol, elsewhere it is a write to the assigned data */
|
|
91435
|
+
isBinding(parent) {
|
|
91436
|
+
const p = parent.get();
|
|
91437
|
+
return p instanceof Statements.AssignLocalCopy
|
|
91438
|
+
|| p instanceof Expressions.For
|
|
91439
|
+
|| p instanceof Expressions.InlineLoopDefinition;
|
|
91440
|
+
}
|
|
91441
|
+
procedureName(statement) {
|
|
91442
|
+
const s = statement.get();
|
|
91443
|
+
if (s instanceof Statements.Form) {
|
|
91444
|
+
return "form";
|
|
91445
|
+
}
|
|
91446
|
+
else if (s instanceof Statements.FunctionModule) {
|
|
91447
|
+
return "function module";
|
|
91448
|
+
}
|
|
91449
|
+
return "method";
|
|
91450
|
+
}
|
|
91451
|
+
}
|
|
91452
|
+
exports.FieldSymbolNeverAssigned = FieldSymbolNeverAssigned;
|
|
91453
|
+
//# sourceMappingURL=field_symbol_never_assigned.js.map
|
|
91454
|
+
|
|
91455
|
+
/***/ },
|
|
91456
|
+
|
|
90979
91457
|
/***/ "../core/build/src/rules/final_newline.js"
|
|
90980
91458
|
/*!************************************************!*\
|
|
90981
91459
|
!*** ../core/build/src/rules/final_newline.js ***!
|
|
@@ -94373,6 +94851,7 @@ __exportStar(__webpack_require__(/*! ./cds_parser_error */ "../core/build/src/ru
|
|
|
94373
94851
|
__exportStar(__webpack_require__(/*! ./chain_mainly_declarations */ "../core/build/src/rules/chain_mainly_declarations.js"), exports);
|
|
94374
94852
|
__exportStar(__webpack_require__(/*! ./change_if_to_case */ "../core/build/src/rules/change_if_to_case.js"), exports);
|
|
94375
94853
|
__exportStar(__webpack_require__(/*! ./changing_sorted_line */ "../core/build/src/rules/changing_sorted_line.js"), exports);
|
|
94854
|
+
__exportStar(__webpack_require__(/*! ./character_field_literal_blanks */ "../core/build/src/rules/character_field_literal_blanks.js"), exports);
|
|
94376
94855
|
__exportStar(__webpack_require__(/*! ./check_abstract */ "../core/build/src/rules/check_abstract.js"), exports);
|
|
94377
94856
|
__exportStar(__webpack_require__(/*! ./check_comments */ "../core/build/src/rules/check_comments.js"), exports);
|
|
94378
94857
|
__exportStar(__webpack_require__(/*! ./check_ddic */ "../core/build/src/rules/check_ddic.js"), exports);
|
|
@@ -94414,6 +94893,7 @@ __exportStar(__webpack_require__(/*! ./else_after_all_returns */ "../core/build/
|
|
|
94414
94893
|
__exportStar(__webpack_require__(/*! ./exit_or_check */ "../core/build/src/rules/exit_or_check.js"), exports);
|
|
94415
94894
|
__exportStar(__webpack_require__(/*! ./expand_macros */ "../core/build/src/rules/expand_macros.js"), exports);
|
|
94416
94895
|
__exportStar(__webpack_require__(/*! ./exporting */ "../core/build/src/rules/exporting.js"), exports);
|
|
94896
|
+
__exportStar(__webpack_require__(/*! ./field_symbol_never_assigned */ "../core/build/src/rules/field_symbol_never_assigned.js"), exports);
|
|
94417
94897
|
__exportStar(__webpack_require__(/*! ./final_newline */ "../core/build/src/rules/final_newline.js"), exports);
|
|
94418
94898
|
__exportStar(__webpack_require__(/*! ./fm_global_parameters_obsolete */ "../core/build/src/rules/fm_global_parameters_obsolete.js"), exports);
|
|
94419
94899
|
__exportStar(__webpack_require__(/*! ./forbidden_identifier */ "../core/build/src/rules/forbidden_identifier.js"), exports);
|
|
@@ -94453,6 +94933,7 @@ __exportStar(__webpack_require__(/*! ./line_only_punc */ "../core/build/src/rule
|
|
|
94453
94933
|
__exportStar(__webpack_require__(/*! ./local_class_naming */ "../core/build/src/rules/local_class_naming.js"), exports);
|
|
94454
94934
|
__exportStar(__webpack_require__(/*! ./local_testclass_consistency */ "../core/build/src/rules/local_testclass_consistency.js"), exports);
|
|
94455
94935
|
__exportStar(__webpack_require__(/*! ./local_variable_names */ "../core/build/src/rules/local_variable_names.js"), exports);
|
|
94936
|
+
__exportStar(__webpack_require__(/*! ./loop_target_misuse */ "../core/build/src/rules/loop_target_misuse.js"), exports);
|
|
94456
94937
|
__exportStar(__webpack_require__(/*! ./macro_naming */ "../core/build/src/rules/macro_naming.js"), exports);
|
|
94457
94938
|
__exportStar(__webpack_require__(/*! ./main_file_contents */ "../core/build/src/rules/main_file_contents.js"), exports);
|
|
94458
94939
|
__exportStar(__webpack_require__(/*! ./many_parentheses */ "../core/build/src/rules/many_parentheses.js"), exports);
|
|
@@ -94532,6 +95013,7 @@ __exportStar(__webpack_require__(/*! ./space_before_colon */ "../core/build/src/
|
|
|
94532
95013
|
__exportStar(__webpack_require__(/*! ./space_before_dot */ "../core/build/src/rules/space_before_dot.js"), exports);
|
|
94533
95014
|
__exportStar(__webpack_require__(/*! ./sql_escape_host_variables */ "../core/build/src/rules/sql_escape_host_variables.js"), exports);
|
|
94534
95015
|
__exportStar(__webpack_require__(/*! ./sql_value_conversion */ "../core/build/src/rules/sql_value_conversion.js"), exports);
|
|
95016
|
+
__exportStar(__webpack_require__(/*! ./stale_subrc */ "../core/build/src/rules/stale_subrc.js"), exports);
|
|
94535
95017
|
__exportStar(__webpack_require__(/*! ./start_at_tab */ "../core/build/src/rules/start_at_tab.js"), exports);
|
|
94536
95018
|
__exportStar(__webpack_require__(/*! ./static_call_via_instance */ "../core/build/src/rules/static_call_via_instance.js"), exports);
|
|
94537
95019
|
__exportStar(__webpack_require__(/*! ./strict_sql */ "../core/build/src/rules/strict_sql.js"), exports);
|
|
@@ -94547,6 +95029,7 @@ __exportStar(__webpack_require__(/*! ./try_without_catch */ "../core/build/src/r
|
|
|
94547
95029
|
__exportStar(__webpack_require__(/*! ./type_form_parameters */ "../core/build/src/rules/type_form_parameters.js"), exports);
|
|
94548
95030
|
__exportStar(__webpack_require__(/*! ./types_naming */ "../core/build/src/rules/types_naming.js"), exports);
|
|
94549
95031
|
__exportStar(__webpack_require__(/*! ./uncaught_exception */ "../core/build/src/rules/uncaught_exception.js"), exports);
|
|
95032
|
+
__exportStar(__webpack_require__(/*! ./unit_test_assertions */ "../core/build/src/rules/unit_test_assertions.js"), exports);
|
|
94550
95033
|
__exportStar(__webpack_require__(/*! ./unknown_types */ "../core/build/src/rules/unknown_types.js"), exports);
|
|
94551
95034
|
__exportStar(__webpack_require__(/*! ./unnecessary_chaining */ "../core/build/src/rules/unnecessary_chaining.js"), exports);
|
|
94552
95035
|
__exportStar(__webpack_require__(/*! ./unnecessary_copy */ "../core/build/src/rules/unnecessary_copy.js"), exports);
|
|
@@ -96909,10 +97392,321 @@ exports.LocalVariableNames = LocalVariableNames;
|
|
|
96909
97392
|
|
|
96910
97393
|
/***/ },
|
|
96911
97394
|
|
|
96912
|
-
/***/ "../core/build/src/rules/
|
|
96913
|
-
|
|
96914
|
-
!*** ../core/build/src/rules/
|
|
96915
|
-
|
|
97395
|
+
/***/ "../core/build/src/rules/loop_target_misuse.js"
|
|
97396
|
+
/*!*****************************************************!*\
|
|
97397
|
+
!*** ../core/build/src/rules/loop_target_misuse.js ***!
|
|
97398
|
+
\*****************************************************/
|
|
97399
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
97400
|
+
|
|
97401
|
+
"use strict";
|
|
97402
|
+
|
|
97403
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
97404
|
+
if (k2 === undefined) k2 = k;
|
|
97405
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
97406
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
97407
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
97408
|
+
}
|
|
97409
|
+
Object.defineProperty(o, k2, desc);
|
|
97410
|
+
}) : (function(o, m, k, k2) {
|
|
97411
|
+
if (k2 === undefined) k2 = k;
|
|
97412
|
+
o[k2] = m[k];
|
|
97413
|
+
}));
|
|
97414
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
97415
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
97416
|
+
}) : function(o, v) {
|
|
97417
|
+
o["default"] = v;
|
|
97418
|
+
});
|
|
97419
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
97420
|
+
var ownKeys = function(o) {
|
|
97421
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
97422
|
+
var ar = [];
|
|
97423
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
97424
|
+
return ar;
|
|
97425
|
+
};
|
|
97426
|
+
return ownKeys(o);
|
|
97427
|
+
};
|
|
97428
|
+
return function (mod) {
|
|
97429
|
+
if (mod && mod.__esModule) return mod;
|
|
97430
|
+
var result = {};
|
|
97431
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
97432
|
+
__setModuleDefault(result, mod);
|
|
97433
|
+
return result;
|
|
97434
|
+
};
|
|
97435
|
+
})();
|
|
97436
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
97437
|
+
exports.LoopTargetMisuse = exports.LoopTargetMisuseConf = void 0;
|
|
97438
|
+
const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
|
|
97439
|
+
const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
|
|
97440
|
+
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
97441
|
+
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
97442
|
+
const _abap_rule_1 = __webpack_require__(/*! ./_abap_rule */ "../core/build/src/rules/_abap_rule.js");
|
|
97443
|
+
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
97444
|
+
class LoopTargetMisuseConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
97445
|
+
constructor() {
|
|
97446
|
+
super(...arguments);
|
|
97447
|
+
/** Report a LOOP inside a LOOP with the same target, when the outer loop body uses the target after the inner ENDLOOP */
|
|
97448
|
+
this.nestedLoop = true;
|
|
97449
|
+
/** Report LOOP AT ... INTO <fs> and READ TABLE ... INTO <fs> when the local field symbol is only bound by ASSIGNING,
|
|
97450
|
+
* so the statement overwrites a table row */
|
|
97451
|
+
this.intoFieldSymbol = true;
|
|
97452
|
+
}
|
|
97453
|
+
}
|
|
97454
|
+
exports.LoopTargetMisuseConf = LoopTargetMisuseConf;
|
|
97455
|
+
class LoopTargetMisuse extends _abap_rule_1.ABAPRule {
|
|
97456
|
+
constructor() {
|
|
97457
|
+
super(...arguments);
|
|
97458
|
+
this.conf = new LoopTargetMisuseConf();
|
|
97459
|
+
}
|
|
97460
|
+
getMetadata() {
|
|
97461
|
+
return {
|
|
97462
|
+
key: "loop_target_misuse",
|
|
97463
|
+
title: "LOOP and READ TABLE targets used wrongly",
|
|
97464
|
+
shortDescription: `Reports a nested LOOP that reuses the target of the enclosing LOOP, and INTO <fs> where ASSIGNING was meant`,
|
|
97465
|
+
extendedInformation: `Option nestedLoop: a LOOP inside a LOOP with the same INTO, REFERENCE INTO or ASSIGNING target.
|
|
97466
|
+
After the inner ENDLOOP, the target holds the last row of the inner table, not the row of the
|
|
97467
|
+
outer loop. Reported when the outer loop body uses the target after the inner ENDLOOP, before
|
|
97468
|
+
it is assigned again.
|
|
97469
|
+
Not reported: a target of a loop that has already ended, a target that is not a plain variable
|
|
97470
|
+
or field symbol, an enclosing LOOP with GROUP BY, and a target the outer loop body does not use
|
|
97471
|
+
after the inner loop.
|
|
97472
|
+
|
|
97473
|
+
Option intoFieldSymbol: LOOP AT ... INTO <fs> or READ TABLE ... INTO <fs>. INTO copies the row
|
|
97474
|
+
into the data object the field symbol points to. When <fs> was bound by ASSIGNING, that data
|
|
97475
|
+
object is a row of a table, and the statement overwrites it. ASSIGNING was meant.
|
|
97476
|
+
Reported only for a field symbol declared in the method, form or function module, and only when
|
|
97477
|
+
no ASSIGN and no STRUCTURE ... DEFAULT binds it there, so it can only point to a table row.`,
|
|
97478
|
+
tags: [_irule_1.RuleTag.SingleFile],
|
|
97479
|
+
badExample: `LOOP AT lt_header INTO ls_row.
|
|
97480
|
+
LOOP AT lt_items INTO ls_row WHERE parent = ls_row-id.
|
|
97481
|
+
lv_sum = lv_sum + ls_row-amount.
|
|
97482
|
+
ENDLOOP.
|
|
97483
|
+
ls_row-amount = lv_sum.
|
|
97484
|
+
APPEND ls_row TO lt_result.
|
|
97485
|
+
ENDLOOP.
|
|
97486
|
+
|
|
97487
|
+
LOOP AT lt_a ASSIGNING <ls_a>.
|
|
97488
|
+
ENDLOOP.
|
|
97489
|
+
READ TABLE lt_a INTO <ls_a> INDEX 1.`,
|
|
97490
|
+
goodExample: `LOOP AT lt_header INTO ls_row.
|
|
97491
|
+
LOOP AT lt_items INTO ls_item WHERE parent = ls_row-id.
|
|
97492
|
+
lv_sum = lv_sum + ls_item-amount.
|
|
97493
|
+
ENDLOOP.
|
|
97494
|
+
ls_row-amount = lv_sum.
|
|
97495
|
+
APPEND ls_row TO lt_result.
|
|
97496
|
+
ENDLOOP.
|
|
97497
|
+
|
|
97498
|
+
LOOP AT lt_a ASSIGNING <ls_a>.
|
|
97499
|
+
ENDLOOP.
|
|
97500
|
+
READ TABLE lt_a ASSIGNING <ls_a> INDEX 1.`,
|
|
97501
|
+
};
|
|
97502
|
+
}
|
|
97503
|
+
getConfig() {
|
|
97504
|
+
return this.conf;
|
|
97505
|
+
}
|
|
97506
|
+
setConfig(conf) {
|
|
97507
|
+
this.conf = conf;
|
|
97508
|
+
}
|
|
97509
|
+
runParsed(file) {
|
|
97510
|
+
const issues = [];
|
|
97511
|
+
const statements = file.getStatements();
|
|
97512
|
+
if (this.conf.nestedLoop !== false) {
|
|
97513
|
+
issues.push(...this.checkNestedLoop(file, statements));
|
|
97514
|
+
}
|
|
97515
|
+
if (this.conf.intoFieldSymbol !== false) {
|
|
97516
|
+
issues.push(...this.checkIntoFieldSymbol(file, statements));
|
|
97517
|
+
}
|
|
97518
|
+
return issues;
|
|
97519
|
+
}
|
|
97520
|
+
////////////////
|
|
97521
|
+
checkNestedLoop(file, statements) {
|
|
97522
|
+
const issues = [];
|
|
97523
|
+
// one entry per open LOOP, key undefined when the LOOP has no target to compare
|
|
97524
|
+
let open = [];
|
|
97525
|
+
for (let i = 0; i < statements.length; i++) {
|
|
97526
|
+
const statement = statements[i];
|
|
97527
|
+
const s = statement.get();
|
|
97528
|
+
if (this.isBlockBoundary(statement)) {
|
|
97529
|
+
open = [];
|
|
97530
|
+
}
|
|
97531
|
+
else if (s instanceof Statements.EndLoop) {
|
|
97532
|
+
open.pop();
|
|
97533
|
+
}
|
|
97534
|
+
else if (s instanceof Statements.Loop) {
|
|
97535
|
+
const node = this.loopTarget(statement);
|
|
97536
|
+
const target = node ? this.targetName(node) : undefined;
|
|
97537
|
+
// INTO <fs> inside LOOP ... ASSIGNING <fs> is left to the option intoFieldSymbol
|
|
97538
|
+
const key = target === undefined ? undefined : ((node === null || node === void 0 ? void 0 : node.get()) instanceof Expressions.Target ? "INTO " : "ASSIGNING ") + target;
|
|
97539
|
+
const outer = key === undefined ? undefined : [...open].reverse().find(o => o.key === key);
|
|
97540
|
+
if (node !== undefined && target !== undefined && outer !== undefined) {
|
|
97541
|
+
const innerEnd = this.findEndLoop(statements, i);
|
|
97542
|
+
const outerEnd = this.findEndLoop(statements, outer.index);
|
|
97543
|
+
if (innerEnd !== undefined && outerEnd !== undefined && this.usedBetween(statements, innerEnd + 1, outerEnd, target)) {
|
|
97544
|
+
const name = node.concatTokens();
|
|
97545
|
+
const message = `Inner LOOP reuses ${name}, the target of the enclosing LOOP, `
|
|
97546
|
+
+ `which is used after the inner ENDLOOP and then holds a row of the inner table`;
|
|
97547
|
+
issues.push(issue_1.Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity));
|
|
97548
|
+
}
|
|
97549
|
+
}
|
|
97550
|
+
const grouped = statement.findDirectExpression(Expressions.LoopGroupBy) !== undefined;
|
|
97551
|
+
open.push({ index: i, key: grouped ? undefined : key });
|
|
97552
|
+
}
|
|
97553
|
+
}
|
|
97554
|
+
return issues;
|
|
97555
|
+
}
|
|
97556
|
+
/** the Target or FSTarget after INTO, REFERENCE INTO or ASSIGNING of a LOOP */
|
|
97557
|
+
loopTarget(statement) {
|
|
97558
|
+
const target = statement.findDirectExpression(Expressions.LoopTarget);
|
|
97559
|
+
return (target === null || target === void 0 ? void 0 : target.findDirectExpression(Expressions.Target)) || (target === null || target === void 0 ? void 0 : target.findDirectExpression(Expressions.FSTarget));
|
|
97560
|
+
}
|
|
97561
|
+
/** upper case name of a Target or FSTarget that is a plain variable or field symbol, also declared inline */
|
|
97562
|
+
targetName(node) {
|
|
97563
|
+
var _a, _b;
|
|
97564
|
+
const inline = ((_a = node.findDirectExpression(Expressions.InlineData)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.TargetField))
|
|
97565
|
+
|| ((_b = node.findDirectExpression(Expressions.InlineFS)) === null || _b === void 0 ? void 0 : _b.findDirectExpression(Expressions.TargetFieldSymbol));
|
|
97566
|
+
const tokens = (inline || node).getAllTokens();
|
|
97567
|
+
return tokens.length === 1 ? tokens[0].getStr().toUpperCase() : undefined;
|
|
97568
|
+
}
|
|
97569
|
+
/** index of the ENDLOOP that closes the LOOP at the index */
|
|
97570
|
+
findEndLoop(statements, index) {
|
|
97571
|
+
let depth = 0;
|
|
97572
|
+
for (let i = index + 1; i < statements.length && this.isBlockBoundary(statements[i]) === false; i++) {
|
|
97573
|
+
const s = statements[i].get();
|
|
97574
|
+
if (s instanceof Statements.Loop) {
|
|
97575
|
+
depth++;
|
|
97576
|
+
}
|
|
97577
|
+
else if (s instanceof Statements.EndLoop) {
|
|
97578
|
+
if (depth === 0) {
|
|
97579
|
+
return i;
|
|
97580
|
+
}
|
|
97581
|
+
depth--;
|
|
97582
|
+
}
|
|
97583
|
+
}
|
|
97584
|
+
return undefined;
|
|
97585
|
+
}
|
|
97586
|
+
/** true when a statement in [from, to) uses the variable before a statement assigns all of it */
|
|
97587
|
+
usedBetween(statements, from, to, name) {
|
|
97588
|
+
for (let i = from; i < to; i++) {
|
|
97589
|
+
const statement = statements[i];
|
|
97590
|
+
const s = statement.get();
|
|
97591
|
+
if (s instanceof Statements.Data || s instanceof Statements.FieldSymbol) {
|
|
97592
|
+
continue;
|
|
97593
|
+
}
|
|
97594
|
+
const whole = new Set();
|
|
97595
|
+
for (const t of [...statement.findAllExpressions(Expressions.Target), ...statement.findAllExpressions(Expressions.FSTarget)]) {
|
|
97596
|
+
if (this.targetName(t) === name) {
|
|
97597
|
+
t.getAllTokens().forEach(token => whole.add(token));
|
|
97598
|
+
}
|
|
97599
|
+
}
|
|
97600
|
+
const tokens = statement.getTokens();
|
|
97601
|
+
for (let j = 0; j < tokens.length; j++) {
|
|
97602
|
+
const previous = j > 0 ? tokens[j - 1].getStr() : "";
|
|
97603
|
+
if (tokens[j].getStr().toUpperCase() === name
|
|
97604
|
+
&& whole.has(tokens[j]) === false
|
|
97605
|
+
&& ["-", "->", "=>", "~"].includes(previous) === false) {
|
|
97606
|
+
return s instanceof Statements.Unassign ? false : true;
|
|
97607
|
+
}
|
|
97608
|
+
}
|
|
97609
|
+
if (whole.size > 0) {
|
|
97610
|
+
return false;
|
|
97611
|
+
}
|
|
97612
|
+
}
|
|
97613
|
+
return false;
|
|
97614
|
+
}
|
|
97615
|
+
checkIntoFieldSymbol(file, statements) {
|
|
97616
|
+
const issues = [];
|
|
97617
|
+
for (let i = 0; i < statements.length; i++) {
|
|
97618
|
+
const statement = statements[i];
|
|
97619
|
+
const s = statement.get();
|
|
97620
|
+
if (!(s instanceof Statements.Loop) && !(s instanceof Statements.ReadTable)) {
|
|
97621
|
+
continue;
|
|
97622
|
+
}
|
|
97623
|
+
const target = statement.findDirectExpression(Expressions.LoopTarget)
|
|
97624
|
+
|| statement.findDirectExpression(Expressions.ReadTableTarget);
|
|
97625
|
+
const into = target === null || target === void 0 ? void 0 : target.findDirectExpression(Expressions.Target);
|
|
97626
|
+
const fs = into === null || into === void 0 ? void 0 : into.findDirectExpression(Expressions.TargetFieldSymbol);
|
|
97627
|
+
if (into === undefined || fs === undefined || fs.concatTokens() !== into.concatTokens()) {
|
|
97628
|
+
continue;
|
|
97629
|
+
}
|
|
97630
|
+
const name = fs.concatTokens().toUpperCase();
|
|
97631
|
+
if (this.onlyBoundToRows(statements, i, name) === false) {
|
|
97632
|
+
continue;
|
|
97633
|
+
}
|
|
97634
|
+
const what = s instanceof Statements.Loop ? "LOOP AT" : "READ TABLE";
|
|
97635
|
+
const message = `${what} ... INTO ${fs.concatTokens()} overwrites the row the field symbol points to, use ASSIGNING`;
|
|
97636
|
+
issues.push(issue_1.Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity));
|
|
97637
|
+
}
|
|
97638
|
+
return issues;
|
|
97639
|
+
}
|
|
97640
|
+
/** true when the field symbol is declared in the block around the statement and every binding of it
|
|
97641
|
+
* in that block is an ASSIGNING, so it can only point to a table row */
|
|
97642
|
+
onlyBoundToRows(statements, index, name) {
|
|
97643
|
+
var _a;
|
|
97644
|
+
let start = index;
|
|
97645
|
+
while (start > 0 && this.isBlockBoundary(statements[start]) === false) {
|
|
97646
|
+
start--;
|
|
97647
|
+
}
|
|
97648
|
+
if (this.startsBlock(statements[start]) === false) {
|
|
97649
|
+
return false;
|
|
97650
|
+
}
|
|
97651
|
+
let declared = false;
|
|
97652
|
+
let assigning = false;
|
|
97653
|
+
for (let i = start + 1; i < statements.length && this.endsBlock(statements[i]) === false; i++) {
|
|
97654
|
+
const statement = statements[i];
|
|
97655
|
+
if (statement.get() instanceof Statements.FieldSymbol) {
|
|
97656
|
+
if (((_a = statement.findDirectExpression(Expressions.FieldSymbol)) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase()) === name) {
|
|
97657
|
+
if (statement.findDirectTokenByText("DEFAULT") !== undefined) {
|
|
97658
|
+
return false;
|
|
97659
|
+
}
|
|
97660
|
+
declared = true;
|
|
97661
|
+
}
|
|
97662
|
+
continue;
|
|
97663
|
+
}
|
|
97664
|
+
for (const fsTarget of statement.findAllExpressions(Expressions.FSTarget)) {
|
|
97665
|
+
if (this.fsName(fsTarget) !== name) {
|
|
97666
|
+
continue;
|
|
97667
|
+
}
|
|
97668
|
+
if (statement.get() instanceof Statements.Assign) {
|
|
97669
|
+
return false;
|
|
97670
|
+
}
|
|
97671
|
+
assigning = true;
|
|
97672
|
+
if (fsTarget.findDirectExpression(Expressions.InlineFS) !== undefined) {
|
|
97673
|
+
declared = true;
|
|
97674
|
+
}
|
|
97675
|
+
}
|
|
97676
|
+
}
|
|
97677
|
+
return declared && assigning;
|
|
97678
|
+
}
|
|
97679
|
+
fsName(fsTarget) {
|
|
97680
|
+
var _a;
|
|
97681
|
+
return (_a = fsTarget.findFirstExpression(Expressions.FieldSymbol)) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase();
|
|
97682
|
+
}
|
|
97683
|
+
isBlockBoundary(statement) {
|
|
97684
|
+
return this.startsBlock(statement) || this.endsBlock(statement);
|
|
97685
|
+
}
|
|
97686
|
+
startsBlock(statement) {
|
|
97687
|
+
const s = statement.get();
|
|
97688
|
+
return s instanceof Statements.MethodImplementation
|
|
97689
|
+
|| s instanceof Statements.Form
|
|
97690
|
+
|| s instanceof Statements.FunctionModule
|
|
97691
|
+
|| s instanceof Statements.Module;
|
|
97692
|
+
}
|
|
97693
|
+
endsBlock(statement) {
|
|
97694
|
+
const s = statement.get();
|
|
97695
|
+
return s instanceof Statements.EndMethod
|
|
97696
|
+
|| s instanceof Statements.EndForm
|
|
97697
|
+
|| s instanceof Statements.EndFunction
|
|
97698
|
+
|| s instanceof Statements.EndModule;
|
|
97699
|
+
}
|
|
97700
|
+
}
|
|
97701
|
+
exports.LoopTargetMisuse = LoopTargetMisuse;
|
|
97702
|
+
//# sourceMappingURL=loop_target_misuse.js.map
|
|
97703
|
+
|
|
97704
|
+
/***/ },
|
|
97705
|
+
|
|
97706
|
+
/***/ "../core/build/src/rules/macro_naming.js"
|
|
97707
|
+
/*!***********************************************!*\
|
|
97708
|
+
!*** ../core/build/src/rules/macro_naming.js ***!
|
|
97709
|
+
\***********************************************/
|
|
96916
97710
|
(__unused_webpack_module, exports, __webpack_require__) {
|
|
96917
97711
|
|
|
96918
97712
|
"use strict";
|
|
@@ -109563,6 +110357,192 @@ exports.SQLValueConversion = SQLValueConversion;
|
|
|
109563
110357
|
|
|
109564
110358
|
/***/ },
|
|
109565
110359
|
|
|
110360
|
+
/***/ "../core/build/src/rules/stale_subrc.js"
|
|
110361
|
+
/*!**********************************************!*\
|
|
110362
|
+
!*** ../core/build/src/rules/stale_subrc.js ***!
|
|
110363
|
+
\**********************************************/
|
|
110364
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
110365
|
+
|
|
110366
|
+
"use strict";
|
|
110367
|
+
|
|
110368
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
110369
|
+
if (k2 === undefined) k2 = k;
|
|
110370
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
110371
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
110372
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
110373
|
+
}
|
|
110374
|
+
Object.defineProperty(o, k2, desc);
|
|
110375
|
+
}) : (function(o, m, k, k2) {
|
|
110376
|
+
if (k2 === undefined) k2 = k;
|
|
110377
|
+
o[k2] = m[k];
|
|
110378
|
+
}));
|
|
110379
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
110380
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
110381
|
+
}) : function(o, v) {
|
|
110382
|
+
o["default"] = v;
|
|
110383
|
+
});
|
|
110384
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
110385
|
+
var ownKeys = function(o) {
|
|
110386
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
110387
|
+
var ar = [];
|
|
110388
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
110389
|
+
return ar;
|
|
110390
|
+
};
|
|
110391
|
+
return ownKeys(o);
|
|
110392
|
+
};
|
|
110393
|
+
return function (mod) {
|
|
110394
|
+
if (mod && mod.__esModule) return mod;
|
|
110395
|
+
var result = {};
|
|
110396
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
110397
|
+
__setModuleDefault(result, mod);
|
|
110398
|
+
return result;
|
|
110399
|
+
};
|
|
110400
|
+
})();
|
|
110401
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
110402
|
+
exports.StaleSubrc = exports.StaleSubrcConf = void 0;
|
|
110403
|
+
const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
|
|
110404
|
+
const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
|
|
110405
|
+
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
110406
|
+
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
110407
|
+
const _abap_rule_1 = __webpack_require__(/*! ./_abap_rule */ "../core/build/src/rules/_abap_rule.js");
|
|
110408
|
+
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
110409
|
+
const _statement_1 = __webpack_require__(/*! ../abap/2_statements/statements/_statement */ "../core/build/src/abap/2_statements/statements/_statement.js");
|
|
110410
|
+
const severity_1 = __webpack_require__(/*! ../severity */ "../core/build/src/severity.js");
|
|
110411
|
+
const _builtin_1 = __webpack_require__(/*! ../abap/5_syntax/_builtin */ "../core/build/src/abap/5_syntax/_builtin.js");
|
|
110412
|
+
class StaleSubrcConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
110413
|
+
constructor() {
|
|
110414
|
+
super(...arguments);
|
|
110415
|
+
this.severity = severity_1.Severity.Warning;
|
|
110416
|
+
}
|
|
110417
|
+
}
|
|
110418
|
+
exports.StaleSubrcConf = StaleSubrcConf;
|
|
110419
|
+
class StaleSubrc extends _abap_rule_1.ABAPRule {
|
|
110420
|
+
constructor() {
|
|
110421
|
+
super(...arguments);
|
|
110422
|
+
this.conf = new StaleSubrcConf();
|
|
110423
|
+
}
|
|
110424
|
+
getMetadata() {
|
|
110425
|
+
return {
|
|
110426
|
+
key: "stale_subrc",
|
|
110427
|
+
title: "sy-subrc checked after a method call",
|
|
110428
|
+
shortDescription: `Reports IF, CHECK, ASSERT or CASE on sy-subrc directly after a method call without EXCEPTIONS`,
|
|
110429
|
+
extendedInformation: `A method call without EXCEPTIONS does not set sy-subrc. After the call, sy-subrc holds whatever
|
|
110430
|
+
the last statement inside the method set, so the check depends on the method's implementation
|
|
110431
|
+
and breaks silently when the method changes.
|
|
110432
|
+
|
|
110433
|
+
Check the result of the method instead, eg. a returning parameter or an exception, or move the
|
|
110434
|
+
check directly after the statement that sets sy-subrc.
|
|
110435
|
+
|
|
110436
|
+
Reported: the statement directly before the check is a method call, CALL METHOD, or an
|
|
110437
|
+
assignment with a method call or NEW in its source.
|
|
110438
|
+
|
|
110439
|
+
Not reported: a call with EXCEPTIONS or EXCEPTION-TABLE, an assignment that only calls built-in
|
|
110440
|
+
functions like lines( ), and any other statement before the check, eg. CALL FUNCTION or
|
|
110441
|
+
CREATE OBJECT, a check that is the first statement of a block, or a check after ENDIF.
|
|
110442
|
+
An assignment or CLEAR without a call does not change sy-subrc, so a check after it still
|
|
110443
|
+
reads the statement before it, which is not reported either.
|
|
110444
|
+
See also check_subrc and subrc_after_assign.`,
|
|
110445
|
+
tags: [_irule_1.RuleTag.SingleFile],
|
|
110446
|
+
badExample: `lv_parent = read_parent( ).
|
|
110447
|
+
IF sy-subrc = 0.
|
|
110448
|
+
WRITE lv_parent.
|
|
110449
|
+
ENDIF.`,
|
|
110450
|
+
goodExample: `lv_parent = read_parent( ).
|
|
110451
|
+
IF lv_parent IS NOT INITIAL.
|
|
110452
|
+
WRITE lv_parent.
|
|
110453
|
+
ENDIF.`,
|
|
110454
|
+
};
|
|
110455
|
+
}
|
|
110456
|
+
getConfig() {
|
|
110457
|
+
return this.conf;
|
|
110458
|
+
}
|
|
110459
|
+
setConfig(conf) {
|
|
110460
|
+
this.conf = conf;
|
|
110461
|
+
}
|
|
110462
|
+
runParsed(file) {
|
|
110463
|
+
const issues = [];
|
|
110464
|
+
const statements = file.getStatements();
|
|
110465
|
+
for (let i = 0; i < statements.length; i++) {
|
|
110466
|
+
const statement = statements[i];
|
|
110467
|
+
if (this.isSubrcCheck(statement) === false) {
|
|
110468
|
+
continue;
|
|
110469
|
+
}
|
|
110470
|
+
const previous = this.previousStatement(i, statements);
|
|
110471
|
+
if (previous === undefined || this.isCallWithoutExceptions(previous) === false) {
|
|
110472
|
+
continue;
|
|
110473
|
+
}
|
|
110474
|
+
const message = "sy-subrc checked after a method call without EXCEPTIONS, the call does not set sy-subrc";
|
|
110475
|
+
issues.push(issue_1.Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity));
|
|
110476
|
+
}
|
|
110477
|
+
return issues;
|
|
110478
|
+
}
|
|
110479
|
+
////////////////
|
|
110480
|
+
isSubrcCheck(statement) {
|
|
110481
|
+
const s = statement.get();
|
|
110482
|
+
if (!(s instanceof Statements.If
|
|
110483
|
+
|| s instanceof Statements.Check
|
|
110484
|
+
|| s instanceof Statements.Assert
|
|
110485
|
+
|| s instanceof Statements.Case)) {
|
|
110486
|
+
return false;
|
|
110487
|
+
}
|
|
110488
|
+
return this.readsSubrc(statement);
|
|
110489
|
+
}
|
|
110490
|
+
readsSubrc(statement) {
|
|
110491
|
+
for (const field of statement.findAllExpressions(Expressions.FieldChain)) {
|
|
110492
|
+
if (field.concatTokens().toUpperCase() === "SY-SUBRC") {
|
|
110493
|
+
return true;
|
|
110494
|
+
}
|
|
110495
|
+
}
|
|
110496
|
+
return false;
|
|
110497
|
+
}
|
|
110498
|
+
/** the statement directly before, skipping comments */
|
|
110499
|
+
previousStatement(index, statements) {
|
|
110500
|
+
for (let i = index - 1; i >= 0; i--) {
|
|
110501
|
+
if (statements[i].get() instanceof _statement_1.Comment) {
|
|
110502
|
+
continue;
|
|
110503
|
+
}
|
|
110504
|
+
return statements[i];
|
|
110505
|
+
}
|
|
110506
|
+
return undefined;
|
|
110507
|
+
}
|
|
110508
|
+
/** a standalone method call, or an assignment with a method call or NEW in its source */
|
|
110509
|
+
isCallWithoutExceptions(statement) {
|
|
110510
|
+
const s = statement.get();
|
|
110511
|
+
if (s instanceof Statements.Call) {
|
|
110512
|
+
return this.hasClassicExceptions(statement) === false;
|
|
110513
|
+
}
|
|
110514
|
+
else if (!(s instanceof Statements.Move) || this.hasClassicExceptions(statement) === true) {
|
|
110515
|
+
return false;
|
|
110516
|
+
}
|
|
110517
|
+
if (statement.findFirstExpression(Expressions.NewObject) !== undefined) {
|
|
110518
|
+
return true;
|
|
110519
|
+
}
|
|
110520
|
+
const tokens = statement.getTokens();
|
|
110521
|
+
for (const call of statement.findAllExpressions(Expressions.MethodCall)) {
|
|
110522
|
+
const name = call.getFirstToken();
|
|
110523
|
+
const index = tokens.indexOf(name);
|
|
110524
|
+
const before = index > 0 ? tokens[index - 1].getStr() : "";
|
|
110525
|
+
if (before === "->" || before === "=>" || _builtin_1.BuiltIn.methods[name.getStr().toUpperCase()] === undefined) {
|
|
110526
|
+
return true;
|
|
110527
|
+
}
|
|
110528
|
+
}
|
|
110529
|
+
return false;
|
|
110530
|
+
}
|
|
110531
|
+
hasClassicExceptions(statement) {
|
|
110532
|
+
for (const token of statement.getTokens()) {
|
|
110533
|
+
const str = token.getStr().toUpperCase();
|
|
110534
|
+
if (str === "EXCEPTIONS" || str === "EXCEPTION-TABLE") {
|
|
110535
|
+
return true;
|
|
110536
|
+
}
|
|
110537
|
+
}
|
|
110538
|
+
return false;
|
|
110539
|
+
}
|
|
110540
|
+
}
|
|
110541
|
+
exports.StaleSubrc = StaleSubrc;
|
|
110542
|
+
//# sourceMappingURL=stale_subrc.js.map
|
|
110543
|
+
|
|
110544
|
+
/***/ },
|
|
110545
|
+
|
|
109566
110546
|
/***/ "../core/build/src/rules/start_at_tab.js"
|
|
109567
110547
|
/*!***********************************************!*\
|
|
109568
110548
|
!*** ../core/build/src/rules/start_at_tab.js ***!
|
|
@@ -111578,6 +112558,279 @@ exports.UncaughtException = UncaughtException;
|
|
|
111578
112558
|
|
|
111579
112559
|
/***/ },
|
|
111580
112560
|
|
|
112561
|
+
/***/ "../core/build/src/rules/unit_test_assertions.js"
|
|
112562
|
+
/*!*******************************************************!*\
|
|
112563
|
+
!*** ../core/build/src/rules/unit_test_assertions.js ***!
|
|
112564
|
+
\*******************************************************/
|
|
112565
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
112566
|
+
|
|
112567
|
+
"use strict";
|
|
112568
|
+
|
|
112569
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
112570
|
+
if (k2 === undefined) k2 = k;
|
|
112571
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
112572
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
112573
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
112574
|
+
}
|
|
112575
|
+
Object.defineProperty(o, k2, desc);
|
|
112576
|
+
}) : (function(o, m, k, k2) {
|
|
112577
|
+
if (k2 === undefined) k2 = k;
|
|
112578
|
+
o[k2] = m[k];
|
|
112579
|
+
}));
|
|
112580
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
112581
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
112582
|
+
}) : function(o, v) {
|
|
112583
|
+
o["default"] = v;
|
|
112584
|
+
});
|
|
112585
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
112586
|
+
var ownKeys = function(o) {
|
|
112587
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
112588
|
+
var ar = [];
|
|
112589
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
112590
|
+
return ar;
|
|
112591
|
+
};
|
|
112592
|
+
return ownKeys(o);
|
|
112593
|
+
};
|
|
112594
|
+
return function (mod) {
|
|
112595
|
+
if (mod && mod.__esModule) return mod;
|
|
112596
|
+
var result = {};
|
|
112597
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
112598
|
+
__setModuleDefault(result, mod);
|
|
112599
|
+
return result;
|
|
112600
|
+
};
|
|
112601
|
+
})();
|
|
112602
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
112603
|
+
exports.UnitTestAssertions = exports.UnitTestAssertionsConf = void 0;
|
|
112604
|
+
const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
|
|
112605
|
+
const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
|
|
112606
|
+
const Structures = __importStar(__webpack_require__(/*! ../abap/3_structures/structures */ "../core/build/src/abap/3_structures/structures/index.js"));
|
|
112607
|
+
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
112608
|
+
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
112609
|
+
const _abap_rule_1 = __webpack_require__(/*! ./_abap_rule */ "../core/build/src/rules/_abap_rule.js");
|
|
112610
|
+
const Tokens = __importStar(__webpack_require__(/*! ../abap/1_lexer/tokens */ "../core/build/src/abap/1_lexer/tokens/index.js"));
|
|
112611
|
+
const severity_1 = __webpack_require__(/*! ../severity */ "../core/build/src/severity.js");
|
|
112612
|
+
class UnitTestAssertionsConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
112613
|
+
constructor() {
|
|
112614
|
+
super(...arguments);
|
|
112615
|
+
this.severity = severity_1.Severity.Warning;
|
|
112616
|
+
/** Report assertions that cannot fail: assert_equals or assert_equals_float with the same operand for act and exp,
|
|
112617
|
+
* assert_true with abap_true or 'X', assert_false with abap_false, space or ' ' */
|
|
112618
|
+
this.cannotFail = true;
|
|
112619
|
+
/** Report the ASSERT statement in FOR TESTING classes */
|
|
112620
|
+
this.assertStatement = true;
|
|
112621
|
+
}
|
|
112622
|
+
}
|
|
112623
|
+
exports.UnitTestAssertionsConf = UnitTestAssertionsConf;
|
|
112624
|
+
const ASSERT_CLASSES = ["CL_ABAP_UNIT_ASSERT", "CL_AUNIT_ASSERT"];
|
|
112625
|
+
class UnitTestAssertions extends _abap_rule_1.ABAPRule {
|
|
112626
|
+
constructor() {
|
|
112627
|
+
super(...arguments);
|
|
112628
|
+
this.conf = new UnitTestAssertionsConf();
|
|
112629
|
+
}
|
|
112630
|
+
getMetadata() {
|
|
112631
|
+
return {
|
|
112632
|
+
key: "unit_test_assertions",
|
|
112633
|
+
title: "Unit test assertions",
|
|
112634
|
+
shortDescription: `Reports unit test assertions that cannot fail, and the ASSERT statement in FOR TESTING classes`,
|
|
112635
|
+
extendedInformation: `Only code in FOR TESTING classes is checked. Each check has its own option.
|
|
112636
|
+
|
|
112637
|
+
cannotFail: an assertion of cl_abap_unit_assert or cl_aunit_assert that passes whatever the code under test does.
|
|
112638
|
+
assert_equals and assert_equals_float with the same operand for act and exp, assert_true with abap_true or 'X',
|
|
112639
|
+
assert_false with abap_false, space or ' '. Not reported: operands that contain a method call or NEW, as two calls
|
|
112640
|
+
can return different values; two different literals or constants; assertions that always fail.
|
|
112641
|
+
|
|
112642
|
+
assertStatement: the ASSERT statement. A failing ASSERT ends in the runtime error ASSERTION_FAILED, so the test
|
|
112643
|
+
run shows a short dump instead of a failed test with act, exp and a message. Use cl_abap_unit_assert instead.
|
|
112644
|
+
Not reported: ASSERT in classes that are not FOR TESTING.`,
|
|
112645
|
+
tags: [],
|
|
112646
|
+
badExample: `CLASS ltcl_test DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
112647
|
+
PRIVATE SECTION.
|
|
112648
|
+
DATA mt_rows TYPE string_table.
|
|
112649
|
+
METHODS test FOR TESTING.
|
|
112650
|
+
ENDCLASS.
|
|
112651
|
+
|
|
112652
|
+
CLASS ltcl_test IMPLEMENTATION.
|
|
112653
|
+
METHOD test.
|
|
112654
|
+
DATA(lv_count) = lines( mt_rows ).
|
|
112655
|
+
cl_abap_unit_assert=>assert_equals( act = lv_count exp = lv_count ).
|
|
112656
|
+
cl_abap_unit_assert=>assert_true( abap_true ).
|
|
112657
|
+
ASSERT lv_count = 2.
|
|
112658
|
+
ENDMETHOD.
|
|
112659
|
+
ENDCLASS.`,
|
|
112660
|
+
goodExample: `CLASS ltcl_test DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
112661
|
+
PRIVATE SECTION.
|
|
112662
|
+
DATA mt_rows TYPE string_table.
|
|
112663
|
+
METHODS test FOR TESTING.
|
|
112664
|
+
ENDCLASS.
|
|
112665
|
+
|
|
112666
|
+
CLASS ltcl_test IMPLEMENTATION.
|
|
112667
|
+
METHOD test.
|
|
112668
|
+
DATA(lv_count) = lines( mt_rows ).
|
|
112669
|
+
cl_abap_unit_assert=>assert_equals( act = lv_count exp = 2 ).
|
|
112670
|
+
cl_abap_unit_assert=>assert_true( xsdbool( lv_count > 0 ) ).
|
|
112671
|
+
ENDMETHOD.
|
|
112672
|
+
ENDCLASS.`,
|
|
112673
|
+
};
|
|
112674
|
+
}
|
|
112675
|
+
getConfig() {
|
|
112676
|
+
return this.conf;
|
|
112677
|
+
}
|
|
112678
|
+
setConfig(conf) {
|
|
112679
|
+
this.conf = conf;
|
|
112680
|
+
}
|
|
112681
|
+
runParsed(file, obj) {
|
|
112682
|
+
var _a, _b;
|
|
112683
|
+
const issues = [];
|
|
112684
|
+
const structure = file.getStructure();
|
|
112685
|
+
if (structure === undefined) {
|
|
112686
|
+
return [];
|
|
112687
|
+
}
|
|
112688
|
+
const testClasses = this.testClassNames(obj);
|
|
112689
|
+
if (testClasses.size === 0) {
|
|
112690
|
+
return [];
|
|
112691
|
+
}
|
|
112692
|
+
for (const implementation of structure.findAllStructures(Structures.ClassImplementation)) {
|
|
112693
|
+
const name = (_b = (_a = implementation.findFirstStatement(Statements.ClassImplementation)) === null || _a === void 0 ? void 0 : _a.findFirstExpression(Expressions.ClassName)) === null || _b === void 0 ? void 0 : _b.concatTokens().toUpperCase();
|
|
112694
|
+
if (name === undefined || testClasses.has(name) === false) {
|
|
112695
|
+
continue;
|
|
112696
|
+
}
|
|
112697
|
+
for (const statement of implementation.findAllStatementNodes()) {
|
|
112698
|
+
if (this.conf.assertStatement === true && statement.get() instanceof Statements.Assert) {
|
|
112699
|
+
const message = "Use cl_abap_unit_assert instead of ASSERT in a test class";
|
|
112700
|
+
issues.push(issue_1.Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity));
|
|
112701
|
+
}
|
|
112702
|
+
else if (this.conf.cannotFail === true && statement.get() instanceof Statements.Call) {
|
|
112703
|
+
const message = this.cannotFail(statement);
|
|
112704
|
+
if (message !== undefined) {
|
|
112705
|
+
issues.push(issue_1.Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity));
|
|
112706
|
+
}
|
|
112707
|
+
}
|
|
112708
|
+
}
|
|
112709
|
+
}
|
|
112710
|
+
return issues;
|
|
112711
|
+
}
|
|
112712
|
+
/** names of the FOR TESTING classes defined in any file of the object, upper case */
|
|
112713
|
+
testClassNames(obj) {
|
|
112714
|
+
const ret = new Set();
|
|
112715
|
+
for (const f of obj.getABAPFiles()) {
|
|
112716
|
+
for (const def of f.getInfo().listClassDefinitions()) {
|
|
112717
|
+
if (def.isForTesting === true) {
|
|
112718
|
+
ret.add(def.name.toUpperCase());
|
|
112719
|
+
}
|
|
112720
|
+
}
|
|
112721
|
+
}
|
|
112722
|
+
return ret;
|
|
112723
|
+
}
|
|
112724
|
+
/** returns the message if the call is an assertion that cannot fail */
|
|
112725
|
+
cannotFail(statement) {
|
|
112726
|
+
const call = this.assertCall(statement);
|
|
112727
|
+
if (call === undefined) {
|
|
112728
|
+
return undefined;
|
|
112729
|
+
}
|
|
112730
|
+
if (call.method === "ASSERT_EQUALS" || call.method === "ASSERT_EQUALS_FLOAT") {
|
|
112731
|
+
const act = call.parameters.get("ACT");
|
|
112732
|
+
const exp = call.parameters.get("EXP");
|
|
112733
|
+
if (act === undefined || exp === undefined || this.hasCall(act) || this.hasCall(exp)) {
|
|
112734
|
+
return undefined;
|
|
112735
|
+
}
|
|
112736
|
+
if (this.normalized(act) === this.normalized(exp)) {
|
|
112737
|
+
return "Assertion cannot fail, act and exp are the same";
|
|
112738
|
+
}
|
|
112739
|
+
}
|
|
112740
|
+
else if (call.method === "ASSERT_TRUE" || call.method === "ASSERT_FALSE") {
|
|
112741
|
+
const act = call.parameters.get("ACT");
|
|
112742
|
+
if (act === undefined) {
|
|
112743
|
+
return undefined;
|
|
112744
|
+
}
|
|
112745
|
+
const value = this.normalized(act);
|
|
112746
|
+
if (call.method === "ASSERT_TRUE" && (value === "ABAP_TRUE" || value === "'X'")) {
|
|
112747
|
+
return "Assertion cannot fail, act is abap_true";
|
|
112748
|
+
}
|
|
112749
|
+
else if (call.method === "ASSERT_FALSE"
|
|
112750
|
+
&& (value === "ABAP_FALSE" || value === "SPACE" || value === "''" || value === "' '")) {
|
|
112751
|
+
return "Assertion cannot fail, act is abap_false";
|
|
112752
|
+
}
|
|
112753
|
+
}
|
|
112754
|
+
return undefined;
|
|
112755
|
+
}
|
|
112756
|
+
/** class method call of cl_abap_unit_assert or cl_aunit_assert: method name and the sources by parameter name, upper case */
|
|
112757
|
+
assertCall(statement) {
|
|
112758
|
+
var _a, _b;
|
|
112759
|
+
let className;
|
|
112760
|
+
let methodName;
|
|
112761
|
+
let parameters;
|
|
112762
|
+
const chain = statement.findDirectExpression(Expressions.MethodCallChain);
|
|
112763
|
+
const source = statement.findDirectExpression(Expressions.MethodSource);
|
|
112764
|
+
if (chain !== undefined) {
|
|
112765
|
+
const children = chain.getChildren();
|
|
112766
|
+
const methodCall = chain.findDirectExpression(Expressions.MethodCall);
|
|
112767
|
+
if (children.length !== 3 || methodCall === undefined) {
|
|
112768
|
+
return undefined;
|
|
112769
|
+
}
|
|
112770
|
+
className = chain.findDirectExpression(Expressions.ClassName);
|
|
112771
|
+
methodName = methodCall.findDirectExpression(Expressions.MethodName);
|
|
112772
|
+
parameters = methodCall.findDirectExpression(Expressions.MethodCallParam);
|
|
112773
|
+
}
|
|
112774
|
+
else if (source !== undefined) {
|
|
112775
|
+
const children = source.getChildren();
|
|
112776
|
+
if (children.length !== 3) {
|
|
112777
|
+
return undefined;
|
|
112778
|
+
}
|
|
112779
|
+
className = source.findDirectExpression(Expressions.ClassName);
|
|
112780
|
+
methodName = source.findDirectExpression(Expressions.AttributeName);
|
|
112781
|
+
parameters = statement.findDirectExpression(Expressions.MethodCallBody);
|
|
112782
|
+
}
|
|
112783
|
+
if (className === undefined
|
|
112784
|
+
|| methodName === undefined
|
|
112785
|
+
|| parameters === undefined
|
|
112786
|
+
|| ASSERT_CLASSES.includes(className.concatTokens().toUpperCase()) === false) {
|
|
112787
|
+
return undefined;
|
|
112788
|
+
}
|
|
112789
|
+
// CALL METHOD x( ... ) and the functional call have a MethodCallParam, CALL METHOD x EXPORTING ... has not
|
|
112790
|
+
const param = parameters.get() instanceof Expressions.MethodCallParam
|
|
112791
|
+
? parameters : parameters.findDirectExpression(Expressions.MethodCallParam);
|
|
112792
|
+
const list = (param === null || param === void 0 ? void 0 : param.findDirectExpression(Expressions.ParameterListS))
|
|
112793
|
+
|| ((_a = (param || parameters).findDirectExpression(Expressions.MethodParameters)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.ParameterListS));
|
|
112794
|
+
const map = new Map();
|
|
112795
|
+
const single = param === null || param === void 0 ? void 0 : param.findDirectExpression(Expressions.Source);
|
|
112796
|
+
if (single !== undefined) {
|
|
112797
|
+
// only the preferred parameter is given, for the assertions checked here it is ACT
|
|
112798
|
+
map.set("ACT", single);
|
|
112799
|
+
}
|
|
112800
|
+
for (const parameter of (list === null || list === void 0 ? void 0 : list.findDirectExpressions(Expressions.ParameterS)) || []) {
|
|
112801
|
+
const name = (_b = parameter.findDirectExpression(Expressions.ParameterName)) === null || _b === void 0 ? void 0 : _b.concatTokens().toUpperCase();
|
|
112802
|
+
const value = parameter.findDirectExpression(Expressions.Source);
|
|
112803
|
+
if (name !== undefined && value !== undefined) {
|
|
112804
|
+
map.set(name, value);
|
|
112805
|
+
}
|
|
112806
|
+
}
|
|
112807
|
+
return { method: methodName.concatTokens().toUpperCase(), parameters: map };
|
|
112808
|
+
}
|
|
112809
|
+
/** two evaluations of the source can give different values */
|
|
112810
|
+
hasCall(source) {
|
|
112811
|
+
return source.findFirstExpression(Expressions.MethodCallChain) !== undefined
|
|
112812
|
+
|| source.findFirstExpression(Expressions.MethodCall) !== undefined
|
|
112813
|
+
|| source.findFirstExpression(Expressions.NewObject) !== undefined;
|
|
112814
|
+
}
|
|
112815
|
+
/** the tokens of the source, upper case outside of literals */
|
|
112816
|
+
normalized(source) {
|
|
112817
|
+
return source.getAllTokens().map(token => {
|
|
112818
|
+
if (token instanceof Tokens.StringToken
|
|
112819
|
+
|| token instanceof Tokens.StringTemplate
|
|
112820
|
+
|| token instanceof Tokens.StringTemplateBegin
|
|
112821
|
+
|| token instanceof Tokens.StringTemplateMiddle
|
|
112822
|
+
|| token instanceof Tokens.StringTemplateEnd) {
|
|
112823
|
+
return token.getStr();
|
|
112824
|
+
}
|
|
112825
|
+
return token.getStr().toUpperCase();
|
|
112826
|
+
}).join(" ");
|
|
112827
|
+
}
|
|
112828
|
+
}
|
|
112829
|
+
exports.UnitTestAssertions = UnitTestAssertions;
|
|
112830
|
+
//# sourceMappingURL=unit_test_assertions.js.map
|
|
112831
|
+
|
|
112832
|
+
/***/ },
|
|
112833
|
+
|
|
111581
112834
|
/***/ "../core/build/src/rules/unknown_types.js"
|
|
111582
112835
|
/*!************************************************!*\
|
|
111583
112836
|
!*** ../core/build/src/rules/unknown_types.js ***!
|