@abaplint/cli 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.
Files changed (2) hide show
  1. package/build/cli.js +663 -1
  2. package/package.json +2 -2
package/build/cli.js CHANGED
@@ -34781,6 +34781,11 @@ class Source {
34781
34781
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
34782
34782
  return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
34783
34783
  }
34784
+ if ((foundType === null || foundType === void 0 ? void 0 : foundType.isGeneric()) && bodyType !== undefined) {
34785
+ this.addIfInferred(node, input, bodyType);
34786
+ this.traverseRemainingChildren(children, input);
34787
+ return bodyType;
34788
+ }
34784
34789
  this.addIfInferred(node, input, foundType);
34785
34790
  this.traverseRemainingChildren(children, input);
34786
34791
  return foundType;
@@ -70685,7 +70690,7 @@ class Registry {
70685
70690
  }
70686
70691
  static abaplintVersion() {
70687
70692
  // magic, see build script "version.js"
70688
- return "2.120.57";
70693
+ return "2.120.59";
70689
70694
  }
70690
70695
  getDDICReferences() {
70691
70696
  return this.ddicReferences;
@@ -85081,7 +85086,9 @@ __exportStar(__webpack_require__(/*! ./prefer_insert_into_table */ "../core/buil
85081
85086
  __exportStar(__webpack_require__(/*! ./prefer_is_not */ "../core/build/src/rules/prefer_is_not.js"), exports);
85082
85087
  __exportStar(__webpack_require__(/*! ./prefer_pragmas */ "../core/build/src/rules/prefer_pragmas.js"), exports);
85083
85088
  __exportStar(__webpack_require__(/*! ./prefer_abap_bool */ "../core/build/src/rules/prefer_abap_bool.js"), exports);
85089
+ __exportStar(__webpack_require__(/*! ./prefer_abap_bool_values */ "../core/build/src/rules/prefer_abap_bool_values.js"), exports);
85084
85090
  __exportStar(__webpack_require__(/*! ./prefer_raise_exception_new */ "../core/build/src/rules/prefer_raise_exception_new.js"), exports);
85091
+ __exportStar(__webpack_require__(/*! ./prefer_string_template */ "../core/build/src/rules/prefer_string_template.js"), exports);
85085
85092
  __exportStar(__webpack_require__(/*! ./prefer_returning_to_exporting */ "../core/build/src/rules/prefer_returning_to_exporting.js"), exports);
85086
85093
  __exportStar(__webpack_require__(/*! ./prefer_xsdbool */ "../core/build/src/rules/prefer_xsdbool.js"), exports);
85087
85094
  __exportStar(__webpack_require__(/*! ./preferred_compare_operator */ "../core/build/src/rules/preferred_compare_operator.js"), exports);
@@ -85121,6 +85128,7 @@ __exportStar(__webpack_require__(/*! ./types_naming */ "../core/build/src/rules/
85121
85128
  __exportStar(__webpack_require__(/*! ./uncaught_exception */ "../core/build/src/rules/uncaught_exception.js"), exports);
85122
85129
  __exportStar(__webpack_require__(/*! ./unknown_types */ "../core/build/src/rules/unknown_types.js"), exports);
85123
85130
  __exportStar(__webpack_require__(/*! ./unnecessary_chaining */ "../core/build/src/rules/unnecessary_chaining.js"), exports);
85131
+ __exportStar(__webpack_require__(/*! ./unnecessary_loop_guard */ "../core/build/src/rules/unnecessary_loop_guard.js"), exports);
85124
85132
  __exportStar(__webpack_require__(/*! ./unnecessary_pragma */ "../core/build/src/rules/unnecessary_pragma.js"), exports);
85125
85133
  __exportStar(__webpack_require__(/*! ./unnecessary_return */ "../core/build/src/rules/unnecessary_return.js"), exports);
85126
85134
  __exportStar(__webpack_require__(/*! ./unreachable_code */ "../core/build/src/rules/unreachable_code.js"), exports);
@@ -85133,6 +85141,7 @@ __exportStar(__webpack_require__(/*! ./unused_variables */ "../core/build/src/ru
85133
85141
  __exportStar(__webpack_require__(/*! ./use_bool_expression */ "../core/build/src/rules/use_bool_expression.js"), exports);
85134
85142
  __exportStar(__webpack_require__(/*! ./use_class_based_exceptions */ "../core/build/src/rules/use_class_based_exceptions.js"), exports);
85135
85143
  __exportStar(__webpack_require__(/*! ./use_line_exists */ "../core/build/src/rules/use_line_exists.js"), exports);
85144
+ __exportStar(__webpack_require__(/*! ./use_message_class */ "../core/build/src/rules/use_message_class.js"), exports);
85136
85145
  __exportStar(__webpack_require__(/*! ./use_new */ "../core/build/src/rules/use_new.js"), exports);
85137
85146
  __exportStar(__webpack_require__(/*! ./when_others_last */ "../core/build/src/rules/when_others_last.js"), exports);
85138
85147
  __exportStar(__webpack_require__(/*! ./whitespace_end */ "../core/build/src/rules/whitespace_end.js"), exports);
@@ -92484,6 +92493,272 @@ exports.PreferAbapBool = PreferAbapBool;
92484
92493
 
92485
92494
  /***/ },
92486
92495
 
92496
+ /***/ "../core/build/src/rules/prefer_abap_bool_values.js"
92497
+ /*!**********************************************************!*\
92498
+ !*** ../core/build/src/rules/prefer_abap_bool_values.js ***!
92499
+ \**********************************************************/
92500
+ (__unused_webpack_module, exports, __webpack_require__) {
92501
+
92502
+ "use strict";
92503
+
92504
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
92505
+ if (k2 === undefined) k2 = k;
92506
+ var desc = Object.getOwnPropertyDescriptor(m, k);
92507
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
92508
+ desc = { enumerable: true, get: function() { return m[k]; } };
92509
+ }
92510
+ Object.defineProperty(o, k2, desc);
92511
+ }) : (function(o, m, k, k2) {
92512
+ if (k2 === undefined) k2 = k;
92513
+ o[k2] = m[k];
92514
+ }));
92515
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
92516
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
92517
+ }) : function(o, v) {
92518
+ o["default"] = v;
92519
+ });
92520
+ var __importStar = (this && this.__importStar) || (function () {
92521
+ var ownKeys = function(o) {
92522
+ ownKeys = Object.getOwnPropertyNames || function (o) {
92523
+ var ar = [];
92524
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
92525
+ return ar;
92526
+ };
92527
+ return ownKeys(o);
92528
+ };
92529
+ return function (mod) {
92530
+ if (mod && mod.__esModule) return mod;
92531
+ var result = {};
92532
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
92533
+ __setModuleDefault(result, mod);
92534
+ return result;
92535
+ };
92536
+ })();
92537
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
92538
+ exports.PreferAbapBoolValues = exports.PreferAbapBoolValuesConf = void 0;
92539
+ const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
92540
+ const _abap_rule_1 = __webpack_require__(/*! ./_abap_rule */ "../core/build/src/rules/_abap_rule.js");
92541
+ const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
92542
+ const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
92543
+ const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
92544
+ const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
92545
+ const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
92546
+ const nodes_1 = __webpack_require__(/*! ../abap/nodes */ "../core/build/src/abap/nodes/index.js");
92547
+ const ABAP_BOOL = "ABAP_BOOL";
92548
+ const ABAP_TRUE = "abap_true";
92549
+ const ABAP_FALSE = "abap_false";
92550
+ const VALID_VALUES = new Set(["ABAP_TRUE", "ABAP_FALSE", "ABAP_UNDEFINED"]);
92551
+ class PreferAbapBoolValuesConf extends _basic_rule_config_1.BasicRuleConfig {
92552
+ }
92553
+ exports.PreferAbapBoolValuesConf = PreferAbapBoolValuesConf;
92554
+ class PreferAbapBoolValues extends _abap_rule_1.ABAPRule {
92555
+ constructor() {
92556
+ super(...arguments);
92557
+ this.conf = new PreferAbapBoolValuesConf();
92558
+ }
92559
+ getMetadata() {
92560
+ return {
92561
+ key: "prefer_abap_bool_values",
92562
+ title: "Prefer abap_true and abap_false",
92563
+ shortDescription: `Use abap_true and abap_false instead of 'X' and ' ' for abap_bool variables`,
92564
+ // eslint-disable-next-line max-len
92565
+ extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#use-abap_true-abap_false-and-abap_undefined-for-abap_bool-variables`,
92566
+ tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
92567
+ badExample: `DATA lv_flag TYPE abap_bool.\nlv_flag = 'X'.`,
92568
+ goodExample: `DATA lv_flag TYPE abap_bool.\nlv_flag = abap_true.`,
92569
+ };
92570
+ }
92571
+ getConfig() {
92572
+ return this.conf;
92573
+ }
92574
+ setConfig(conf) {
92575
+ this.conf = conf;
92576
+ }
92577
+ runParsed(file) {
92578
+ const issues = [];
92579
+ const structure = file.getStructure();
92580
+ if (structure === undefined) {
92581
+ return [];
92582
+ }
92583
+ const boolVars = this.collectBoolVars(file);
92584
+ // Check Move statements: target = source
92585
+ for (const stat of structure.findAllStatements(Statements.Move)) {
92586
+ const target = stat.findFirstExpression(Expressions.Target);
92587
+ const source = stat.findFirstExpression(Expressions.Source);
92588
+ if (target === undefined || source === undefined) {
92589
+ continue;
92590
+ }
92591
+ const targetName = target.concatTokens().toUpperCase();
92592
+ if (!boolVars.has(targetName)) {
92593
+ continue;
92594
+ }
92595
+ this.checkSourceNode(source, file, issues);
92596
+ }
92597
+ // Check comparisons: IF/ELSEIF conditions
92598
+ const compareStatements = [
92599
+ ...structure.findAllStatements(Statements.If),
92600
+ ...structure.findAllStatements(Statements.ElseIf),
92601
+ ];
92602
+ for (const stat of compareStatements) {
92603
+ const cond = stat.findFirstExpression(Expressions.Cond);
92604
+ if (cond === undefined) {
92605
+ continue;
92606
+ }
92607
+ for (const compare of cond.findAllExpressions(Expressions.Compare)) {
92608
+ this.checkCompareBoolLiteral(compare, boolVars, file, issues);
92609
+ }
92610
+ }
92611
+ return issues;
92612
+ }
92613
+ collectBoolVars(file) {
92614
+ var _a;
92615
+ const boolVars = new Set();
92616
+ const structure = file.getStructure();
92617
+ if (structure === undefined) {
92618
+ return boolVars;
92619
+ }
92620
+ const statements = [
92621
+ ...structure.findAllStatements(Statements.Data),
92622
+ ...structure.findAllStatements(Statements.ClassData),
92623
+ ...structure.findAllStatements(Statements.FieldSymbol),
92624
+ ];
92625
+ for (const stat of statements) {
92626
+ const typeNameExpr = stat.findFirstExpression(Expressions.TypeName);
92627
+ if (typeNameExpr === undefined) {
92628
+ continue;
92629
+ }
92630
+ if (typeNameExpr.concatTokens().toUpperCase() !== ABAP_BOOL) {
92631
+ continue;
92632
+ }
92633
+ const nameExpr = (_a = stat.findFirstExpression(Expressions.DefinitionName)) !== null && _a !== void 0 ? _a : stat.findFirstExpression(Expressions.FieldSymbol);
92634
+ if (nameExpr === undefined) {
92635
+ continue;
92636
+ }
92637
+ boolVars.add(nameExpr.concatTokens().toUpperCase());
92638
+ }
92639
+ return boolVars;
92640
+ }
92641
+ checkSourceNode(source, file, issues) {
92642
+ const firstToken = source.getFirstToken().getStr().toUpperCase();
92643
+ if (firstToken === "COND") {
92644
+ const condBody = source.findDirectExpression(Expressions.CondBody);
92645
+ if (condBody) {
92646
+ this.checkCondBodyBranches(condBody, file, issues);
92647
+ }
92648
+ return;
92649
+ }
92650
+ if (firstToken === "SWITCH") {
92651
+ const switchBody = source.findDirectExpression(Expressions.SwitchBody);
92652
+ if (switchBody) {
92653
+ this.checkSwitchBodyBranches(switchBody, file, issues);
92654
+ }
92655
+ return;
92656
+ }
92657
+ // Plain literal assignment
92658
+ const issue = this.checkLiteralSource(source, file);
92659
+ if (issue) {
92660
+ issues.push(issue);
92661
+ }
92662
+ }
92663
+ checkLiteralSource(source, file) {
92664
+ const constantStr = source.findFirstExpression(Expressions.ConstantString);
92665
+ if (constantStr === undefined) {
92666
+ return undefined;
92667
+ }
92668
+ const token = constantStr.getFirstToken();
92669
+ const val = token.getStr();
92670
+ if (val === "'X'") {
92671
+ const fix = edit_helper_1.EditHelper.replaceToken(file, token, ABAP_TRUE);
92672
+ return issue_1.Issue.atToken(file, token, `Use ${ABAP_TRUE} instead of 'X'`, this.getMetadata().key, this.conf.severity, fix);
92673
+ }
92674
+ if (val === "' '") {
92675
+ const fix = edit_helper_1.EditHelper.replaceToken(file, token, ABAP_FALSE);
92676
+ return issue_1.Issue.atToken(file, token, `Use ${ABAP_FALSE} instead of ' '`, this.getMetadata().key, this.conf.severity, fix);
92677
+ }
92678
+ return undefined;
92679
+ }
92680
+ checkCondBodyBranches(condBody, file, issues) {
92681
+ // CondBody: WHEN <cond> THEN <source> [WHEN <cond> THEN <source>]* [ELSE <source>]
92682
+ // Walk children; Source nodes after THEN/ELSE are the result values
92683
+ let afterThenOrElse = false;
92684
+ for (const child of condBody.getChildren()) {
92685
+ const tokenStr = child.getFirstToken().getStr().toUpperCase();
92686
+ if (tokenStr === "THEN" || tokenStr === "ELSE") {
92687
+ afterThenOrElse = true;
92688
+ continue;
92689
+ }
92690
+ if (tokenStr === "WHEN") {
92691
+ afterThenOrElse = false;
92692
+ continue;
92693
+ }
92694
+ if (afterThenOrElse && child instanceof nodes_1.ExpressionNode && child.get() instanceof Expressions.Source) {
92695
+ const issue = this.checkLiteralSource(child, file);
92696
+ if (issue) {
92697
+ issues.push(issue);
92698
+ }
92699
+ afterThenOrElse = false;
92700
+ }
92701
+ }
92702
+ }
92703
+ checkSwitchBodyBranches(switchBody, file, issues) {
92704
+ // SwitchBody: <source> WHEN <val> [OR <val>]* THEN <source> [ELSE <source>]
92705
+ // First Source is the operand; Source after THEN/ELSE are result values
92706
+ let firstSourceSeen = false;
92707
+ let afterThenOrElse = false;
92708
+ for (const child of switchBody.getChildren()) {
92709
+ const tokenStr = child.getFirstToken().getStr().toUpperCase();
92710
+ if (tokenStr === "THEN" || tokenStr === "ELSE") {
92711
+ afterThenOrElse = true;
92712
+ continue;
92713
+ }
92714
+ if (tokenStr === "WHEN" || tokenStr === "OR") {
92715
+ afterThenOrElse = false;
92716
+ continue;
92717
+ }
92718
+ if (child instanceof nodes_1.ExpressionNode && child.get() instanceof Expressions.Source) {
92719
+ if (!firstSourceSeen) {
92720
+ firstSourceSeen = true;
92721
+ continue;
92722
+ }
92723
+ if (afterThenOrElse) {
92724
+ const issue = this.checkLiteralSource(child, file);
92725
+ if (issue) {
92726
+ issues.push(issue);
92727
+ }
92728
+ afterThenOrElse = false;
92729
+ }
92730
+ }
92731
+ }
92732
+ }
92733
+ checkCompareBoolLiteral(compare, boolVars, file, issues) {
92734
+ // Compare: Source CompareOperator Source (or other forms)
92735
+ const sources = compare.findDirectExpressions(Expressions.Source);
92736
+ if (sources.length < 2) {
92737
+ return;
92738
+ }
92739
+ const [left, right] = sources;
92740
+ const leftStr = left.concatTokens().toUpperCase();
92741
+ const rightStr = right.concatTokens().toUpperCase();
92742
+ let literalSource;
92743
+ if (boolVars.has(leftStr) && !VALID_VALUES.has(rightStr)) {
92744
+ literalSource = right;
92745
+ }
92746
+ else if (boolVars.has(rightStr) && !VALID_VALUES.has(leftStr)) {
92747
+ literalSource = left;
92748
+ }
92749
+ if (literalSource) {
92750
+ const issue = this.checkLiteralSource(literalSource, file);
92751
+ if (issue) {
92752
+ issues.push(issue);
92753
+ }
92754
+ }
92755
+ }
92756
+ }
92757
+ exports.PreferAbapBoolValues = PreferAbapBoolValues;
92758
+ //# sourceMappingURL=prefer_abap_bool_values.js.map
92759
+
92760
+ /***/ },
92761
+
92487
92762
  /***/ "../core/build/src/rules/prefer_corresponding.js"
92488
92763
  /*!*******************************************************!*\
92489
92764
  !*** ../core/build/src/rules/prefer_corresponding.js ***!
@@ -93473,6 +93748,151 @@ exports.PreferReturningToExporting = PreferReturningToExporting;
93473
93748
 
93474
93749
  /***/ },
93475
93750
 
93751
+ /***/ "../core/build/src/rules/prefer_string_template.js"
93752
+ /*!*********************************************************!*\
93753
+ !*** ../core/build/src/rules/prefer_string_template.js ***!
93754
+ \*********************************************************/
93755
+ (__unused_webpack_module, exports, __webpack_require__) {
93756
+
93757
+ "use strict";
93758
+
93759
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
93760
+ if (k2 === undefined) k2 = k;
93761
+ var desc = Object.getOwnPropertyDescriptor(m, k);
93762
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
93763
+ desc = { enumerable: true, get: function() { return m[k]; } };
93764
+ }
93765
+ Object.defineProperty(o, k2, desc);
93766
+ }) : (function(o, m, k, k2) {
93767
+ if (k2 === undefined) k2 = k;
93768
+ o[k2] = m[k];
93769
+ }));
93770
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
93771
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
93772
+ }) : function(o, v) {
93773
+ o["default"] = v;
93774
+ });
93775
+ var __importStar = (this && this.__importStar) || (function () {
93776
+ var ownKeys = function(o) {
93777
+ ownKeys = Object.getOwnPropertyNames || function (o) {
93778
+ var ar = [];
93779
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
93780
+ return ar;
93781
+ };
93782
+ return ownKeys(o);
93783
+ };
93784
+ return function (mod) {
93785
+ if (mod && mod.__esModule) return mod;
93786
+ var result = {};
93787
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
93788
+ __setModuleDefault(result, mod);
93789
+ return result;
93790
+ };
93791
+ })();
93792
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
93793
+ exports.PreferStringTemplate = exports.PreferStringTemplateConf = void 0;
93794
+ const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
93795
+ const _abap_rule_1 = __webpack_require__(/*! ./_abap_rule */ "../core/build/src/rules/_abap_rule.js");
93796
+ const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
93797
+ const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
93798
+ const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
93799
+ const nodes_1 = __webpack_require__(/*! ../abap/nodes */ "../core/build/src/abap/nodes/index.js");
93800
+ const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
93801
+ class PreferStringTemplateConf extends _basic_rule_config_1.BasicRuleConfig {
93802
+ }
93803
+ exports.PreferStringTemplateConf = PreferStringTemplateConf;
93804
+ class PreferStringTemplate extends _abap_rule_1.ABAPRule {
93805
+ constructor() {
93806
+ super(...arguments);
93807
+ this.conf = new PreferStringTemplateConf();
93808
+ }
93809
+ getMetadata() {
93810
+ return {
93811
+ key: "prefer_string_template",
93812
+ title: "Prefer string template over &&",
93813
+ shortDescription: `Use string templates instead of && to assemble text`,
93814
+ extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#use--to-assemble-text`,
93815
+ tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
93816
+ badExample: `DATA(msg) = \`Hello \` && name && \`!\`.`,
93817
+ goodExample: `DATA(msg) = |Hello { name }!|.`,
93818
+ };
93819
+ }
93820
+ getConfig() {
93821
+ return this.conf;
93822
+ }
93823
+ setConfig(conf) {
93824
+ this.conf = conf;
93825
+ }
93826
+ runParsed(file) {
93827
+ const issues = [];
93828
+ const structure = file.getStructure();
93829
+ if (structure === undefined) {
93830
+ return [];
93831
+ }
93832
+ const allSources = structure.findAllExpressions(Expressions.Source);
93833
+ // collect all Source nodes that appear as the RHS (children[2]) of a && expression
93834
+ const rhsChildren = new Set();
93835
+ for (const source of allSources) {
93836
+ const children = source.getChildren();
93837
+ if (children.length === 3 && children[1].getFirstToken().getStr() === "&&") {
93838
+ rhsChildren.add(children[2]);
93839
+ }
93840
+ }
93841
+ for (const source of allSources) {
93842
+ const children = source.getChildren();
93843
+ if (children.length !== 3) {
93844
+ continue;
93845
+ }
93846
+ if (children[1].getFirstToken().getStr() !== "&&") {
93847
+ continue;
93848
+ }
93849
+ // only process top-level && roots (not nested RHS children)
93850
+ if (rhsChildren.has(source)) {
93851
+ continue;
93852
+ }
93853
+ const operands = this.flattenChain(source);
93854
+ if (!operands.some(op => { const c = op.getFirstToken().getStr()[0]; return c === "'" || c === "`"; })) {
93855
+ continue;
93856
+ }
93857
+ const template = this.buildTemplate(operands);
93858
+ const start = source.getFirstToken().getStart();
93859
+ const end = source.getLastToken().getEnd();
93860
+ const fix = edit_helper_1.EditHelper.replaceRange(file, start, end, template);
93861
+ const token = children[1].getFirstToken();
93862
+ issues.push(issue_1.Issue.atToken(file, token, "Use string template instead of &&", this.getMetadata().key, this.conf.severity, fix));
93863
+ }
93864
+ return issues;
93865
+ }
93866
+ flattenChain(node) {
93867
+ const children = node.getChildren();
93868
+ if (children.length === 3 && children[1].getFirstToken().getStr() === "&&") {
93869
+ return [...this.flattenChain(children[0]), ...this.flattenChain(children[2])];
93870
+ }
93871
+ if (children.length === 1 && children[0] instanceof nodes_1.ExpressionNode) {
93872
+ return this.flattenChain(children[0]);
93873
+ }
93874
+ return [node];
93875
+ }
93876
+ buildTemplate(operands) {
93877
+ let inner = "";
93878
+ for (const op of operands) {
93879
+ const raw = op.getFirstToken().getStr();
93880
+ const firstChar = raw[0];
93881
+ if (firstChar === "'" || firstChar === "`") {
93882
+ inner += raw.slice(1, -1);
93883
+ }
93884
+ else {
93885
+ inner += `{ ${op.concatTokens()} }`;
93886
+ }
93887
+ }
93888
+ return `|${inner}|`;
93889
+ }
93890
+ }
93891
+ exports.PreferStringTemplate = PreferStringTemplate;
93892
+ //# sourceMappingURL=prefer_string_template.js.map
93893
+
93894
+ /***/ },
93895
+
93476
93896
  /***/ "../core/build/src/rules/prefer_xsdbool.js"
93477
93897
  /*!*************************************************!*\
93478
93898
  !*** ../core/build/src/rules/prefer_xsdbool.js ***!
@@ -98458,6 +98878,151 @@ exports.UnnecessaryChaining = UnnecessaryChaining;
98458
98878
 
98459
98879
  /***/ },
98460
98880
 
98881
+ /***/ "../core/build/src/rules/unnecessary_loop_guard.js"
98882
+ /*!*********************************************************!*\
98883
+ !*** ../core/build/src/rules/unnecessary_loop_guard.js ***!
98884
+ \*********************************************************/
98885
+ (__unused_webpack_module, exports, __webpack_require__) {
98886
+
98887
+ "use strict";
98888
+
98889
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
98890
+ if (k2 === undefined) k2 = k;
98891
+ var desc = Object.getOwnPropertyDescriptor(m, k);
98892
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
98893
+ desc = { enumerable: true, get: function() { return m[k]; } };
98894
+ }
98895
+ Object.defineProperty(o, k2, desc);
98896
+ }) : (function(o, m, k, k2) {
98897
+ if (k2 === undefined) k2 = k;
98898
+ o[k2] = m[k];
98899
+ }));
98900
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
98901
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
98902
+ }) : function(o, v) {
98903
+ o["default"] = v;
98904
+ });
98905
+ var __importStar = (this && this.__importStar) || (function () {
98906
+ var ownKeys = function(o) {
98907
+ ownKeys = Object.getOwnPropertyNames || function (o) {
98908
+ var ar = [];
98909
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
98910
+ return ar;
98911
+ };
98912
+ return ownKeys(o);
98913
+ };
98914
+ return function (mod) {
98915
+ if (mod && mod.__esModule) return mod;
98916
+ var result = {};
98917
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
98918
+ __setModuleDefault(result, mod);
98919
+ return result;
98920
+ };
98921
+ })();
98922
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
98923
+ exports.UnnecessaryLoopGuard = exports.UnnecessaryLoopGuardConf = void 0;
98924
+ const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
98925
+ const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
98926
+ const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
98927
+ const Structures = __importStar(__webpack_require__(/*! ../abap/3_structures/structures */ "../core/build/src/abap/3_structures/structures/index.js"));
98928
+ const _abap_rule_1 = __webpack_require__(/*! ./_abap_rule */ "../core/build/src/rules/_abap_rule.js");
98929
+ const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
98930
+ const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
98931
+ const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
98932
+ class UnnecessaryLoopGuardConf extends _basic_rule_config_1.BasicRuleConfig {
98933
+ }
98934
+ exports.UnnecessaryLoopGuardConf = UnnecessaryLoopGuardConf;
98935
+ class UnnecessaryLoopGuard extends _abap_rule_1.ABAPRule {
98936
+ constructor() {
98937
+ super(...arguments);
98938
+ this.conf = new UnnecessaryLoopGuardConf();
98939
+ }
98940
+ getMetadata() {
98941
+ return {
98942
+ key: "unnecessary_loop_guard",
98943
+ title: "Unnecessary loop guard",
98944
+ shortDescription: `Detects unnecessary IS [NOT] INITIAL check before LOOP AT`,
98945
+ extendedInformation: `LOOP AT iterates zero times on an empty table, so an IS [NOT] INITIAL guard is redundant.`,
98946
+ tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Styleguide, _irule_1.RuleTag.Quickfix],
98947
+ badExample: `IF lt_data IS NOT INITIAL.
98948
+ LOOP AT lt_data INTO DATA(ls_item).
98949
+ WRITE ls_item-name.
98950
+ ENDLOOP.
98951
+ ENDIF.`,
98952
+ goodExample: `LOOP AT lt_data INTO DATA(ls_item).
98953
+ WRITE ls_item-name.
98954
+ ENDLOOP.`,
98955
+ };
98956
+ }
98957
+ getConfig() {
98958
+ return this.conf;
98959
+ }
98960
+ setConfig(conf) {
98961
+ this.conf = conf;
98962
+ }
98963
+ runParsed(file) {
98964
+ const issues = [];
98965
+ const stru = file.getStructure();
98966
+ if (stru === undefined) {
98967
+ return issues;
98968
+ }
98969
+ for (const ifStru of stru.findAllStructuresRecursive(Structures.If)) {
98970
+ if (ifStru.findDirectStructures(Structures.ElseIf).length > 0
98971
+ || ifStru.findDirectStructures(Structures.Else).length > 0) {
98972
+ continue;
98973
+ }
98974
+ const ifStatement = ifStru.findDirectStatement(Statements.If);
98975
+ if (ifStatement === undefined) {
98976
+ continue;
98977
+ }
98978
+ const cond = ifStatement.findDirectExpression(Expressions.Cond);
98979
+ if (cond === undefined) {
98980
+ continue;
98981
+ }
98982
+ const compareNodes = cond.findDirectExpressions(Expressions.Compare);
98983
+ if (compareNodes.length !== 1) {
98984
+ continue;
98985
+ }
98986
+ const m = compareNodes[0].concatTokens().toUpperCase().match(/^(.+?)\s+IS\s+(?:NOT\s+)?INITIAL\s*$/);
98987
+ if (!m) {
98988
+ continue;
98989
+ }
98990
+ const tableName = m[1];
98991
+ const bodyStructures = ifStru.findDirectStructures(Structures.Body);
98992
+ if (bodyStructures.length !== 1) {
98993
+ continue;
98994
+ }
98995
+ const normalStructures = bodyStructures[0].findDirectStructures(Structures.Normal);
98996
+ if (normalStructures.length !== 1) {
98997
+ continue;
98998
+ }
98999
+ const loopStructures = normalStructures[0].findDirectStructures(Structures.Loop);
99000
+ if (loopStructures.length !== 1) {
99001
+ continue;
99002
+ }
99003
+ const loopStatement = loopStructures[0].findDirectStatement(Statements.Loop);
99004
+ if (loopStatement === undefined) {
99005
+ continue;
99006
+ }
99007
+ const loopSource = loopStatement.findFirstExpression(Expressions.LoopSource);
99008
+ if (loopSource === undefined) {
99009
+ continue;
99010
+ }
99011
+ if (loopSource.concatTokens().toUpperCase() !== tableName) {
99012
+ continue;
99013
+ }
99014
+ const endifStatement = ifStru.findDirectStatement(Statements.EndIf);
99015
+ const fix = edit_helper_1.EditHelper.merge(edit_helper_1.EditHelper.deleteStatement(file, ifStatement), edit_helper_1.EditHelper.deleteStatement(file, endifStatement));
99016
+ issues.push(issue_1.Issue.atStatement(file, ifStatement, "Unnecessary IS [NOT] INITIAL check before LOOP AT", this.getMetadata().key, this.conf.severity, fix));
99017
+ }
99018
+ return issues;
99019
+ }
99020
+ }
99021
+ exports.UnnecessaryLoopGuard = UnnecessaryLoopGuard;
99022
+ //# sourceMappingURL=unnecessary_loop_guard.js.map
99023
+
99024
+ /***/ },
99025
+
98461
99026
  /***/ "../core/build/src/rules/unnecessary_pragma.js"
98462
99027
  /*!*****************************************************!*\
98463
99028
  !*** ../core/build/src/rules/unnecessary_pragma.js ***!
@@ -100532,6 +101097,103 @@ exports.UseLineExists = UseLineExists;
100532
101097
 
100533
101098
  /***/ },
100534
101099
 
101100
+ /***/ "../core/build/src/rules/use_message_class.js"
101101
+ /*!****************************************************!*\
101102
+ !*** ../core/build/src/rules/use_message_class.js ***!
101103
+ \****************************************************/
101104
+ (__unused_webpack_module, exports, __webpack_require__) {
101105
+
101106
+ "use strict";
101107
+
101108
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
101109
+ if (k2 === undefined) k2 = k;
101110
+ var desc = Object.getOwnPropertyDescriptor(m, k);
101111
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
101112
+ desc = { enumerable: true, get: function() { return m[k]; } };
101113
+ }
101114
+ Object.defineProperty(o, k2, desc);
101115
+ }) : (function(o, m, k, k2) {
101116
+ if (k2 === undefined) k2 = k;
101117
+ o[k2] = m[k];
101118
+ }));
101119
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
101120
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
101121
+ }) : function(o, v) {
101122
+ o["default"] = v;
101123
+ });
101124
+ var __importStar = (this && this.__importStar) || (function () {
101125
+ var ownKeys = function(o) {
101126
+ ownKeys = Object.getOwnPropertyNames || function (o) {
101127
+ var ar = [];
101128
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
101129
+ return ar;
101130
+ };
101131
+ return ownKeys(o);
101132
+ };
101133
+ return function (mod) {
101134
+ if (mod && mod.__esModule) return mod;
101135
+ var result = {};
101136
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
101137
+ __setModuleDefault(result, mod);
101138
+ return result;
101139
+ };
101140
+ })();
101141
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
101142
+ exports.UseMessageClass = exports.UseMessageClassConf = void 0;
101143
+ const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
101144
+ const _abap_rule_1 = __webpack_require__(/*! ./_abap_rule */ "../core/build/src/rules/_abap_rule.js");
101145
+ const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
101146
+ const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
101147
+ const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
101148
+ const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
101149
+ class UseMessageClassConf extends _basic_rule_config_1.BasicRuleConfig {
101150
+ }
101151
+ exports.UseMessageClassConf = UseMessageClassConf;
101152
+ class UseMessageClass extends _abap_rule_1.ABAPRule {
101153
+ constructor() {
101154
+ super(...arguments);
101155
+ this.conf = new UseMessageClassConf();
101156
+ }
101157
+ getMetadata() {
101158
+ return {
101159
+ key: "use_message_class",
101160
+ title: "Use message class",
101161
+ shortDescription: `Define messages in SE91 instead of using inline text or variables`,
101162
+ tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile],
101163
+ badExample: `MESSAGE 'Something went wrong' TYPE 'E'.`,
101164
+ goodExample: `MESSAGE e001(bc_msg).`,
101165
+ };
101166
+ }
101167
+ getConfig() {
101168
+ return this.conf;
101169
+ }
101170
+ setConfig(conf) {
101171
+ this.conf = conf;
101172
+ }
101173
+ runParsed(file, _obj) {
101174
+ const structure = file.getStructure();
101175
+ if (structure === undefined) {
101176
+ return [];
101177
+ }
101178
+ const issues = [];
101179
+ const key = this.getMetadata().key;
101180
+ for (const statement of structure.findAllStatements(Statements.Message)) {
101181
+ // The parser populates MessageSource only for the class-based forms (e001(bc_msg) or ID/TYPE/NUMBER).
101182
+ // The text form (MESSAGE <source> TYPE <source>) uses MessageSourceSource directly with no MessageSource child.
101183
+ // Absence of MessageSource is therefore a reliable discriminator between the two forms.
101184
+ if (statement.findDirectExpression(Expressions.MessageSource) !== undefined) {
101185
+ continue;
101186
+ }
101187
+ issues.push(issue_1.Issue.atStatement(file, statement, "Use a message class (SE91) instead of inline text or variable", key, this.conf.severity));
101188
+ }
101189
+ return issues;
101190
+ }
101191
+ }
101192
+ exports.UseMessageClass = UseMessageClass;
101193
+ //# sourceMappingURL=use_message_class.js.map
101194
+
101195
+ /***/ },
101196
+
100535
101197
  /***/ "../core/build/src/rules/use_new.js"
100536
101198
  /*!******************************************!*\
100537
101199
  !*** ../core/build/src/rules/use_new.js ***!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/cli",
3
- "version": "2.120.57",
3
+ "version": "2.120.59",
4
4
  "description": "abaplint - Command Line Interface",
5
5
  "funding": "https://github.com/sponsors/larshp",
6
6
  "bin": {
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "homepage": "https://abaplint.org",
41
41
  "devDependencies": {
42
- "@abaplint/core": "^2.120.57",
42
+ "@abaplint/core": "^2.120.59",
43
43
  "@types/chai": "^4.3.20",
44
44
  "@types/minimist": "^1.2.5",
45
45
  "@types/mocha": "^10.0.10",