@abaplint/core 2.103.10 → 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.
package/build/src/registry.js
CHANGED
package/build/src/rules/index.js
CHANGED
|
@@ -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.
|
|
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,7 +53,7 @@
|
|
|
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.10.
|
|
56
|
+
"@types/node": "^20.10.1",
|
|
57
57
|
"chai": "^4.3.10",
|
|
58
58
|
"eslint": "^8.54.0",
|
|
59
59
|
"mocha": "^10.2.0",
|