@abaplint/core 2.103.9 → 2.104.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.
@@ -6,9 +6,11 @@ const tokens_1 = require("../../1_lexer/tokens");
6
6
  const source_1 = require("./source");
7
7
  const dynamic_1 = require("./dynamic");
8
8
  const field_1 = require("./field");
9
+ const simple_source3_1 = require("./simple_source3");
10
+ const version_1 = require("../../../version");
9
11
  class AssignSource extends combi_1.Expression {
10
12
  getRunnable() {
11
- const component = (0, combi_1.seq)("COMPONENT", source_1.Source, "OF STRUCTURE", source_1.Source);
13
+ const component = (0, combi_1.seq)("COMPONENT", (0, combi_1.alt)(simple_source3_1.SimpleSource3, (0, combi_1.ver)(version_1.Version.v740sp02, source_1.Source)), "OF STRUCTURE", source_1.Source);
12
14
  const tableField = (0, combi_1.seq)("TABLE FIELD", (0, combi_1.alt)(source_1.Source, dynamic_1.Dynamic));
13
15
  const arrow = (0, combi_1.alt)((0, combi_1.tok)(tokens_1.InstanceArrow), (0, combi_1.tok)(tokens_1.StaticArrow));
14
16
  const source = (0, combi_1.alt)((0, combi_1.seq)(source_1.Source, (0, combi_1.opt)((0, combi_1.seq)(arrow, dynamic_1.Dynamic))), component, tableField, (0, combi_1.seq)(dynamic_1.Dynamic, (0, combi_1.opt)((0, combi_1.seq)(arrow, (0, combi_1.alt)(field_1.Field, dynamic_1.Dynamic)))));
@@ -11,7 +11,7 @@ class Assign {
11
11
  runSyntax(node, scope, filename) {
12
12
  var _a;
13
13
  const assignSource = node.findDirectExpression(Expressions.AssignSource);
14
- const sources = (assignSource === null || assignSource === void 0 ? void 0 : assignSource.findDirectExpressions(Expressions.Source)) || [];
14
+ const sources = (assignSource === null || assignSource === void 0 ? void 0 : assignSource.findDirectExpressionsMulti([Expressions.Source, Expressions.SimpleSource3])) || [];
15
15
  const theSource = sources[sources.length - 1];
16
16
  let sourceType = undefined;
17
17
  const firstAssign = assignSource === null || assignSource === void 0 ? void 0 : assignSource.getChildren()[0];
@@ -65,7 +65,7 @@ class Registry {
65
65
  }
66
66
  static abaplintVersion() {
67
67
  // magic, see build script "version.sh"
68
- return "2.103.9";
68
+ return "2.104.0";
69
69
  }
70
70
  getDDICReferences() {
71
71
  return this.ddicReferences;
@@ -129,6 +129,7 @@ __exportStar(require("./prefer_returning_to_exporting"), exports);
129
129
  __exportStar(require("./prefer_xsdbool"), exports);
130
130
  __exportStar(require("./preferred_compare_operator"), exports);
131
131
  __exportStar(require("./prefix_is_current_class"), exports);
132
+ __exportStar(require("./reduce_procedural_code"), exports);
132
133
  __exportStar(require("./reduce_string_templates"), exports);
133
134
  __exportStar(require("./release_idoc"), exports);
134
135
  __exportStar(require("./remove_descriptions"), exports);
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReduceProceduralCode = exports.ReduceProceduralCodeConf = void 0;
4
+ const _basic_rule_config_1 = require("./_basic_rule_config");
5
+ const _abap_rule_1 = require("./_abap_rule");
6
+ const _irule_1 = require("./_irule");
7
+ const Statements = require("../abap/2_statements/statements");
8
+ const issue_1 = require("../issue");
9
+ class ReduceProceduralCodeConf extends _basic_rule_config_1.BasicRuleConfig {
10
+ constructor() {
11
+ super(...arguments);
12
+ this.maxStatements = 10;
13
+ }
14
+ }
15
+ exports.ReduceProceduralCodeConf = ReduceProceduralCodeConf;
16
+ class ReduceProceduralCode extends _abap_rule_1.ABAPRule {
17
+ constructor() {
18
+ super(...arguments);
19
+ this.conf = new ReduceProceduralCodeConf();
20
+ }
21
+ getMetadata() {
22
+ return {
23
+ key: "reduce_procedural_code",
24
+ title: "Reduce procedural code",
25
+ shortDescription: `Checks FORM and FUNCTION-MODULE have few statements`,
26
+ extendedInformation: `Delegate logic to a class method instead of using FORM or FUNCTION-MODULE.
27
+
28
+ Only one issue is reported per include/file.
29
+
30
+ https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#prefer-object-orientation-to-procedural-programming`,
31
+ tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Styleguide],
32
+ badExample: `FORM foo.
33
+ DATA lv_bar TYPE i.
34
+ lv_bar = 2 + 2.
35
+ IF lv_bar = 4.
36
+ WRITE 'hello world'.
37
+ ENDIF.
38
+ DATA lv_bar TYPE i.
39
+ lv_bar = 2 + 2.
40
+ IF lv_bar = 4.
41
+ WRITE 'hello world'.
42
+ ENDIF.
43
+ ENDFORM.`,
44
+ goodExample: `FORM foo.
45
+ NEW zcl_global_class( )->run_logic( ).
46
+ ENDFORM.`,
47
+ };
48
+ }
49
+ getConfig() {
50
+ return this.conf;
51
+ }
52
+ setConfig(conf) {
53
+ this.conf = conf;
54
+ }
55
+ runParsed(file) {
56
+ const issues = [];
57
+ if (file.getStructure() === undefined) {
58
+ // constains syntax errors, skip this check
59
+ return issues;
60
+ }
61
+ let doCount = undefined;
62
+ let count = 0;
63
+ for (const statement of file.getStatements()) {
64
+ if (statement.get() instanceof Statements.Form || statement.get() instanceof Statements.FunctionModule) {
65
+ doCount = statement;
66
+ count = 0;
67
+ }
68
+ else if (statement.get() instanceof Statements.EndForm || statement.get() instanceof Statements.EndFunction) {
69
+ if (count >= this.conf.maxStatements && doCount !== undefined) {
70
+ const message = "Reduce procedural code, max " + this.conf.maxStatements + " statements";
71
+ const issue = issue_1.Issue.atStatement(file, doCount, message, this.getMetadata().key, this.conf.severity);
72
+ issues.push(issue);
73
+ }
74
+ doCount = undefined;
75
+ }
76
+ else if (doCount !== undefined) {
77
+ count = count + 1;
78
+ }
79
+ }
80
+ return issues;
81
+ }
82
+ }
83
+ exports.ReduceProceduralCode = ReduceProceduralCode;
84
+ //# sourceMappingURL=reduce_procedural_code.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.103.9",
3
+ "version": "2.104.0",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",
@@ -53,13 +53,13 @@
53
53
  "@microsoft/api-extractor": "^7.38.3",
54
54
  "@types/chai": "^4.3.11",
55
55
  "@types/mocha": "^10.0.6",
56
- "@types/node": "^20.9.4",
56
+ "@types/node": "^20.10.1",
57
57
  "chai": "^4.3.10",
58
58
  "eslint": "^8.54.0",
59
59
  "mocha": "^10.2.0",
60
60
  "c8": "^8.0.1",
61
61
  "source-map-support": "^0.5.21",
62
- "ts-json-schema-generator": "^1.4.0",
62
+ "ts-json-schema-generator": "^1.4.1",
63
63
  "typescript": "^5.3.2"
64
64
  },
65
65
  "dependencies": {