@abaplint/cli 2.120.76 → 2.120.78

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 +452 -14
  2. package/package.json +2 -2
package/build/cli.js CHANGED
@@ -35478,7 +35478,7 @@ const version_1 = __webpack_require__(/*! ../../../version */ "../core/build/src
35478
35478
  // TODO: refactor all these method parameters to objects, this is getting messy
35479
35479
  class Source {
35480
35480
  static runSyntax(node, input, targetType, writeReference = false, allowGenericDeference = false, readReference = true) {
35481
- var _a, _b, _c, _d;
35481
+ var _a, _b;
35482
35482
  if (node === undefined) {
35483
35483
  return undefined;
35484
35484
  }
@@ -35573,13 +35573,7 @@ class Source {
35573
35573
  this.traverseRemainingChildren(children, input);
35574
35574
  return bodyType;
35575
35575
  }
35576
- const bodySource = (_b = node.findDirectExpression(Expressions.ConvBody)) === null || _b === void 0 ? void 0 : _b.findDirectExpression(Expressions.Source);
35577
- const nestedType = (_c = bodySource === null || bodySource === void 0 ? void 0 : bodySource.findDirectExpression(Expressions.TypeNameOrInfer)) === null || _c === void 0 ? void 0 : _c.concatTokens();
35578
- // CONV # passes its target type into a nested inferred constructor, so
35579
- // showing both inferred types would produce duplicate inlay hints.
35580
- if (!(inferred === "#" && nestedType === "#")) {
35581
- this.addIfInferred(node, input, foundType);
35582
- }
35576
+ this.addIfInferred(node, input, foundType);
35583
35577
  this.traverseRemainingChildren(children, input);
35584
35578
  return foundType;
35585
35579
  }
@@ -35637,7 +35631,7 @@ class Source {
35637
35631
  {
35638
35632
  const foundType = this.determineType(node, input, targetType);
35639
35633
  if ((foundType === null || foundType === void 0 ? void 0 : foundType.isGeneric()) === true
35640
- && ((_d = node.findDirectExpression(Expressions.TypeNameOrInfer)) === null || _d === void 0 ? void 0 : _d.concatTokens()) === "#"
35634
+ && ((_b = node.findDirectExpression(Expressions.TypeNameOrInfer)) === null || _b === void 0 ? void 0 : _b.concatTokens()) === "#"
35641
35635
  && !(0, version_1.releaseAtLeast)(input.scope.getRelease(), version_1.Release.v756)
35642
35636
  && input.scope.getLanguageVersion() !== version_1.LanguageVersion.Cloud
35643
35637
  && !input.scope.getOpenABAP()) {
@@ -71379,7 +71373,7 @@ class Registry {
71379
71373
  }
71380
71374
  static abaplintVersion() {
71381
71375
  // magic, see build script "version.js"
71382
- return "2.120.76";
71376
+ return "2.120.78";
71383
71377
  }
71384
71378
  getDDICReferences() {
71385
71379
  return this.ddicReferences;
@@ -87128,6 +87122,7 @@ __exportStar(__webpack_require__(/*! ./inline_data_old_versions */ "../core/buil
87128
87122
  __exportStar(__webpack_require__(/*! ./inline_packed_computation */ "../core/build/src/rules/inline_packed_computation.js"), exports);
87129
87123
  __exportStar(__webpack_require__(/*! ./intf_referencing_clas */ "../core/build/src/rules/intf_referencing_clas.js"), exports);
87130
87124
  __exportStar(__webpack_require__(/*! ./invalid_table_index */ "../core/build/src/rules/invalid_table_index.js"), exports);
87125
+ __exportStar(__webpack_require__(/*! ./is_assigned_in_loop */ "../core/build/src/rules/is_assigned_in_loop.js"), exports);
87131
87126
  __exportStar(__webpack_require__(/*! ./keep_single_parameter_on_one_line */ "../core/build/src/rules/keep_single_parameter_on_one_line.js"), exports);
87132
87127
  __exportStar(__webpack_require__(/*! ./keyword_case */ "../core/build/src/rules/keyword_case.js"), exports);
87133
87128
  __exportStar(__webpack_require__(/*! ./line_break_multiple_parameters */ "../core/build/src/rules/line_break_multiple_parameters.js"), exports);
@@ -87193,6 +87188,7 @@ __exportStar(__webpack_require__(/*! ./prefix_is_current_class */ "../core/build
87193
87188
  __exportStar(__webpack_require__(/*! ./range_row_values */ "../core/build/src/rules/range_row_values.js"), exports);
87194
87189
  __exportStar(__webpack_require__(/*! ./reduce_procedural_code */ "../core/build/src/rules/reduce_procedural_code.js"), exports);
87195
87190
  __exportStar(__webpack_require__(/*! ./reduce_string_templates */ "../core/build/src/rules/reduce_string_templates.js"), exports);
87191
+ __exportStar(__webpack_require__(/*! ./redundant_cast */ "../core/build/src/rules/redundant_cast.js"), exports);
87196
87192
  __exportStar(__webpack_require__(/*! ./redundant_conversion */ "../core/build/src/rules/redundant_conversion.js"), exports);
87197
87193
  __exportStar(__webpack_require__(/*! ./release_idoc */ "../core/build/src/rules/release_idoc.js"), exports);
87198
87194
  __exportStar(__webpack_require__(/*! ./remove_descriptions */ "../core/build/src/rules/remove_descriptions.js"), exports);
@@ -87877,6 +87873,258 @@ exports.InvalidTableIndex = InvalidTableIndex;
87877
87873
 
87878
87874
  /***/ },
87879
87875
 
87876
+ /***/ "../core/build/src/rules/is_assigned_in_loop.js"
87877
+ /*!******************************************************!*\
87878
+ !*** ../core/build/src/rules/is_assigned_in_loop.js ***!
87879
+ \******************************************************/
87880
+ (__unused_webpack_module, exports, __webpack_require__) {
87881
+
87882
+ "use strict";
87883
+
87884
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
87885
+ if (k2 === undefined) k2 = k;
87886
+ var desc = Object.getOwnPropertyDescriptor(m, k);
87887
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
87888
+ desc = { enumerable: true, get: function() { return m[k]; } };
87889
+ }
87890
+ Object.defineProperty(o, k2, desc);
87891
+ }) : (function(o, m, k, k2) {
87892
+ if (k2 === undefined) k2 = k;
87893
+ o[k2] = m[k];
87894
+ }));
87895
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
87896
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
87897
+ }) : function(o, v) {
87898
+ o["default"] = v;
87899
+ });
87900
+ var __importStar = (this && this.__importStar) || (function () {
87901
+ var ownKeys = function(o) {
87902
+ ownKeys = Object.getOwnPropertyNames || function (o) {
87903
+ var ar = [];
87904
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
87905
+ return ar;
87906
+ };
87907
+ return ownKeys(o);
87908
+ };
87909
+ return function (mod) {
87910
+ if (mod && mod.__esModule) return mod;
87911
+ var result = {};
87912
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
87913
+ __setModuleDefault(result, mod);
87914
+ return result;
87915
+ };
87916
+ })();
87917
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
87918
+ exports.IsAssignedInLoop = exports.IsAssignedInLoopConf = void 0;
87919
+ const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
87920
+ const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
87921
+ const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
87922
+ const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
87923
+ const _abap_rule_1 = __webpack_require__(/*! ./_abap_rule */ "../core/build/src/rules/_abap_rule.js");
87924
+ const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
87925
+ const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
87926
+ const severity_1 = __webpack_require__(/*! ../severity */ "../core/build/src/severity.js");
87927
+ class IsAssignedInLoopConf extends _basic_rule_config_1.BasicRuleConfig {
87928
+ constructor() {
87929
+ super(...arguments);
87930
+ this.severity = severity_1.Severity.Warning;
87931
+ }
87932
+ }
87933
+ exports.IsAssignedInLoopConf = IsAssignedInLoopConf;
87934
+ class IsAssignedInLoop extends _abap_rule_1.ABAPRule {
87935
+ constructor() {
87936
+ super(...arguments);
87937
+ this.conf = new IsAssignedInLoopConf();
87938
+ }
87939
+ getMetadata() {
87940
+ return {
87941
+ key: "is_assigned_in_loop",
87942
+ title: "IS ASSIGNED after READ TABLE or ASSIGN in a loop",
87943
+ shortDescription: `Reports IS [NOT] ASSIGNED after a READ TABLE ... ASSIGNING or ASSIGN inside a loop, without UNASSIGN before it`,
87944
+ extendedInformation: `A failed READ TABLE ... ASSIGNING or ASSIGN keeps the previous binding of the field symbol. Inside a
87945
+ loop, the field symbol still points to the row of an earlier iteration, so IS ASSIGNED is true
87946
+ although the statement failed, and the code goes on with the wrong row.
87947
+
87948
+ Add UNASSIGN <fs> before the statement, inside the loop, or check sy-subrc after a READ TABLE.
87949
+ The quick fix inserts the UNASSIGN; it is not offered for a field symbol declared inline in
87950
+ the statement, or for a chained statement.
87951
+
87952
+ Not reported: a check that also reads sy-subrc, an ASSIGN that cannot fail (a static source
87953
+ without dereference, table expression or dynamic part), and loops outside of the
87954
+ method, form or function module of the statement. See also subrc_after_assign.`,
87955
+ tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
87956
+ badExample: `LOOP AT lt_cells INTO ls_cell.
87957
+ READ TABLE lt_styles ASSIGNING <style> WITH KEY id = ls_cell-style.
87958
+ IF <style> IS ASSIGNED.
87959
+ ls_cell-format = <style>-format.
87960
+ ENDIF.
87961
+ ENDLOOP.`,
87962
+ goodExample: `LOOP AT lt_cells INTO ls_cell.
87963
+ UNASSIGN <style>.
87964
+ READ TABLE lt_styles ASSIGNING <style> WITH KEY id = ls_cell-style.
87965
+ IF <style> IS ASSIGNED.
87966
+ ls_cell-format = <style>-format.
87967
+ ENDIF.
87968
+ ENDLOOP.`,
87969
+ };
87970
+ }
87971
+ getConfig() {
87972
+ return this.conf;
87973
+ }
87974
+ setConfig(conf) {
87975
+ this.conf = conf;
87976
+ }
87977
+ runParsed(file) {
87978
+ const issues = [];
87979
+ const statements = file.getStatements();
87980
+ for (let i = 0; i < statements.length; i++) {
87981
+ const statement = statements[i];
87982
+ const name = this.boundByFailable(statement);
87983
+ if (name === undefined) {
87984
+ continue;
87985
+ }
87986
+ const fs = name.toUpperCase();
87987
+ const loop = this.innermostLoop(i, statements);
87988
+ if (loop === undefined || this.unassignedBefore(loop, i, statements, fs) === true) {
87989
+ continue;
87990
+ }
87991
+ const check = this.nextCheck(i, statements, fs);
87992
+ if (check === undefined) {
87993
+ continue;
87994
+ }
87995
+ const read = statement.get() instanceof Statements.ReadTable;
87996
+ const message = `${read ? "READ TABLE" : "ASSIGN"} in a loop keeps the previous binding of ${name} when it fails, `
87997
+ + `UNASSIGN ${name} before it` + (read ? " or check sy-subrc" : "");
87998
+ const fix = this.buildFix(file, statement, name);
87999
+ issues.push(issue_1.Issue.atStatement(file, check, message, this.getMetadata().key, this.conf.severity, fix));
88000
+ }
88001
+ return issues;
88002
+ }
88003
+ ////////////////
88004
+ /** the field symbol bound by a READ TABLE ... ASSIGNING or an ASSIGN that can fail */
88005
+ boundByFailable(statement) {
88006
+ var _a, _b, _c;
88007
+ const s = statement.get();
88008
+ if (s instanceof Statements.ReadTable) {
88009
+ const target = (_a = statement.findDirectExpression(Expressions.ReadTableTarget)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.FSTarget);
88010
+ return (_b = target === null || target === void 0 ? void 0 : target.findFirstExpression(Expressions.FieldSymbol)) === null || _b === void 0 ? void 0 : _b.concatTokens();
88011
+ }
88012
+ else if (s instanceof Statements.Assign) {
88013
+ const source = statement.findDirectExpression(Expressions.AssignSource);
88014
+ if (source === undefined) {
88015
+ return undefined;
88016
+ }
88017
+ const first = source.getFirstToken().getStr().toUpperCase();
88018
+ const failable = first === "COMPONENT"
88019
+ || first === "TABLE"
88020
+ || source.findFirstExpression(Expressions.Dynamic) !== undefined
88021
+ || source.findFirstExpression(Expressions.Dereference) !== undefined
88022
+ || source.findFirstExpression(Expressions.TableExpression) !== undefined
88023
+ || statement.findDirectTokenByText("INCREMENT") !== undefined;
88024
+ if (failable === false) {
88025
+ return undefined;
88026
+ }
88027
+ const target = statement.findDirectExpression(Expressions.FSTarget);
88028
+ return (_c = target === null || target === void 0 ? void 0 : target.findFirstExpression(Expressions.FieldSymbol)) === null || _c === void 0 ? void 0 : _c.concatTokens();
88029
+ }
88030
+ return undefined;
88031
+ }
88032
+ /** index of the innermost LOOP, DO, WHILE or SELECT loop around the statement, in the same block */
88033
+ innermostLoop(index, statements) {
88034
+ let depth = 0;
88035
+ for (let i = index - 1; i >= 0 && this.startsBlock(statements[i]) === false; i--) {
88036
+ if (this.endsLoop(statements[i])) {
88037
+ depth++;
88038
+ }
88039
+ else if (this.startsLoop(statements[i])) {
88040
+ if (depth === 0) {
88041
+ return i;
88042
+ }
88043
+ depth--;
88044
+ }
88045
+ }
88046
+ return undefined;
88047
+ }
88048
+ unassignedBefore(loop, index, statements, fs) {
88049
+ for (let i = loop + 1; i < index; i++) {
88050
+ if (statements[i].get() instanceof Statements.Unassign && this.mentions(statements[i], fs)) {
88051
+ return true;
88052
+ }
88053
+ }
88054
+ return false;
88055
+ }
88056
+ /** the first IS [NOT] ASSIGNED of the field symbol after the statement, before the end of the loop
88057
+ * or another UNASSIGN or binding of it; a check that also reads sy-subrc is fine */
88058
+ nextCheck(index, statements, fs) {
88059
+ let depth = 0;
88060
+ for (let i = index + 1; i < statements.length && this.startsBlock(statements[i]) === false; i++) {
88061
+ const statement = statements[i];
88062
+ if (this.startsLoop(statement)) {
88063
+ depth++;
88064
+ }
88065
+ else if (this.endsLoop(statement)) {
88066
+ if (depth === 0) {
88067
+ return undefined;
88068
+ }
88069
+ depth--;
88070
+ }
88071
+ const concat = statement.concatTokens().toUpperCase();
88072
+ if (concat.includes(fs + " IS ASSIGNED") || concat.includes(fs + " IS NOT ASSIGNED")) {
88073
+ return concat.includes("SY-SUBRC") ? undefined : statement;
88074
+ }
88075
+ if ((statement.get() instanceof Statements.Unassign && this.mentions(statement, fs))
88076
+ || this.binds(statement, fs)) {
88077
+ return undefined;
88078
+ }
88079
+ }
88080
+ return undefined;
88081
+ }
88082
+ mentions(statement, fs) {
88083
+ return statement.findAllExpressions(Expressions.FieldSymbol).some(e => e.concatTokens().toUpperCase() === fs);
88084
+ }
88085
+ binds(statement, fs) {
88086
+ return statement.findAllExpressions(Expressions.FSTarget)
88087
+ .some(t => { var _a; return ((_a = t.findFirstExpression(Expressions.FieldSymbol)) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase()) === fs; });
88088
+ }
88089
+ startsLoop(statement) {
88090
+ const s = statement.get();
88091
+ return s instanceof Statements.Loop
88092
+ || s instanceof Statements.Do
88093
+ || s instanceof Statements.While
88094
+ || s instanceof Statements.SelectLoop;
88095
+ }
88096
+ endsLoop(statement) {
88097
+ const s = statement.get();
88098
+ return s instanceof Statements.EndLoop
88099
+ || s instanceof Statements.EndDo
88100
+ || s instanceof Statements.EndWhile
88101
+ || s instanceof Statements.EndSelect;
88102
+ }
88103
+ startsBlock(statement) {
88104
+ const s = statement.get();
88105
+ return s instanceof Statements.MethodImplementation
88106
+ || s instanceof Statements.Form
88107
+ || s instanceof Statements.FunctionModule
88108
+ || s instanceof Statements.Module
88109
+ || s instanceof Statements.EndMethod
88110
+ || s instanceof Statements.EndForm
88111
+ || s instanceof Statements.EndFunction
88112
+ || s instanceof Statements.EndModule;
88113
+ }
88114
+ /** UNASSIGN on a line of its own before the statement, with the same indentation */
88115
+ buildFix(file, statement, name) {
88116
+ if (statement.getColon() !== undefined || statement.findFirstExpression(Expressions.InlineFS) !== undefined) {
88117
+ return undefined;
88118
+ }
88119
+ const start = statement.getStart();
88120
+ return edit_helper_1.EditHelper.insertAt(file, start, `UNASSIGN ${name}.\n` + " ".repeat(start.getCol() - 1));
88121
+ }
88122
+ }
88123
+ exports.IsAssignedInLoop = IsAssignedInLoop;
88124
+ //# sourceMappingURL=is_assigned_in_loop.js.map
88125
+
88126
+ /***/ },
88127
+
87880
88128
  /***/ "../core/build/src/rules/keep_single_parameter_on_one_line.js"
87881
88129
  /*!********************************************************************!*\
87882
88130
  !*** ../core/build/src/rules/keep_single_parameter_on_one_line.js ***!
@@ -89576,7 +89824,11 @@ ENDIF.
89576
89824
  && lastChildren[1].getChildren().length === 1
89577
89825
  && lastChildren[1].getFirstToken().getStr().startsWith("-") === false
89578
89826
  && lastChildren[2].getFirstToken().getStr() === ")") {
89579
- const issue = issue_1.Issue.atToken(file, lastChildren[0].getFirstToken(), "Too many parentheses", this.getMetadata().key, this.conf.severity);
89827
+ const fixText = lastChildren[1].concatTokens();
89828
+ const start = lastChildren[0].getFirstToken().getStart();
89829
+ const end = lastChildren[2].getLastToken().getEnd();
89830
+ const fix = edit_helper_1.EditHelper.replaceRange(file, start, end, fixText);
89831
+ const issue = issue_1.Issue.atToken(file, lastChildren[0].getFirstToken(), "Too many parentheses", this.getMetadata().key, this.conf.severity, fix);
89580
89832
  issues.push(issue);
89581
89833
  }
89582
89834
  }
@@ -91168,6 +91420,8 @@ const _abap_rule_1 = __webpack_require__(/*! ./_abap_rule */ "../core/build/src/
91168
91420
  const sequential_blank_1 = __webpack_require__(/*! ./sequential_blank */ "../core/build/src/rules/sequential_blank.js");
91169
91421
  const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
91170
91422
  const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
91423
+ const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
91424
+ const position_1 = __webpack_require__(/*! ../position */ "../core/build/src/position.js");
91171
91425
  var NewlineLogic;
91172
91426
  (function (NewlineLogic) {
91173
91427
  NewlineLogic["Exact"] = "exact";
@@ -91197,7 +91451,7 @@ class NewlineBetweenMethods extends _abap_rule_1.ABAPRule {
91197
91451
  key: "newline_between_methods",
91198
91452
  title: "New line between methods",
91199
91453
  shortDescription: `Checks for newlines between method implementations.`,
91200
- tags: [_irule_1.RuleTag.Whitespace, _irule_1.RuleTag.SingleFile],
91454
+ tags: [_irule_1.RuleTag.Whitespace, _irule_1.RuleTag.Quickfix, _irule_1.RuleTag.SingleFile],
91201
91455
  };
91202
91456
  }
91203
91457
  getMessage() {
@@ -91226,18 +91480,35 @@ class NewlineBetweenMethods extends _abap_rule_1.ABAPRule {
91226
91480
  continue;
91227
91481
  }
91228
91482
  let counter = 0;
91229
- while (sequential_blank_1.SequentialBlank.isBlankOrWhitespace(rows[nextRow]) && (counter <= this.conf.count + 1)) {
91483
+ while (sequential_blank_1.SequentialBlank.isBlankOrWhitespace(rows[nextRow])) {
91230
91484
  counter++;
91231
91485
  nextRow++;
91232
91486
  }
91233
91487
  if ((counter !== this.conf.count && this.conf.logic === NewlineLogic.Exact)
91234
91488
  || (counter >= this.conf.count && this.conf.logic === NewlineLogic.Less)
91235
91489
  || counter === 0) {
91236
- issues.push(issue_1.Issue.atStatement(file, statement, this.getMessage(), this.getMetadata().key, this.conf.severity));
91490
+ const fix = this.buildFix(file, rows, statement.getStart().getRow(), counter);
91491
+ issues.push(issue_1.Issue.atStatement(file, statement, this.getMessage(), this.getMetadata().key, this.conf.severity, fix));
91237
91492
  }
91238
91493
  }
91239
91494
  return issues;
91240
91495
  }
91496
+ buildFix(file, rows, row, blanks) {
91497
+ let target = this.conf.count;
91498
+ if (this.conf.logic === NewlineLogic.Less) {
91499
+ target = blanks === 0 ? 1 : this.conf.count - 1;
91500
+ }
91501
+ if (blanks < target) {
91502
+ const end = new position_1.Position(row, rows[row - 1].length + 1);
91503
+ return edit_helper_1.EditHelper.insertAt(file, end, "\n".repeat(target - blanks));
91504
+ }
91505
+ else if (blanks > target) {
91506
+ const start = new position_1.Position(row + target, rows[row + target - 1].length + 1);
91507
+ const end = new position_1.Position(row + blanks, rows[row + blanks - 1].length + 1);
91508
+ return edit_helper_1.EditHelper.deleteRange(file, start, end);
91509
+ }
91510
+ return undefined;
91511
+ }
91241
91512
  isConfigurationValid() {
91242
91513
  if (this.conf.count < 1 || (this.conf.count === 1 && this.conf.logic === NewlineLogic.Less)) {
91243
91514
  return false;
@@ -97679,6 +97950,173 @@ exports.ReduceStringTemplates = ReduceStringTemplates;
97679
97950
 
97680
97951
  /***/ },
97681
97952
 
97953
+ /***/ "../core/build/src/rules/redundant_cast.js"
97954
+ /*!*************************************************!*\
97955
+ !*** ../core/build/src/rules/redundant_cast.js ***!
97956
+ \*************************************************/
97957
+ (__unused_webpack_module, exports, __webpack_require__) {
97958
+
97959
+ "use strict";
97960
+
97961
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
97962
+ if (k2 === undefined) k2 = k;
97963
+ var desc = Object.getOwnPropertyDescriptor(m, k);
97964
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
97965
+ desc = { enumerable: true, get: function() { return m[k]; } };
97966
+ }
97967
+ Object.defineProperty(o, k2, desc);
97968
+ }) : (function(o, m, k, k2) {
97969
+ if (k2 === undefined) k2 = k;
97970
+ o[k2] = m[k];
97971
+ }));
97972
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
97973
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
97974
+ }) : function(o, v) {
97975
+ o["default"] = v;
97976
+ });
97977
+ var __importStar = (this && this.__importStar) || (function () {
97978
+ var ownKeys = function(o) {
97979
+ ownKeys = Object.getOwnPropertyNames || function (o) {
97980
+ var ar = [];
97981
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
97982
+ return ar;
97983
+ };
97984
+ return ownKeys(o);
97985
+ };
97986
+ return function (mod) {
97987
+ if (mod && mod.__esModule) return mod;
97988
+ var result = {};
97989
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
97990
+ __setModuleDefault(result, mod);
97991
+ return result;
97992
+ };
97993
+ })();
97994
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
97995
+ exports.RedundantCast = exports.RedundantCastConf = void 0;
97996
+ const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
97997
+ const _reference_1 = __webpack_require__(/*! ../abap/5_syntax/_reference */ "../core/build/src/abap/5_syntax/_reference.js");
97998
+ const syntax_1 = __webpack_require__(/*! ../abap/5_syntax/syntax */ "../core/build/src/abap/5_syntax/syntax.js");
97999
+ const nodes_1 = __webpack_require__(/*! ../abap/nodes */ "../core/build/src/abap/nodes/index.js");
98000
+ const _typed_identifier_1 = __webpack_require__(/*! ../abap/types/_typed_identifier */ "../core/build/src/abap/types/_typed_identifier.js");
98001
+ const basic_1 = __webpack_require__(/*! ../abap/types/basic */ "../core/build/src/abap/types/basic/index.js");
98002
+ const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
98003
+ const _abap_object_1 = __webpack_require__(/*! ../objects/_abap_object */ "../core/build/src/objects/_abap_object.js");
98004
+ const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
98005
+ const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
98006
+ const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
98007
+ const version_1 = __webpack_require__(/*! ../version */ "../core/build/src/version.js");
98008
+ class RedundantCastConf extends _basic_rule_config_1.BasicRuleConfig {
98009
+ }
98010
+ exports.RedundantCastConf = RedundantCastConf;
98011
+ class RedundantCast {
98012
+ constructor() {
98013
+ this.conf = new RedundantCastConf();
98014
+ }
98015
+ getMetadata() {
98016
+ return {
98017
+ key: "redundant_cast",
98018
+ title: "Redundant Cast",
98019
+ shortDescription: `Find redundant CAST expressions`,
98020
+ extendedInformation: `Reports CAST expressions whose operand is already a reference to the cast's target class or interface.`,
98021
+ tags: [_irule_1.RuleTag.Quickfix],
98022
+ badExample: `DATA ref TYPE REF TO lcl.
98023
+ DATA(copy) = CAST lcl( ref ).`,
98024
+ goodExample: `DATA ref TYPE REF TO lcl.
98025
+ DATA(copy) = ref.`,
98026
+ };
98027
+ }
98028
+ getConfig() {
98029
+ return this.conf;
98030
+ }
98031
+ setConfig(conf) {
98032
+ this.conf = conf;
98033
+ }
98034
+ initialize(reg) {
98035
+ this.reg = reg;
98036
+ return this;
98037
+ }
98038
+ run(obj) {
98039
+ var _a;
98040
+ if (!(0, version_1.releaseAtLeast)(this.reg.getConfig().getRelease(), version_1.Release.v740sp02)
98041
+ && !this.reg.getConfig().isOpenABAP()) {
98042
+ return [];
98043
+ }
98044
+ if (!(obj instanceof _abap_object_1.ABAPObject)) {
98045
+ return [];
98046
+ }
98047
+ const syntax = new syntax_1.SyntaxLogic(this.reg, obj).run();
98048
+ if (syntax.issues.length > 0) {
98049
+ return [];
98050
+ }
98051
+ const issues = [];
98052
+ for (const file of obj.getABAPFiles()) {
98053
+ const structure = file.getStructure();
98054
+ if (structure === undefined) {
98055
+ continue;
98056
+ }
98057
+ for (const cast of structure.findAllExpressionsRecursive(Expressions.Cast)) {
98058
+ const typeExpression = cast.findDirectExpression(Expressions.TypeNameOrInfer);
98059
+ const source = cast.findDirectExpression(Expressions.Source);
98060
+ if (typeExpression === undefined
98061
+ || source === undefined
98062
+ || cast.findDirectExpression(Expressions.Let) !== undefined) {
98063
+ continue;
98064
+ }
98065
+ const scope = syntax.spaghetti.lookupPosition(cast.getFirstToken().getStart(), file.getFilename());
98066
+ if (scope === undefined) {
98067
+ continue;
98068
+ }
98069
+ const target = (_a = scope.getData().references.find(reference => reference.referenceType === _reference_1.ReferenceType.InferredType
98070
+ && reference.position.getStart().equals(typeExpression.getFirstToken().getStart()))) === null || _a === void 0 ? void 0 : _a.resolved;
98071
+ if (!(target instanceof _typed_identifier_1.TypedIdentifier)) {
98072
+ continue;
98073
+ }
98074
+ const operandType = this.sourceType(source, scope);
98075
+ if (operandType === undefined || this.sameType(target.getType(), operandType) === false) {
98076
+ continue;
98077
+ }
98078
+ const closingParen = cast.getDirectTokens().find(token => token.getStr() === ")" && token.getStart().isAfter(source.getLastToken().getStart()));
98079
+ if (closingParen === undefined) {
98080
+ continue;
98081
+ }
98082
+ const fix = edit_helper_1.EditHelper.replaceRange(file, cast.getFirstToken().getStart(), closingParen.getEnd(), source.concatTokens());
98083
+ issues.push(issue_1.Issue.atRange(file, cast.getFirstToken().getStart(), closingParen.getEnd(), "Redundant CAST expression", this.getMetadata().key, this.conf.severity, fix));
98084
+ }
98085
+ }
98086
+ return issues;
98087
+ }
98088
+ /** The type of a plain variable or attribute, undefined for anything more complex */
98089
+ sourceType(source, scope) {
98090
+ var _a;
98091
+ const children = source.getChildren();
98092
+ if (children.length !== 1 || !(children[0].get() instanceof Expressions.FieldChain)) {
98093
+ return undefined;
98094
+ }
98095
+ const fieldChain = children[0];
98096
+ const last = fieldChain.getLastChild();
98097
+ if (!(last instanceof nodes_1.ExpressionNode)
98098
+ || !(last.get() instanceof Expressions.SourceField || last.get() instanceof Expressions.AttributeName)) {
98099
+ return undefined;
98100
+ }
98101
+ const operand = (_a = scope.getData().references.find(reference => reference.referenceType === _reference_1.ReferenceType.DataReadReference
98102
+ && reference.position.getStart().equals(last.getFirstToken().getStart()))) === null || _a === void 0 ? void 0 : _a.resolved;
98103
+ if (!(operand instanceof _typed_identifier_1.TypedIdentifier)) {
98104
+ return undefined;
98105
+ }
98106
+ return operand.getType();
98107
+ }
98108
+ sameType(first, second) {
98109
+ if (!(first instanceof basic_1.ObjectReferenceType) || !(second instanceof basic_1.ObjectReferenceType)) {
98110
+ return false;
98111
+ }
98112
+ return first.getIdentifierName().toUpperCase() === second.getIdentifierName().toUpperCase();
98113
+ }
98114
+ }
98115
+ exports.RedundantCast = RedundantCast;
98116
+ //# sourceMappingURL=redundant_cast.js.map
98117
+
98118
+ /***/ },
98119
+
97682
98120
  /***/ "../core/build/src/rules/redundant_conversion.js"
97683
98121
  /*!*******************************************************!*\
97684
98122
  !*** ../core/build/src/rules/redundant_conversion.js ***!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/cli",
3
- "version": "2.120.76",
3
+ "version": "2.120.78",
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.76",
42
+ "@abaplint/core": "^2.120.78",
43
43
  "@types/chai": "^4.3.20",
44
44
  "@types/minimist": "^1.2.5",
45
45
  "@types/mocha": "^10.0.10",