@abaplint/cli 2.108.14 → 2.109.1

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 +205 -21
  2. package/package.json +2 -2
package/build/cli.js CHANGED
@@ -3648,17 +3648,23 @@ class Macros {
3648
3648
  constructor(globalMacros) {
3649
3649
  this.macros = {};
3650
3650
  for (const m of globalMacros) {
3651
- this.macros[m.toUpperCase()] = [];
3651
+ this.macros[m.toUpperCase()] = {
3652
+ statements: [],
3653
+ filename: undefined,
3654
+ };
3652
3655
  }
3653
3656
  }
3654
- addMacro(name, contents) {
3657
+ addMacro(name, contents, filename) {
3655
3658
  if (this.isMacro(name)) {
3656
3659
  return;
3657
3660
  }
3658
- this.macros[name.toUpperCase()] = contents;
3661
+ this.macros[name.toUpperCase()] = {
3662
+ statements: contents,
3663
+ filename: filename,
3664
+ };
3659
3665
  }
3660
3666
  getContents(name) {
3661
- return this.macros[name.toUpperCase()];
3667
+ return this.macros[name.toUpperCase()].statements;
3662
3668
  }
3663
3669
  listMacroNames() {
3664
3670
  return Object.keys(this.macros);
@@ -3669,6 +3675,9 @@ class Macros {
3669
3675
  }
3670
3676
  return false;
3671
3677
  }
3678
+ getMacroFilename(name) {
3679
+ return this.macros[name.toUpperCase()].filename;
3680
+ }
3672
3681
  }
3673
3682
  class ExpandMacros {
3674
3683
  // "reg" must be supplied if there are cross object macros via INCLUDE
@@ -3678,35 +3687,42 @@ class ExpandMacros {
3678
3687
  this.globalMacros = globalMacros;
3679
3688
  this.reg = reg;
3680
3689
  }
3681
- find(statements) {
3682
- var _a, _b;
3683
- let name = undefined;
3690
+ find(statements, file, clear = true) {
3691
+ var _a, _b, _c;
3692
+ let nameToken = undefined;
3693
+ let start = undefined;
3684
3694
  let contents = [];
3695
+ const macroReferences = (_a = this.reg) === null || _a === void 0 ? void 0 : _a.getMacroReferences();
3696
+ if (clear) {
3697
+ macroReferences === null || macroReferences === void 0 ? void 0 : macroReferences.clear(file.getFilename());
3698
+ }
3685
3699
  for (let i = 0; i < statements.length; i++) {
3686
3700
  const statement = statements[i];
3687
3701
  const type = statement.get();
3688
3702
  if (type instanceof Statements.Define) {
3689
3703
  // todo, will this break if first token is a pragma?
3690
- name = statement.getTokens()[1].getStr();
3704
+ nameToken = statement.getTokens()[1];
3705
+ start = statement.getFirstToken().getStart();
3691
3706
  contents = [];
3692
3707
  }
3693
3708
  else if (type instanceof Statements.Include) {
3694
- const includeName = (_a = statement.findDirectExpression(Expressions.IncludeName)) === null || _a === void 0 ? void 0 : _a.concatTokens();
3709
+ const includeName = (_b = statement.findDirectExpression(Expressions.IncludeName)) === null || _b === void 0 ? void 0 : _b.concatTokens();
3695
3710
  // todo, this does not take function module includes into account
3696
- const prog = (_b = this.reg) === null || _b === void 0 ? void 0 : _b.getObject("PROG", includeName);
3711
+ const prog = (_c = this.reg) === null || _c === void 0 ? void 0 : _c.getObject("PROG", includeName);
3697
3712
  if (prog) {
3698
3713
  prog.parse(this.version, this.globalMacros, this.reg);
3699
- const main = prog.getMainABAPFile();
3700
- if (main) {
3714
+ const includeMainFile = prog.getMainABAPFile();
3715
+ if (includeMainFile) {
3701
3716
  // slow, this copies everything,
3702
- this.find([...main.getStatements()]);
3717
+ this.find([...includeMainFile.getStatements()], includeMainFile, false);
3703
3718
  }
3704
3719
  }
3705
3720
  }
3706
- else if (name) {
3721
+ else if (nameToken) {
3707
3722
  if (type instanceof Statements.EndOfDefinition) {
3708
- this.macros.addMacro(name, contents);
3709
- name = undefined;
3723
+ this.macros.addMacro(nameToken.getStr(), contents, file.getFilename());
3724
+ macroReferences === null || macroReferences === void 0 ? void 0 : macroReferences.addDefinition({ filename: file.getFilename(), token: nameToken }, start, statement.getLastToken().getEnd());
3725
+ nameToken = undefined;
3710
3726
  }
3711
3727
  else if (!(type instanceof _statement_1.Comment)) {
3712
3728
  statements[i] = new statement_node_1.StatementNode(new _statement_1.MacroContent()).setChildren(this.tokensToNodes(statement.getTokens()));
@@ -3715,17 +3731,26 @@ class ExpandMacros {
3715
3731
  }
3716
3732
  }
3717
3733
  }
3718
- handleMacros(statements) {
3734
+ handleMacros(statements, file) {
3735
+ var _a;
3719
3736
  const result = [];
3720
3737
  let containsUnknown = false;
3738
+ const macroReferences = (_a = this.reg) === null || _a === void 0 ? void 0 : _a.getMacroReferences();
3721
3739
  for (const statement of statements) {
3722
3740
  const type = statement.get();
3723
3741
  if (type instanceof _statement_1.Unknown || type instanceof _statement_1.MacroCall) {
3724
3742
  const macroName = this.findName(statement.getTokens());
3725
3743
  if (macroName && this.macros.isMacro(macroName)) {
3744
+ const filename = this.macros.getMacroFilename(macroName);
3745
+ if (filename) {
3746
+ macroReferences === null || macroReferences === void 0 ? void 0 : macroReferences.addReference({
3747
+ filename: filename,
3748
+ token: statement.getFirstToken(),
3749
+ });
3750
+ }
3726
3751
  result.push(new statement_node_1.StatementNode(new _statement_1.MacroCall(), statement.getColon()).setChildren(this.tokensToNodes(statement.getTokens())));
3727
3752
  const expanded = this.expandContents(macroName, statement);
3728
- const handled = this.handleMacros(expanded);
3753
+ const handled = this.handleMacros(expanded, file);
3729
3754
  for (const e of handled.statements) {
3730
3755
  result.push(e);
3731
3756
  }
@@ -9581,10 +9606,10 @@ class StatementParser {
9581
9606
  for (const w of wa) {
9582
9607
  this.process(w);
9583
9608
  this.categorize(w);
9584
- macros.find(w.statements);
9609
+ macros.find(w.statements, w.file);
9585
9610
  }
9586
9611
  for (const w of wa) {
9587
- const res = macros.handleMacros(w.statements);
9612
+ const res = macros.handleMacros(w.statements, w.file);
9588
9613
  w.statements = res.statements;
9589
9614
  if (res.containsUnknown === true) {
9590
9615
  this.lazyUnknown(w);
@@ -42840,6 +42865,7 @@ const LServer = __webpack_require__(/*! vscode-languageserver-types */ "./node_m
42840
42865
  const _abap_object_1 = __webpack_require__(/*! ../objects/_abap_object */ "./node_modules/@abaplint/core/build/src/objects/_abap_object.js");
42841
42866
  const _lsp_utils_1 = __webpack_require__(/*! ./_lsp_utils */ "./node_modules/@abaplint/core/build/src/lsp/_lsp_utils.js");
42842
42867
  const _lookup_1 = __webpack_require__(/*! ./_lookup */ "./node_modules/@abaplint/core/build/src/lsp/_lookup.js");
42868
+ const _statement_1 = __webpack_require__(/*! ../abap/2_statements/statements/_statement */ "./node_modules/@abaplint/core/build/src/abap/2_statements/statements/_statement.js");
42843
42869
  class Hover {
42844
42870
  constructor(reg) {
42845
42871
  this.reg = reg;
@@ -42863,6 +42889,9 @@ class Hover {
42863
42889
  || found.token instanceof Tokens.StringTemplateMiddle) {
42864
42890
  return { kind: LServer.MarkupKind.Markdown, value: "String Template" };
42865
42891
  }
42892
+ else if (found.snode.get() instanceof _statement_1.MacroCall) {
42893
+ return { kind: LServer.MarkupKind.Markdown, value: "Macro Call" };
42894
+ }
42866
42895
  else if (found.snode.get() instanceof Statements.Define && found.stack.length === 2) {
42867
42896
  return { kind: LServer.MarkupKind.Markdown, value: "Macro Name" };
42868
42897
  }
@@ -43687,6 +43716,71 @@ exports.Symbols = Symbols;
43687
43716
 
43688
43717
  /***/ }),
43689
43718
 
43719
+ /***/ "./node_modules/@abaplint/core/build/src/macro_references.js":
43720
+ /*!*******************************************************************!*\
43721
+ !*** ./node_modules/@abaplint/core/build/src/macro_references.js ***!
43722
+ \*******************************************************************/
43723
+ /***/ ((__unused_webpack_module, exports) => {
43724
+
43725
+ "use strict";
43726
+
43727
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
43728
+ exports.MacroReferences = void 0;
43729
+ class MacroReferences {
43730
+ constructor() {
43731
+ this.definitions = {};
43732
+ this.references = {};
43733
+ }
43734
+ addDefinition(ref, start, end) {
43735
+ if (this.definitions[ref.filename] === undefined) {
43736
+ this.definitions[ref.filename] = [];
43737
+ }
43738
+ else if (this.definitions[ref.filename].find((d) => d.token.getStart().equals(ref.token.getStart()))) {
43739
+ return;
43740
+ }
43741
+ this.definitions[ref.filename].push({ token: ref.token, start, end });
43742
+ }
43743
+ getDefinitionPosition(filename, token) {
43744
+ for (const d of this.definitions[filename] || []) {
43745
+ if (d.token.getStart().equals(token.getStart())) {
43746
+ return { start: d.token.getStart(), end: d.token.getEnd() };
43747
+ }
43748
+ }
43749
+ return undefined;
43750
+ }
43751
+ addReference(ref) {
43752
+ if (this.references[ref.filename] === undefined) {
43753
+ this.references[ref.filename] = [];
43754
+ }
43755
+ this.references[ref.filename].push(ref);
43756
+ }
43757
+ listDefinitionsByFile(filename) {
43758
+ const ret = [];
43759
+ for (const d of this.definitions[filename] || []) {
43760
+ ret.push(d.token);
43761
+ }
43762
+ return ret;
43763
+ }
43764
+ listUsagesbyMacro(filename, token) {
43765
+ const ret = [];
43766
+ const tokenStr = token.getStr().toUpperCase();
43767
+ for (const ref of this.references[filename] || []) {
43768
+ if (ref.token.getStr().toUpperCase() === tokenStr) {
43769
+ ret.push(ref);
43770
+ }
43771
+ }
43772
+ return ret;
43773
+ }
43774
+ clear(filename) {
43775
+ delete this.definitions[filename];
43776
+ delete this.references[filename];
43777
+ }
43778
+ }
43779
+ exports.MacroReferences = MacroReferences;
43780
+ //# sourceMappingURL=macro_references.js.map
43781
+
43782
+ /***/ }),
43783
+
43690
43784
  /***/ "./node_modules/@abaplint/core/build/src/msag_references.js":
43691
43785
  /*!******************************************************************!*\
43692
43786
  !*** ./node_modules/@abaplint/core/build/src/msag_references.js ***!
@@ -51592,6 +51686,7 @@ const excludeHelper_1 = __webpack_require__(/*! ./utils/excludeHelper */ "./node
51592
51686
  const ddic_references_1 = __webpack_require__(/*! ./ddic_references */ "./node_modules/@abaplint/core/build/src/ddic_references.js");
51593
51687
  const rules_runner_1 = __webpack_require__(/*! ./rules_runner */ "./node_modules/@abaplint/core/build/src/rules_runner.js");
51594
51688
  const msag_references_1 = __webpack_require__(/*! ./msag_references */ "./node_modules/@abaplint/core/build/src/msag_references.js");
51689
+ const macro_references_1 = __webpack_require__(/*! ./macro_references */ "./node_modules/@abaplint/core/build/src/macro_references.js");
51595
51690
  // todo, this should really be an instance in case there are multiple Registry'ies
51596
51691
  class ParsingPerformance {
51597
51692
  static clear() {
@@ -51646,10 +51741,11 @@ class Registry {
51646
51741
  this.conf = conf ? conf : config_1.Config.getDefault();
51647
51742
  this.ddicReferences = new ddic_references_1.DDICReferences();
51648
51743
  this.msagReferences = new msag_references_1.MSAGReferences();
51744
+ this.macroReferences = new macro_references_1.MacroReferences();
51649
51745
  }
51650
51746
  static abaplintVersion() {
51651
51747
  // magic, see build script "version.sh"
51652
- return "2.108.14";
51748
+ return "2.109.1";
51653
51749
  }
51654
51750
  getDDICReferences() {
51655
51751
  return this.ddicReferences;
@@ -51657,6 +51753,9 @@ class Registry {
51657
51753
  getMSAGReferences() {
51658
51754
  return this.msagReferences;
51659
51755
  }
51756
+ getMacroReferences() {
51757
+ return this.macroReferences;
51758
+ }
51660
51759
  *getObjects() {
51661
51760
  for (const name in this.objects) {
51662
51761
  for (const type in this.objects[name]) {
@@ -62388,6 +62487,7 @@ __exportStar(__webpack_require__(/*! ./cds_legacy_view */ "./node_modules/@abapl
62388
62487
  __exportStar(__webpack_require__(/*! ./cds_parser_error */ "./node_modules/@abaplint/core/build/src/rules/cds_parser_error.js"), exports);
62389
62488
  __exportStar(__webpack_require__(/*! ./chain_mainly_declarations */ "./node_modules/@abaplint/core/build/src/rules/chain_mainly_declarations.js"), exports);
62390
62489
  __exportStar(__webpack_require__(/*! ./change_if_to_case */ "./node_modules/@abaplint/core/build/src/rules/change_if_to_case.js"), exports);
62490
+ __exportStar(__webpack_require__(/*! ./unused_macros */ "./node_modules/@abaplint/core/build/src/rules/unused_macros.js"), exports);
62391
62491
  __exportStar(__webpack_require__(/*! ./check_abstract */ "./node_modules/@abaplint/core/build/src/rules/check_abstract.js"), exports);
62392
62492
  __exportStar(__webpack_require__(/*! ./check_comments */ "./node_modules/@abaplint/core/build/src/rules/check_comments.js"), exports);
62393
62493
  __exportStar(__webpack_require__(/*! ./check_ddic */ "./node_modules/@abaplint/core/build/src/rules/check_ddic.js"), exports);
@@ -72266,6 +72366,90 @@ exports.UnusedDDIC = UnusedDDIC;
72266
72366
 
72267
72367
  /***/ }),
72268
72368
 
72369
+ /***/ "./node_modules/@abaplint/core/build/src/rules/unused_macros.js":
72370
+ /*!**********************************************************************!*\
72371
+ !*** ./node_modules/@abaplint/core/build/src/rules/unused_macros.js ***!
72372
+ \**********************************************************************/
72373
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
72374
+
72375
+ "use strict";
72376
+
72377
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
72378
+ exports.UnusedMacros = exports.UnusedMacrosConf = void 0;
72379
+ const issue_1 = __webpack_require__(/*! ../issue */ "./node_modules/@abaplint/core/build/src/issue.js");
72380
+ const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "./node_modules/@abaplint/core/build/src/rules/_basic_rule_config.js");
72381
+ const _irule_1 = __webpack_require__(/*! ./_irule */ "./node_modules/@abaplint/core/build/src/rules/_irule.js");
72382
+ const _abap_object_1 = __webpack_require__(/*! ../objects/_abap_object */ "./node_modules/@abaplint/core/build/src/objects/_abap_object.js");
72383
+ const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "./node_modules/@abaplint/core/build/src/edit_helper.js");
72384
+ class UnusedMacrosConf extends _basic_rule_config_1.BasicRuleConfig {
72385
+ constructor() {
72386
+ super(...arguments);
72387
+ /** skip specific names, case insensitive
72388
+ * @uniqueItems true
72389
+ */
72390
+ this.skipNames = [];
72391
+ }
72392
+ }
72393
+ exports.UnusedMacrosConf = UnusedMacrosConf;
72394
+ class UnusedMacros {
72395
+ constructor() {
72396
+ this.conf = new UnusedMacrosConf();
72397
+ }
72398
+ getMetadata() {
72399
+ return {
72400
+ key: "unused_macros",
72401
+ title: "Unused macros",
72402
+ shortDescription: `Checks for unused macro definitions definitions`,
72403
+ tags: [_irule_1.RuleTag.Quickfix],
72404
+ badExample: `DEFINE foobar1.
72405
+ WRITE 'hello'.
72406
+ END-OF-DEFINITION.`,
72407
+ goodExample: `DEFINE foobar2.
72408
+ WRITE 'hello'.
72409
+ END-OF-DEFINITION.
72410
+
72411
+ foobar2.`,
72412
+ };
72413
+ }
72414
+ getConfig() {
72415
+ return this.conf;
72416
+ }
72417
+ setConfig(conf) {
72418
+ this.conf = conf;
72419
+ if (this.conf.skipNames === undefined) {
72420
+ this.conf.skipNames = [];
72421
+ }
72422
+ }
72423
+ initialize(reg) {
72424
+ this.reg = reg;
72425
+ return this;
72426
+ }
72427
+ run(obj) {
72428
+ var _a;
72429
+ const result = [];
72430
+ if (!(obj instanceof _abap_object_1.ABAPObject)) {
72431
+ return [];
72432
+ }
72433
+ const references = this.reg.getMacroReferences();
72434
+ for (const file of obj.getABAPFiles()) {
72435
+ for (const macroToken of references.listDefinitionsByFile(file.getFilename())) {
72436
+ const usages = references.listUsagesbyMacro(file.getFilename(), macroToken);
72437
+ if (usages.length === 0 && ((_a = this.conf.skipNames) === null || _a === void 0 ? void 0 : _a.includes(macroToken.getStr().toUpperCase())) === false) {
72438
+ const message = "Unused macro definition: " + macroToken.getStr();
72439
+ const pos = references.getDefinitionPosition(file.getFilename(), macroToken);
72440
+ const fix = edit_helper_1.EditHelper.deleteRange(file, pos.start, pos.end);
72441
+ result.push(issue_1.Issue.atToken(file, macroToken, message, this.getMetadata().key, this.conf.severity, fix));
72442
+ }
72443
+ }
72444
+ }
72445
+ return result;
72446
+ }
72447
+ }
72448
+ exports.UnusedMacros = UnusedMacros;
72449
+ //# sourceMappingURL=unused_macros.js.map
72450
+
72451
+ /***/ }),
72452
+
72269
72453
  /***/ "./node_modules/@abaplint/core/build/src/rules/unused_methods.js":
72270
72454
  /*!***********************************************************************!*\
72271
72455
  !*** ./node_modules/@abaplint/core/build/src/rules/unused_methods.js ***!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/cli",
3
- "version": "2.108.14",
3
+ "version": "2.109.1",
4
4
  "description": "abaplint - Command Line Interface",
5
5
  "funding": "https://github.com/sponsors/larshp",
6
6
  "bin": {
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "homepage": "https://abaplint.org",
40
40
  "devDependencies": {
41
- "@abaplint/core": "^2.108.14",
41
+ "@abaplint/core": "^2.109.1",
42
42
  "@types/chai": "^4.3.16",
43
43
  "@types/glob": "^8.1.0",
44
44
  "@types/minimist": "^1.2.5",