@abaplint/core 2.119.40 → 2.119.41

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.
@@ -2870,6 +2870,11 @@ declare class FormDefinition_2 extends Identifier implements IFormDefinition {
2870
2870
  private findParams;
2871
2871
  }
2872
2872
 
2873
+ export declare class FormLengthStats {
2874
+ static run(obj: IObject): IMethodLengthResult[];
2875
+ private static findName;
2876
+ }
2877
+
2873
2878
  declare class FormName extends Expression {
2874
2879
  getRunnable(): IStatementRunnable;
2875
2880
  }
@@ -2968,6 +2973,11 @@ declare class FunctionGroup extends ABAPObject {
2968
2973
  private findTextFile;
2969
2974
  }
2970
2975
 
2976
+ export declare class FunctionLengthStats {
2977
+ static run(obj: IObject): IMethodLengthResult[];
2978
+ private static findName;
2979
+ }
2980
+
2971
2981
  declare class FunctionModule implements IStructure {
2972
2982
  getMatcher(): IStructureRunnable;
2973
2983
  }
@@ -33,8 +33,8 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.Rename = exports.PrettyPrinter = exports.Position = exports.CurrentScope = exports.RulesRunner = exports.SpaghettiScope = exports.SyntaxLogic = exports.ABAPObject = exports.Tokens = exports.ExpressionsCDS = exports.CDSParser = exports.LanguageServerTypes = exports.DDLParser = exports.AbstractFile = exports.ABAPFile = exports.MemoryFile = exports.Edits = exports.ReferenceType = exports.NativeSQL = exports.MacroContent = exports.MacroCall = exports.SpaghettiScopeNode = 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.SkipLogic = exports.Objects = exports.ArtifactsRules = exports.ArtifactsObjects = exports.ArtifactsABAP = exports.BuiltIn = exports.MethodLengthStats = exports.LanguageServer = exports.Registry = exports.CyclomaticComplexityStats = exports.Version = exports.Config = exports.Issue = void 0;
37
- exports.LSPEdit = exports.RuleTag = exports.Severity = exports.Visibility = exports.Info = exports.Diagnostics = void 0;
36
+ exports.Position = exports.CurrentScope = exports.RulesRunner = exports.SpaghettiScope = exports.SyntaxLogic = exports.ABAPObject = exports.Tokens = exports.ExpressionsCDS = exports.CDSParser = exports.LanguageServerTypes = exports.DDLParser = exports.AbstractFile = exports.ABAPFile = exports.MemoryFile = exports.Edits = exports.ReferenceType = exports.NativeSQL = exports.MacroContent = exports.MacroCall = exports.SpaghettiScopeNode = 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.SkipLogic = exports.Objects = exports.ArtifactsRules = exports.ArtifactsObjects = exports.ArtifactsABAP = exports.BuiltIn = exports.FormLengthStats = exports.FunctionLengthStats = exports.MethodLengthStats = exports.LanguageServer = exports.Registry = exports.CyclomaticComplexityStats = exports.Version = exports.Config = exports.Issue = void 0;
37
+ exports.LSPEdit = exports.RuleTag = exports.Severity = exports.Visibility = exports.Info = exports.Diagnostics = exports.Rename = exports.PrettyPrinter = void 0;
38
38
  const issue_1 = require("./issue");
39
39
  Object.defineProperty(exports, "Issue", { enumerable: true, get: function () { return issue_1.Issue; } });
40
40
  const config_1 = require("./config");
@@ -140,6 +140,10 @@ const _edit_1 = require("./lsp/_edit");
140
140
  Object.defineProperty(exports, "LSPEdit", { enumerable: true, get: function () { return _edit_1.LSPEdit; } });
141
141
  const _reference_1 = require("./abap/5_syntax/_reference");
142
142
  Object.defineProperty(exports, "ReferenceType", { enumerable: true, get: function () { return _reference_1.ReferenceType; } });
143
+ const function_length_stats_1 = require("./utils/function_length_stats");
144
+ Object.defineProperty(exports, "FunctionLengthStats", { enumerable: true, get: function () { return function_length_stats_1.FunctionLengthStats; } });
145
+ const form_length_stats_1 = require("./utils/form_length_stats");
146
+ Object.defineProperty(exports, "FormLengthStats", { enumerable: true, get: function () { return form_length_stats_1.FormLengthStats; } });
143
147
  // do not include this file from anywhere within abaplint
144
148
  // https://github.com/abaplint/abaplint/issues/873
145
149
  const Edits = {
@@ -74,7 +74,7 @@ class Registry {
74
74
  }
75
75
  static abaplintVersion() {
76
76
  // magic, see build script "version.js"
77
- return "2.119.40";
77
+ return "2.119.41";
78
78
  }
79
79
  getDDICReferences() {
80
80
  return this.ddicReferences;
@@ -40,17 +40,20 @@ const method_length_stats_1 = require("../utils/method_length_stats");
40
40
  const _irule_1 = require("./_irule");
41
41
  const _basic_rule_config_1 = require("./_basic_rule_config");
42
42
  const form_length_stats_1 = require("../utils/form_length_stats");
43
+ const function_length_stats_1 = require("../utils/function_length_stats");
43
44
  class MethodLengthConf extends _basic_rule_config_1.BasicRuleConfig {
44
45
  constructor() {
45
46
  super(...arguments);
46
- /** Maximum method/form length in statements. */
47
+ /** Maximum method/form/function module length in statements. */
47
48
  this.statements = 100;
48
- /** Checks for empty methods/forms. */
49
+ /** Checks for empty methods/forms/function modules. */
49
50
  this.errorWhenEmpty = true;
50
51
  /** Option to ignore test classes for this check. */
51
52
  this.ignoreTestClasses = false;
52
53
  /** Option to check forms. */
53
54
  this.checkForms = true;
55
+ /** Option to check function modules. */
56
+ this.checkFunctionModules = true;
54
57
  }
55
58
  }
56
59
  exports.MethodLengthConf = MethodLengthConf;
@@ -66,8 +69,8 @@ class MethodLength {
66
69
  getMetadata() {
67
70
  return {
68
71
  key: "method_length",
69
- title: "Method/Form Length",
70
- shortDescription: `Checks relating to method/form length.`,
72
+ title: "Method/Form/Function Module Length",
73
+ shortDescription: `Checks relating to method/form/function module length.`,
71
74
  extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#keep-methods-small
72
75
 
73
76
  Abstract methods without statements are considered okay.`,
@@ -110,7 +113,12 @@ Abstract methods without statements are considered okay.`,
110
113
  const formStats = form_length_stats_1.FormLengthStats.run(obj);
111
114
  formIssues = this.check(formStats, "FORM");
112
115
  }
113
- return methodIssues.concat(formIssues);
116
+ let functionIssues = [];
117
+ if (this.conf.checkFunctionModules) {
118
+ const functionStats = function_length_stats_1.FunctionLengthStats.run(obj);
119
+ functionIssues = this.check(functionStats, "FUNCTION MODULE");
120
+ }
121
+ return methodIssues.concat(formIssues).concat(functionIssues);
114
122
  }
115
123
  // ***********************
116
124
  check(stats, type) {
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.FunctionLengthStats = void 0;
37
+ const Statements = __importStar(require("../abap/2_statements/statements"));
38
+ const Expressions = __importStar(require("../abap/2_statements/expressions"));
39
+ const _abap_object_1 = require("../objects/_abap_object");
40
+ const _statement_1 = require("../abap/2_statements/statements/_statement");
41
+ class FunctionLengthStats {
42
+ static run(obj) {
43
+ const res = [];
44
+ let pos = undefined;
45
+ let name = "";
46
+ let count = 0;
47
+ let func = false;
48
+ if (!(obj instanceof _abap_object_1.ABAPObject)) {
49
+ return [];
50
+ }
51
+ for (const file of obj.getABAPFiles()) {
52
+ for (const stat of file.getStatements()) {
53
+ const type = stat.get();
54
+ if (type instanceof Statements.FunctionModule) {
55
+ pos = stat.getFirstToken().getStart();
56
+ name = this.findName(stat);
57
+ func = true;
58
+ count = 0;
59
+ }
60
+ else if (type instanceof Statements.EndFunction) {
61
+ if (pos) {
62
+ res.push({ name: name, className: "", count, file, pos });
63
+ }
64
+ else {
65
+ continue;
66
+ }
67
+ func = false;
68
+ }
69
+ else if (func === true
70
+ && !(type instanceof _statement_1.Comment)
71
+ && !(type instanceof _statement_1.Empty)) {
72
+ count = count + 1;
73
+ }
74
+ }
75
+ }
76
+ return res;
77
+ }
78
+ static findName(stat) {
79
+ const nameExpr = stat.findFirstExpression(Expressions.Field);
80
+ if (nameExpr) {
81
+ return nameExpr.getFirstToken().getStr();
82
+ }
83
+ else {
84
+ throw new Error("FunctionLength, findName, expected Field");
85
+ }
86
+ }
87
+ }
88
+ exports.FunctionLengthStats = FunctionLengthStats;
89
+ //# sourceMappingURL=function_length_stats.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.119.40",
3
+ "version": "2.119.41",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",
@@ -64,7 +64,7 @@
64
64
  "typescript": "^6.0.3"
65
65
  },
66
66
  "dependencies": {
67
- "fast-xml-parser": "^5.9.0",
67
+ "fast-xml-parser": "^5.9.3",
68
68
  "json5": "^2.2.3",
69
69
  "vscode-languageserver-types": "^3.18.0"
70
70
  }