@abaplint/core 2.109.2 → 2.110.0

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.
@@ -3221,10 +3221,14 @@ declare interface IMacroReferences {
3221
3221
  addReference(ref: IFilenameAndToken): void;
3222
3222
  listDefinitionsByFile(filename: string): Token[];
3223
3223
  listUsagesbyMacro(filename: string, token: Token): IFilenameAndToken[];
3224
- getDefinitionPosition(filename: string, token: Token): {
3224
+ getDefinitionRange(filename: string, token: Token): {
3225
3225
  start: Position;
3226
3226
  end: Position;
3227
3227
  } | undefined;
3228
+ findDefinitionByUsage(filename: string, token: Token): {
3229
+ filename: string;
3230
+ token: Token;
3231
+ } | undefined;
3228
3232
  clear(filename: string): void;
3229
3233
  }
3230
3234
 
@@ -12,6 +12,7 @@ const _reference_1 = require("../abap/5_syntax/_reference");
12
12
  const _builtin_1 = require("../abap/5_syntax/_builtin");
13
13
  const _scope_type_1 = require("../abap/5_syntax/_scope_type");
14
14
  const types_1 = require("../abap/types");
15
+ const _statement_1 = require("../abap/2_statements/statements/_statement");
15
16
  class LSPLookup {
16
17
  static lookup(cursor, reg, obj) {
17
18
  var _a, _b;
@@ -128,6 +129,18 @@ class LSPLookup {
128
129
  scope: bottomScope,
129
130
  };
130
131
  }
132
+ if (cursor.snode.get() instanceof _statement_1.MacroCall) {
133
+ const macroDefinition = reg.getMacroReferences().findDefinitionByUsage(cursor.identifier.getFilename(), cursor.snode.getFirstToken());
134
+ if (macroDefinition) {
135
+ return {
136
+ hover: "Macro Call",
137
+ definition: {
138
+ uri: macroDefinition === null || macroDefinition === void 0 ? void 0 : macroDefinition.filename,
139
+ range: _lsp_utils_1.LSPUtils.tokenToRange(macroDefinition.token),
140
+ },
141
+ };
142
+ }
143
+ }
131
144
  if (hoverValue !== "") {
132
145
  return { hover: hoverValue, scope: bottomScope };
133
146
  }
@@ -30,6 +30,7 @@ class References {
30
30
  const locs = this.search(lookup.definitionId, lookup.scope);
31
31
  return locs.map(_lsp_utils_1.LSPUtils.identiferToLocation);
32
32
  }
33
+ ////////////////////////////////////////////
33
34
  // todo, cleanup this mehtod, some of the method parameters are not used anymore?
34
35
  search(identifier, node, exitAfterFound = false, removeDuplicates = true) {
35
36
  let ret = [];
@@ -57,7 +58,6 @@ class References {
57
58
  return ret;
58
59
  }
59
60
  }
60
- ////////////////////////////////////////////
61
61
  removeDuplicates(arr) {
62
62
  const values = {};
63
63
  return arr.filter(item => {
@@ -15,7 +15,7 @@ class MacroReferences {
15
15
  }
16
16
  this.definitions[ref.filename].push({ token: ref.token, start, end });
17
17
  }
18
- getDefinitionPosition(filename, token) {
18
+ getDefinitionRange(filename, token) {
19
19
  for (const d of this.definitions[filename] || []) {
20
20
  if (d.token.getStart().equals(token.getStart())) {
21
21
  return { start: d.start, end: d.end };
@@ -50,6 +50,22 @@ class MacroReferences {
50
50
  delete this.definitions[filename];
51
51
  delete this.references[filename];
52
52
  }
53
+ findDefinitionByUsage(filename, token) {
54
+ const tokenStr = token.getStr().toUpperCase();
55
+ for (const ref of this.references[filename] || []) {
56
+ if (ref.token.getStart().equals(token.getStart())) {
57
+ for (const d of this.definitions[ref.filename] || []) {
58
+ if (d.token.getStr().toUpperCase() === tokenStr) {
59
+ return {
60
+ filename: ref.filename,
61
+ token: d.token,
62
+ };
63
+ }
64
+ }
65
+ }
66
+ }
67
+ return undefined;
68
+ }
53
69
  }
54
70
  exports.MacroReferences = MacroReferences;
55
71
  //# sourceMappingURL=macro_references.js.map
@@ -67,7 +67,7 @@ class Registry {
67
67
  }
68
68
  static abaplintVersion() {
69
69
  // magic, see build script "version.sh"
70
- return "2.109.2";
70
+ return "2.110.0";
71
71
  }
72
72
  getDDICReferences() {
73
73
  return this.ddicReferences;
@@ -31,7 +31,6 @@ __exportStar(require("./cds_legacy_view"), exports);
31
31
  __exportStar(require("./cds_parser_error"), exports);
32
32
  __exportStar(require("./chain_mainly_declarations"), exports);
33
33
  __exportStar(require("./change_if_to_case"), exports);
34
- __exportStar(require("./unused_macros"), exports);
35
34
  __exportStar(require("./check_abstract"), exports);
36
35
  __exportStar(require("./check_comments"), exports);
37
36
  __exportStar(require("./check_ddic"), exports);
@@ -93,6 +92,7 @@ __exportStar(require("./line_only_punc"), exports);
93
92
  __exportStar(require("./local_class_naming"), exports);
94
93
  __exportStar(require("./local_testclass_consistency"), exports);
95
94
  __exportStar(require("./local_variable_names"), exports);
95
+ __exportStar(require("./macro_naming"), exports);
96
96
  __exportStar(require("./main_file_contents"), exports);
97
97
  __exportStar(require("./many_parentheses"), exports);
98
98
  __exportStar(require("./max_one_method_parameter_per_line"), exports);
@@ -170,6 +170,7 @@ __exportStar(require("./unnecessary_return"), exports);
170
170
  __exportStar(require("./unreachable_code"), exports);
171
171
  __exportStar(require("./unsecure_fae"), exports);
172
172
  __exportStar(require("./unused_ddic"), exports);
173
+ __exportStar(require("./unused_macros"), exports);
173
174
  __exportStar(require("./unused_methods"), exports);
174
175
  __exportStar(require("./unused_types"), exports);
175
176
  __exportStar(require("./unused_variables"), exports);
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MacroNaming = exports.MacroNamingConf = void 0;
4
+ const issue_1 = require("../issue");
5
+ const _abap_rule_1 = require("./_abap_rule");
6
+ const Statements = require("../abap/2_statements/statements");
7
+ const Expressions = require("../abap/2_statements/expressions");
8
+ const _basic_rule_config_1 = require("./_basic_rule_config");
9
+ const _irule_1 = require("./_irule");
10
+ const objects_1 = require("../objects");
11
+ class MacroNamingConf extends _basic_rule_config_1.BasicRuleConfig {
12
+ constructor() {
13
+ super(...arguments);
14
+ /** The pattern for macros, case insensitive */
15
+ this.pattern = "^_.+$";
16
+ }
17
+ }
18
+ exports.MacroNamingConf = MacroNamingConf;
19
+ class MacroNaming extends _abap_rule_1.ABAPRule {
20
+ constructor() {
21
+ super(...arguments);
22
+ this.conf = new MacroNamingConf();
23
+ }
24
+ getMetadata() {
25
+ return {
26
+ key: "macro_naming",
27
+ title: "Macro naming conventions",
28
+ shortDescription: `Allows you to enforce a pattern for macro definitions`,
29
+ extendedInformation: `Use rule "avoid_use" to avoid macros alotogether.`,
30
+ tags: [_irule_1.RuleTag.Naming, _irule_1.RuleTag.SingleFile],
31
+ };
32
+ }
33
+ getConfig() {
34
+ return this.conf;
35
+ }
36
+ setConfig(conf) {
37
+ this.conf = conf;
38
+ }
39
+ runParsed(file, obj) {
40
+ const issues = [];
41
+ const testRegex = new RegExp(this.conf.pattern, "i");
42
+ if (obj instanceof objects_1.TypePool) {
43
+ return [];
44
+ }
45
+ for (const stat of file.getStatements()) {
46
+ if (!(stat.get() instanceof Statements.Define)) {
47
+ continue;
48
+ }
49
+ const expr = stat.findDirectExpression(Expressions.MacroName);
50
+ if (expr === undefined) {
51
+ continue;
52
+ }
53
+ const token = expr.getFirstToken();
54
+ if (testRegex.exec(token.getStr())) {
55
+ continue;
56
+ }
57
+ else {
58
+ const message = "Bad macro name naming, expected \"" + this.conf.pattern + "\", got \"" + token.getStr() + "\"";
59
+ const issue = issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity);
60
+ issues.push(issue);
61
+ }
62
+ }
63
+ return issues;
64
+ }
65
+ }
66
+ exports.MacroNaming = MacroNaming;
67
+ //# sourceMappingURL=macro_naming.js.map
@@ -22,11 +22,9 @@ class RFCErrorHandling extends _abap_rule_1.ABAPRule {
22
22
  tags: [_irule_1.RuleTag.SingleFile],
23
23
  shortDescription: `Checks that exceptions 'system_failure' and 'communication_failure' are handled in RFC calls`,
24
24
  extendedInformation: `https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abenrfc_exception.htm`,
25
- badExample: `
26
- CALL FUNCTION 'ZRFC'
25
+ badExample: `CALL FUNCTION 'ZRFC'
27
26
  DESTINATION lv_rfc.`,
28
- goodExample: `
29
- CALL FUNCTION 'ZRFC'
27
+ goodExample: `CALL FUNCTION 'ZRFC'
30
28
  DESTINATION lv_rfc
31
29
  EXCEPTIONS
32
30
  system_failure = 1 MESSAGE msg
@@ -11,7 +11,7 @@ const objects_1 = require("../objects");
11
11
  class TypesNamingConf extends _basic_rule_config_1.BasicRuleConfig {
12
12
  constructor() {
13
13
  super(...arguments);
14
- /** The pattern for TYPES */
14
+ /** The pattern for TYPES, case insensitive */
15
15
  this.pattern = "^TY_.+$";
16
16
  }
17
17
  }
@@ -61,7 +61,7 @@ foobar2.`,
61
61
  const usages = references.listUsagesbyMacro(file.getFilename(), macroToken);
62
62
  if (usages.length === 0 && ((_a = this.conf.skipNames) === null || _a === void 0 ? void 0 : _a.includes(macroToken.getStr().toUpperCase())) === false) {
63
63
  const message = "Unused macro definition: " + macroToken.getStr();
64
- const pos = references.getDefinitionPosition(file.getFilename(), macroToken);
64
+ const pos = references.getDefinitionRange(file.getFilename(), macroToken);
65
65
  const fix = edit_helper_1.EditHelper.deleteRange(file, pos.start, pos.end);
66
66
  result.push(issue_1.Issue.atToken(file, macroToken, message, this.getMetadata().key, this.conf.severity, fix));
67
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.109.2",
3
+ "version": "2.110.0",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",
@@ -57,7 +57,7 @@
57
57
  "chai": "^4.4.1",
58
58
  "eslint": "^8.57.0",
59
59
  "mocha": "^10.4.0",
60
- "c8": "^9.1.0",
60
+ "c8": "^10.1.2",
61
61
  "source-map-support": "^0.5.21",
62
62
  "ts-json-schema-generator": "=2.0.1",
63
63
  "typescript": "^5.4.5"