@abaplint/core 2.95.40 → 2.95.42

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.
@@ -1328,6 +1328,10 @@ declare class CustomizingTransaction extends AbstractObject {
1328
1328
  getDescription(): string | undefined;
1329
1329
  }
1330
1330
 
1331
+ export declare class CyclomaticComplexityStats {
1332
+ static run(obj: IObject): ICyclomaticComplexityResult[];
1333
+ }
1334
+
1331
1335
  declare class Dash extends Token {
1332
1336
  static railroad(): string;
1333
1337
  }
@@ -2799,6 +2803,13 @@ export declare interface IConfiguration {
2799
2803
  readByKey(rule: string, key: string): any;
2800
2804
  }
2801
2805
 
2806
+ declare interface ICyclomaticComplexityResult {
2807
+ file: IFile;
2808
+ pos: Position;
2809
+ name: string;
2810
+ count: number;
2811
+ }
2812
+
2802
2813
  declare interface IDDICReferences {
2803
2814
  setUsing(obj: IObject, using: readonly IObjectAndToken[]): void;
2804
2815
  addUsing(obj: IObject, using: IObjectAndToken | undefined): void;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RuleTag = exports.Severity = exports.Visibility = exports.Info = exports.Rename = exports.PrettyPrinter = exports.Position = exports.CurrentScope = exports.ABAPFile = exports.RulesRunner = exports.SpaghettiScope = exports.SyntaxLogic = exports.ABAPObject = exports.Tokens = exports.ExpressionsCDS = exports.CDSParser = exports.LanguageServerTypes = exports.DDLParser = exports.applyEditList = exports.applyEditSingle = exports.SpaghettiScopeNode = exports.AbstractFile = exports.Token = exports.ScopeType = exports.BasicTypes = exports.TypedIdentifier = exports.AbstractType = exports.VirtualPosition = exports.Comment = exports.Unknown = exports.Empty = exports.Identifier = exports.Nodes = exports.Types = exports.Expressions = exports.Statements = exports.Structures = exports.Objects = exports.ArtifactsRules = exports.ArtifactsObjects = exports.ArtifactsABAP = exports.BuiltIn = exports.MethodLengthStats = exports.LanguageServer = exports.Registry = exports.ReferenceType = exports.Version = exports.Config = exports.Issue = exports.MemoryFile = void 0;
3
+ exports.Severity = exports.Visibility = exports.Info = exports.Rename = exports.PrettyPrinter = exports.Position = exports.CurrentScope = exports.ABAPFile = exports.RulesRunner = exports.SpaghettiScope = exports.SyntaxLogic = exports.ABAPObject = exports.Tokens = exports.ExpressionsCDS = exports.CDSParser = exports.LanguageServerTypes = exports.DDLParser = exports.applyEditList = exports.applyEditSingle = exports.SpaghettiScopeNode = exports.AbstractFile = exports.Token = exports.ScopeType = exports.BasicTypes = exports.TypedIdentifier = exports.AbstractType = exports.VirtualPosition = exports.Comment = exports.Unknown = exports.Empty = exports.Identifier = exports.Nodes = exports.Types = exports.Expressions = exports.Statements = exports.Structures = exports.Objects = exports.ArtifactsRules = exports.ArtifactsObjects = exports.ArtifactsABAP = exports.BuiltIn = exports.MethodLengthStats = exports.LanguageServer = exports.Registry = exports.CyclomaticComplexityStats = exports.ReferenceType = exports.Version = exports.Config = exports.Issue = exports.MemoryFile = void 0;
4
+ exports.RuleTag = void 0;
4
5
  const issue_1 = require("./issue");
5
6
  Object.defineProperty(exports, "Issue", { enumerable: true, get: function () { return issue_1.Issue; } });
6
7
  const config_1 = require("./config");
@@ -96,4 +97,6 @@ const rules_runner_1 = require("./rules_runner");
96
97
  Object.defineProperty(exports, "RulesRunner", { enumerable: true, get: function () { return rules_runner_1.RulesRunner; } });
97
98
  const _irule_1 = require("./rules/_irule");
98
99
  Object.defineProperty(exports, "RuleTag", { enumerable: true, get: function () { return _irule_1.RuleTag; } });
100
+ const cyclomatic_complexity_stats_1 = require("./utils/cyclomatic_complexity_stats");
101
+ Object.defineProperty(exports, "CyclomaticComplexityStats", { enumerable: true, get: function () { return cyclomatic_complexity_stats_1.CyclomaticComplexityStats; } });
99
102
  //# sourceMappingURL=index.js.map
@@ -63,7 +63,7 @@ class Registry {
63
63
  }
64
64
  static abaplintVersion() {
65
65
  // magic, see build script "version.sh"
66
- return "2.95.40";
66
+ return "2.95.42";
67
67
  }
68
68
  getDDICReferences() {
69
69
  return this.references;
@@ -182,6 +182,19 @@ Only one transformation is applied to a statement at a time, so multiple steps m
182
182
  }
183
183
  return this.graph.listMainForInclude(filename);
184
184
  }
185
+ containsError(highObj) {
186
+ for (const file of highObj.getABAPFiles()) {
187
+ for (const statement of file.getStatements()) {
188
+ if (statement.get() instanceof _statement_1.Unknown) {
189
+ return true; // contains parser errors
190
+ }
191
+ }
192
+ if (file.getStructure() === undefined) {
193
+ return true;
194
+ }
195
+ }
196
+ return false;
197
+ }
185
198
  run(lowObj) {
186
199
  var _a;
187
200
  const ret = [];
@@ -198,6 +211,9 @@ Only one transformation is applied to a statement at a time, so multiple steps m
198
211
  return ret;
199
212
  }
200
213
  let highSyntaxObj = highObj;
214
+ if (this.containsError(highObj)) {
215
+ return ret;
216
+ }
201
217
  // for includes do the syntax check via a main program
202
218
  if (lowObj instanceof objects_1.Program && lowObj.isInclude()) {
203
219
  const mains = this.listMainForInclude((_a = lowObj.getMainABAPFile()) === null || _a === void 0 ? void 0 : _a.getFilename());
@@ -2395,6 +2411,11 @@ ${indentation} output = ${topTarget}.`;
2395
2411
  if (chain === undefined) {
2396
2412
  continue;
2397
2413
  }
2414
+ const concat = chain.concatTokens().toUpperCase();
2415
+ if (concat.startsWith("LINE_EXISTS( ") || concat.startsWith("LINE_INDEX( ")) {
2416
+ // these are handled separately
2417
+ continue;
2418
+ }
2398
2419
  let predicate = false;
2399
2420
  const spag = highSyntax.spaghetti.lookupPosition(high.getFirstToken().getStart(), lowFile.getFilename());
2400
2421
  for (const r of (spag === null || spag === void 0 ? void 0 : spag.getData().references) || []) {
@@ -2511,6 +2532,9 @@ ${indentation} output = ${topTarget}.`;
2511
2532
  if (node.get() instanceof statements_1.ElseIf) {
2512
2533
  // assumption: no side effects in IF conditions
2513
2534
  insertAt = this.findStartOfIf(node, highFile);
2535
+ if (insertAt === undefined) {
2536
+ continue;
2537
+ }
2514
2538
  }
2515
2539
  const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, insertAt, code);
2516
2540
  const start = expression.getFirstToken().getStart();
@@ -2523,14 +2547,15 @@ ${indentation} output = ${topTarget}.`;
2523
2547
  return undefined;
2524
2548
  }
2525
2549
  findStartOfIf(node, highFile) {
2526
- var _a;
2527
2550
  const structure = highFile.getStructure();
2528
2551
  for (const c of (structure === null || structure === void 0 ? void 0 : structure.findAllStructuresRecursive(Structures.If)) || []) {
2529
- if (((_a = c.findDirectStructure(Structures.ElseIf)) === null || _a === void 0 ? void 0 : _a.getFirstStatement()) === node) {
2530
- return c.getFirstToken().getStart();
2552
+ for (const ei of c.findDirectStructures(Structures.ElseIf)) {
2553
+ if (ei.getFirstStatement() === node) {
2554
+ return c.getFirstToken().getStart();
2555
+ }
2531
2556
  }
2532
2557
  }
2533
- return node.getFirstToken().getStart();
2558
+ return undefined;
2534
2559
  }
2535
2560
  newToCreateObject(low, high, lowFile, highSyntax) {
2536
2561
  if (!(low.get() instanceof _statement_1.Unknown)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.95.40",
3
+ "version": "2.95.42",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",
@@ -50,7 +50,7 @@
50
50
  "@microsoft/api-extractor": "^7.34.4",
51
51
  "@types/chai": "^4.3.4",
52
52
  "@types/mocha": "^10.0.1",
53
- "@types/node": "^18.15.0",
53
+ "@types/node": "^18.15.1",
54
54
  "chai": "^4.3.7",
55
55
  "eslint": "^8.36.0",
56
56
  "mocha": "^10.2.0",