@abaplint/core 2.120.58 → 2.120.60
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/abap/2_statements/expressions/method_def_exceptions.js +3 -1
- package/build/src/abap/2_statements/expressions/method_def_raising.js +3 -1
- package/build/src/abap/2_statements/statements/method_def.js +1 -1
- package/build/src/abap/2_statements/statements/method_implementation.js +2 -1
- package/build/src/abap/5_syntax/expressions/source.js +5 -0
- package/build/src/abap/5_syntax/statements/create_data.js +13 -1
- package/build/src/abap/5_syntax/statements/create_object.js +5 -0
- package/build/src/registry.js +1 -1
- package/build/src/rules/abapdoc.js +4 -3
- package/build/src/rules/index.js +2 -0
- package/build/src/rules/unnecessary_loop_guard.js +135 -0
- package/build/src/rules/use_message_class.js +87 -0
- package/package.json +1 -1
|
@@ -5,7 +5,9 @@ const combi_1 = require("../combi");
|
|
|
5
5
|
const _1 = require(".");
|
|
6
6
|
class MethodDefExceptions extends combi_1.Expression {
|
|
7
7
|
getRunnable() {
|
|
8
|
-
|
|
8
|
+
// parameter section keywords cannot be exception names
|
|
9
|
+
const name = (0, combi_1.seq)((0, combi_1.stopBefore1)("IMPORTING", "EXPORTING", "CHANGING", "RETURNING", "RAISING", "EXCEPTIONS"), _1.NamespaceSimpleName);
|
|
10
|
+
const exceptions = (0, combi_1.seq)("EXCEPTIONS", (0, combi_1.plusPrio)(name));
|
|
9
11
|
return exceptions;
|
|
10
12
|
}
|
|
11
13
|
}
|
|
@@ -7,7 +7,9 @@ const class_name_1 = require("./class_name");
|
|
|
7
7
|
class MethodDefRaising extends combi_1.Expression {
|
|
8
8
|
getRunnable() {
|
|
9
9
|
const resumable = (0, combi_1.seq)("RESUMABLE", (0, combi_1.tok)(tokens_1.ParenLeft), class_name_1.ClassName, (0, combi_1.tok)(tokens_1.ParenRightW));
|
|
10
|
-
|
|
10
|
+
// parameter section keywords cannot be exception names
|
|
11
|
+
const name = (0, combi_1.seq)((0, combi_1.stopBefore1)("IMPORTING", "EXPORTING", "CHANGING", "RETURNING", "RAISING", "EXCEPTIONS"), class_name_1.ClassName);
|
|
12
|
+
const raising = (0, combi_1.seq)("RAISING", (0, combi_1.plus)((0, combi_1.altPrio)(resumable, name)));
|
|
11
13
|
return raising;
|
|
12
14
|
}
|
|
13
15
|
}
|
|
@@ -26,7 +26,7 @@ class MethodDef {
|
|
|
26
26
|
(0, combi_1.seq)("VALIDATE ON SAVE IMPORTING", expressions_1.MethodParamName, "FOR", expressions_1.TypeName), (0, combi_1.seq)("MODIFY", (0, combi_1.opt)("IMPORTING"), (0, combi_1.plus)((0, combi_1.seq)(expressions_1.MethodParamName, modify))), (0, combi_1.seq)("PRECHECK IMPORTING", expressions_1.MethodParamName, modify), (0, combi_1.seq)("DETERMINATION", expressions_1.TypeName, "IMPORTING", expressions_1.MethodParamName, "FOR", expressions_1.TypeName), (0, combi_1.seq)("VALIDATION", expressions_1.TypeName, "IMPORTING", expressions_1.MethodParamName, "FOR", expressions_1.TypeName), (0, combi_1.seq)("NUMBERING IMPORTING", expressions_1.MethodParamName, modify), (0, combi_1.seq)("READ IMPORTING", expressions_1.MethodParamName, (0, combi_1.altPrio)(forRead, forfunction)), (0, combi_1.seq)("FEATURES IMPORTING", expressions_1.MethodParamName, "REQUEST", expressions_1.NamespaceSimpleName, "FOR", expressions_1.NamespaceSimpleName, result), (0, combi_1.seq)("BEHAVIOR IMPORTING", expressions_1.MethodParamName, "FOR CREATE", expressions_1.TypeName, expressions_1.MethodParamName, "FOR UPDATE", expressions_1.TypeName, expressions_1.MethodParamName, "FOR DELETE", expressions_1.TypeName), (0, combi_1.seq)("BEHAVIOR IMPORTING", expressions_1.MethodParamName, "FOR READ", expressions_1.TypeName, result), (0, combi_1.seq)("BEHAVIOR IMPORTING", expressions_1.MethodParamName, "FOR UPDATE", expressions_1.TypeName), (0, combi_1.seq)((0, combi_1.alt)("BEHAVIOR", "LOCK"), "IMPORTING", expressions_1.MethodParamName, "FOR LOCK", expressions_1.TypeName), (0, combi_1.seq)("DETERMINE", (0, combi_1.alt)("ON MODIFY", "ON SAVE"), "IMPORTING", expressions_1.MethodParamName, "FOR", expressions_1.TypeName), (0, combi_1.seq)("GLOBAL AUTHORIZATION IMPORTING REQUEST", expressions_1.MethodParamName, "FOR", expressions_1.TypeName, result), (0, combi_1.seq)("GLOBAL FEATURES IMPORTING REQUEST", expressions_1.MethodParamName, "FOR", expressions_1.TypeName, result), (0, combi_1.seq)((0, combi_1.seq)((0, combi_1.opt)("INSTANCE"), "AUTHORIZATION IMPORTING"), expressions_1.MethodParamName, "REQUEST", expressions_1.MethodParamName, "FOR", expressions_1.TypeName, result), (0, combi_1.seq)("INSTANCE FEATURES IMPORTING", expressions_1.MethodParamName, "REQUEST", expressions_1.MethodParamName, "FOR", expressions_1.TypeName, result));
|
|
27
27
|
// todo, this is only from version something
|
|
28
28
|
// AMDP OPTIONS clause blocked in KeyUser
|
|
29
|
-
const amdp = (0, combi_1.verNotLang)(version_1.LanguageVersion.KeyUser, (0, combi_1.seq)("AMDP OPTIONS", (0, combi_1.
|
|
29
|
+
const amdp = (0, combi_1.verNotLang)(version_1.LanguageVersion.KeyUser, (0, combi_1.seq)("AMDP OPTIONS", (0, combi_1.per)("READ-ONLY", (0, combi_1.seq)("CDS SESSION CLIENT", (0, combi_1.alt)("CURRENT", "DEPENDENT"))), (0, combi_1.optPrio)(expressions_1.MethodDefImporting), (0, combi_1.optPrio)(expressions_1.MethodDefExporting), (0, combi_1.optPrio)(expressions_1.MethodDefRaising)));
|
|
30
30
|
// FOR DDL OBJECT / FOR TABLE FUNCTION / FOR SCALAR FUNCTION blocked in KeyUser
|
|
31
31
|
const regular = (0, combi_1.seq)((0, combi_1.altPrio)("CLASS-METHODS", "METHODS"), expressions_1.MethodName, (0, combi_1.alt)((0, combi_1.seq)((0, combi_1.optPrio)(expressions_1.Abstract), (0, combi_1.optPrio)(def), expressions_1.EventHandler), parameters, testing, (0, combi_1.verNotLang)(version_1.LanguageVersion.KeyUser, (0, combi_1.seq)("FOR", behavior)), amdp, "NOT AT END OF MODE", (0, combi_1.optPrio)(expressions_1.Redefinition)));
|
|
32
32
|
// RAP event handlers are instance methods; CLASS-METHODS is not allowed.
|
|
@@ -9,7 +9,8 @@ class MethodImplementation {
|
|
|
9
9
|
const name = (0, combi_1.regex)(/[\w~]+/);
|
|
10
10
|
const kernel = (0, combi_1.seq)("KERNEL MODULE", (0, combi_1.plus)(name), (0, combi_1.optPrio)((0, combi_1.altPrio)("FAIL", "IGNORE")));
|
|
11
11
|
const using = (0, combi_1.seq)("USING", (0, combi_1.plus)(expressions_1.SimpleFieldChain));
|
|
12
|
-
const
|
|
12
|
+
const options = (0, combi_1.seq)("OPTIONS", (0, combi_1.per)("READ-ONLY", "SUPPRESS SYNTAX ERRORS", "DETERMINISTIC"));
|
|
13
|
+
const database = (0, combi_1.seq)("DATABASE", (0, combi_1.alt)("PROCEDURE", "FUNCTION", "GRAPH WORKSPACE"), "FOR HDB", expressions_1.Language, (0, combi_1.opt)(options), (0, combi_1.opt)(using));
|
|
13
14
|
// BY DATABASE and BY KERNEL both blocked in KeyUser
|
|
14
15
|
const by = (0, combi_1.verNotLang)(version_1.LanguageVersion.KeyUser, (0, combi_1.seq)("BY", (0, combi_1.alt)(kernel, database)));
|
|
15
16
|
return (0, combi_1.seq)("METHOD", expressions_1.MethodName, (0, combi_1.optPrio)(by));
|
|
@@ -162,6 +162,11 @@ class Source {
|
|
|
162
162
|
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
|
|
163
163
|
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
|
|
164
164
|
}
|
|
165
|
+
if ((foundType === null || foundType === void 0 ? void 0 : foundType.isGeneric()) && bodyType !== undefined) {
|
|
166
|
+
this.addIfInferred(node, input, bodyType);
|
|
167
|
+
this.traverseRemainingChildren(children, input);
|
|
168
|
+
return bodyType;
|
|
169
|
+
}
|
|
165
170
|
this.addIfInferred(node, input, foundType);
|
|
166
171
|
this.traverseRemainingChildren(children, input);
|
|
167
172
|
return foundType;
|
|
@@ -42,10 +42,22 @@ const basic_types_1 = require("../basic_types");
|
|
|
42
42
|
const basic_1 = require("../../types/basic");
|
|
43
43
|
const _typed_identifier_1 = require("../../types/_typed_identifier");
|
|
44
44
|
const _reference_1 = require("../_reference");
|
|
45
|
+
const _syntax_input_1 = require("../_syntax_input");
|
|
45
46
|
class CreateData {
|
|
46
47
|
runSyntax(node, input) {
|
|
48
|
+
const likeLineOf = node.concatTokens().toUpperCase().includes(" LIKE LINE OF ");
|
|
47
49
|
for (const s of node.findDirectExpressions(Expressions.Source)) {
|
|
48
|
-
source_1.Source.runSyntax(s, input);
|
|
50
|
+
const sourceType = source_1.Source.runSyntax(s, input);
|
|
51
|
+
if (likeLineOf === true
|
|
52
|
+
&& sourceType !== undefined
|
|
53
|
+
&& !(sourceType instanceof basic_1.TableType)
|
|
54
|
+
&& !(sourceType instanceof basic_1.VoidType)
|
|
55
|
+
&& !(sourceType instanceof basic_1.UnknownType)
|
|
56
|
+
&& !(sourceType instanceof basic_1.AnyType)) {
|
|
57
|
+
const message = `"${s.concatTokens()}" is not an internal table`;
|
|
58
|
+
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
49
61
|
}
|
|
50
62
|
for (const t of node.findDirectExpressions(Expressions.Target)) {
|
|
51
63
|
target_1.Target.runSyntax(t, input);
|
|
@@ -141,6 +141,11 @@ class CreateObject {
|
|
|
141
141
|
ooName = found.getVoided();
|
|
142
142
|
}
|
|
143
143
|
input.scope.addReference(t === null || t === void 0 ? void 0 : t.getFirstToken(), cdef, _reference_1.ReferenceType.ConstructorReference, input.filename, { ooName: ooName });
|
|
144
|
+
if (type && type.get() instanceof Expressions.Dynamic) {
|
|
145
|
+
// the class is only known at runtime, cdef is the static type of the target
|
|
146
|
+
this.validateParameters(undefined, node, input);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
144
149
|
if (cdef !== undefined) {
|
|
145
150
|
const err = CreateObject.checkInstantiationAllowed(cdef, input);
|
|
146
151
|
if (err) {
|
package/build/src/registry.js
CHANGED
|
@@ -110,12 +110,13 @@ https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#abap-doc-on
|
|
|
110
110
|
return issues;
|
|
111
111
|
}
|
|
112
112
|
getAbapdoc(rows, pos) {
|
|
113
|
+
var _a, _b, _c;
|
|
113
114
|
let previousRow = pos.getRow() - 2;
|
|
114
|
-
let rowText = rows[previousRow].trim().toUpperCase();
|
|
115
|
+
let rowText = ((_a = rows[previousRow]) !== null && _a !== void 0 ? _a : "").trim().toUpperCase();
|
|
115
116
|
const text = [];
|
|
116
117
|
if (rowText === "METHODS" || rowText === "CLASS-METHODS") {
|
|
117
118
|
previousRow--;
|
|
118
|
-
rowText = rows[previousRow].trim().toUpperCase();
|
|
119
|
+
rowText = ((_b = rows[previousRow]) !== null && _b !== void 0 ? _b : "").trim().toUpperCase();
|
|
119
120
|
}
|
|
120
121
|
text.push(rowText);
|
|
121
122
|
//we need to push the first row despite if it is actually an abapdoc or not
|
|
@@ -123,7 +124,7 @@ https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#abap-doc-on
|
|
|
123
124
|
if (rowText.trim().substring(0, 2) === "\"!") {
|
|
124
125
|
while (previousRow >= 0) {
|
|
125
126
|
previousRow--;
|
|
126
|
-
rowText = rows[previousRow].trim().toUpperCase();
|
|
127
|
+
rowText = ((_c = rows[previousRow]) !== null && _c !== void 0 ? _c : "").trim().toUpperCase();
|
|
127
128
|
if (rowText.trim().substring(0, 2) !== "\"!") {
|
|
128
129
|
break;
|
|
129
130
|
}
|
package/build/src/rules/index.js
CHANGED
|
@@ -191,6 +191,7 @@ __exportStar(require("./types_naming"), exports);
|
|
|
191
191
|
__exportStar(require("./uncaught_exception"), exports);
|
|
192
192
|
__exportStar(require("./unknown_types"), exports);
|
|
193
193
|
__exportStar(require("./unnecessary_chaining"), exports);
|
|
194
|
+
__exportStar(require("./unnecessary_loop_guard"), exports);
|
|
194
195
|
__exportStar(require("./unnecessary_pragma"), exports);
|
|
195
196
|
__exportStar(require("./unnecessary_return"), exports);
|
|
196
197
|
__exportStar(require("./unreachable_code"), exports);
|
|
@@ -203,6 +204,7 @@ __exportStar(require("./unused_variables"), exports);
|
|
|
203
204
|
__exportStar(require("./use_bool_expression"), exports);
|
|
204
205
|
__exportStar(require("./use_class_based_exceptions"), exports);
|
|
205
206
|
__exportStar(require("./use_line_exists"), exports);
|
|
207
|
+
__exportStar(require("./use_message_class"), exports);
|
|
206
208
|
__exportStar(require("./use_new"), exports);
|
|
207
209
|
__exportStar(require("./when_others_last"), exports);
|
|
208
210
|
__exportStar(require("./whitespace_end"), exports);
|
|
@@ -0,0 +1,135 @@
|
|
|
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.UnnecessaryLoopGuard = exports.UnnecessaryLoopGuardConf = void 0;
|
|
37
|
+
const issue_1 = require("../issue");
|
|
38
|
+
const Expressions = __importStar(require("../abap/2_statements/expressions"));
|
|
39
|
+
const Statements = __importStar(require("../abap/2_statements/statements"));
|
|
40
|
+
const Structures = __importStar(require("../abap/3_structures/structures"));
|
|
41
|
+
const _abap_rule_1 = require("./_abap_rule");
|
|
42
|
+
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
43
|
+
const _irule_1 = require("./_irule");
|
|
44
|
+
const edit_helper_1 = require("../edit_helper");
|
|
45
|
+
class UnnecessaryLoopGuardConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
46
|
+
}
|
|
47
|
+
exports.UnnecessaryLoopGuardConf = UnnecessaryLoopGuardConf;
|
|
48
|
+
class UnnecessaryLoopGuard extends _abap_rule_1.ABAPRule {
|
|
49
|
+
constructor() {
|
|
50
|
+
super(...arguments);
|
|
51
|
+
this.conf = new UnnecessaryLoopGuardConf();
|
|
52
|
+
}
|
|
53
|
+
getMetadata() {
|
|
54
|
+
return {
|
|
55
|
+
key: "unnecessary_loop_guard",
|
|
56
|
+
title: "Unnecessary loop guard",
|
|
57
|
+
shortDescription: `Detects unnecessary IS [NOT] INITIAL check before LOOP AT`,
|
|
58
|
+
extendedInformation: `LOOP AT iterates zero times on an empty table, so an IS [NOT] INITIAL guard is redundant.`,
|
|
59
|
+
tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Styleguide, _irule_1.RuleTag.Quickfix],
|
|
60
|
+
badExample: `IF lt_data IS NOT INITIAL.
|
|
61
|
+
LOOP AT lt_data INTO DATA(ls_item).
|
|
62
|
+
WRITE ls_item-name.
|
|
63
|
+
ENDLOOP.
|
|
64
|
+
ENDIF.`,
|
|
65
|
+
goodExample: `LOOP AT lt_data INTO DATA(ls_item).
|
|
66
|
+
WRITE ls_item-name.
|
|
67
|
+
ENDLOOP.`,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
getConfig() {
|
|
71
|
+
return this.conf;
|
|
72
|
+
}
|
|
73
|
+
setConfig(conf) {
|
|
74
|
+
this.conf = conf;
|
|
75
|
+
}
|
|
76
|
+
runParsed(file) {
|
|
77
|
+
const issues = [];
|
|
78
|
+
const stru = file.getStructure();
|
|
79
|
+
if (stru === undefined) {
|
|
80
|
+
return issues;
|
|
81
|
+
}
|
|
82
|
+
for (const ifStru of stru.findAllStructuresRecursive(Structures.If)) {
|
|
83
|
+
if (ifStru.findDirectStructures(Structures.ElseIf).length > 0
|
|
84
|
+
|| ifStru.findDirectStructures(Structures.Else).length > 0) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const ifStatement = ifStru.findDirectStatement(Statements.If);
|
|
88
|
+
if (ifStatement === undefined) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const cond = ifStatement.findDirectExpression(Expressions.Cond);
|
|
92
|
+
if (cond === undefined) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const compareNodes = cond.findDirectExpressions(Expressions.Compare);
|
|
96
|
+
if (compareNodes.length !== 1) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const m = compareNodes[0].concatTokens().toUpperCase().match(/^(.+?)\s+IS\s+(?:NOT\s+)?INITIAL\s*$/);
|
|
100
|
+
if (!m) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const tableName = m[1];
|
|
104
|
+
const bodyStructures = ifStru.findDirectStructures(Structures.Body);
|
|
105
|
+
if (bodyStructures.length !== 1) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const normalStructures = bodyStructures[0].findDirectStructures(Structures.Normal);
|
|
109
|
+
if (normalStructures.length !== 1) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const loopStructures = normalStructures[0].findDirectStructures(Structures.Loop);
|
|
113
|
+
if (loopStructures.length !== 1) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const loopStatement = loopStructures[0].findDirectStatement(Statements.Loop);
|
|
117
|
+
if (loopStatement === undefined) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const loopSource = loopStatement.findFirstExpression(Expressions.LoopSource);
|
|
121
|
+
if (loopSource === undefined) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (loopSource.concatTokens().toUpperCase() !== tableName) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const endifStatement = ifStru.findDirectStatement(Statements.EndIf);
|
|
128
|
+
const fix = edit_helper_1.EditHelper.merge(edit_helper_1.EditHelper.deleteStatement(file, ifStatement), edit_helper_1.EditHelper.deleteStatement(file, endifStatement));
|
|
129
|
+
issues.push(issue_1.Issue.atStatement(file, ifStatement, "Unnecessary IS [NOT] INITIAL check before LOOP AT", this.getMetadata().key, this.conf.severity, fix));
|
|
130
|
+
}
|
|
131
|
+
return issues;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.UnnecessaryLoopGuard = UnnecessaryLoopGuard;
|
|
135
|
+
//# sourceMappingURL=unnecessary_loop_guard.js.map
|
|
@@ -0,0 +1,87 @@
|
|
|
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.UseMessageClass = exports.UseMessageClassConf = void 0;
|
|
37
|
+
const issue_1 = require("../issue");
|
|
38
|
+
const _abap_rule_1 = require("./_abap_rule");
|
|
39
|
+
const Expressions = __importStar(require("../abap/2_statements/expressions"));
|
|
40
|
+
const Statements = __importStar(require("../abap/2_statements/statements"));
|
|
41
|
+
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
42
|
+
const _irule_1 = require("./_irule");
|
|
43
|
+
class UseMessageClassConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
44
|
+
}
|
|
45
|
+
exports.UseMessageClassConf = UseMessageClassConf;
|
|
46
|
+
class UseMessageClass extends _abap_rule_1.ABAPRule {
|
|
47
|
+
constructor() {
|
|
48
|
+
super(...arguments);
|
|
49
|
+
this.conf = new UseMessageClassConf();
|
|
50
|
+
}
|
|
51
|
+
getMetadata() {
|
|
52
|
+
return {
|
|
53
|
+
key: "use_message_class",
|
|
54
|
+
title: "Use message class",
|
|
55
|
+
shortDescription: `Define messages in SE91 instead of using inline text or variables`,
|
|
56
|
+
tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile],
|
|
57
|
+
badExample: `MESSAGE 'Something went wrong' TYPE 'E'.`,
|
|
58
|
+
goodExample: `MESSAGE e001(bc_msg).`,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
getConfig() {
|
|
62
|
+
return this.conf;
|
|
63
|
+
}
|
|
64
|
+
setConfig(conf) {
|
|
65
|
+
this.conf = conf;
|
|
66
|
+
}
|
|
67
|
+
runParsed(file, _obj) {
|
|
68
|
+
const structure = file.getStructure();
|
|
69
|
+
if (structure === undefined) {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
const issues = [];
|
|
73
|
+
const key = this.getMetadata().key;
|
|
74
|
+
for (const statement of structure.findAllStatements(Statements.Message)) {
|
|
75
|
+
// The parser populates MessageSource only for the class-based forms (e001(bc_msg) or ID/TYPE/NUMBER).
|
|
76
|
+
// The text form (MESSAGE <source> TYPE <source>) uses MessageSourceSource directly with no MessageSource child.
|
|
77
|
+
// Absence of MessageSource is therefore a reliable discriminator between the two forms.
|
|
78
|
+
if (statement.findDirectExpression(Expressions.MessageSource) !== undefined) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
issues.push(issue_1.Issue.atStatement(file, statement, "Use a message class (SE91) instead of inline text or variable", key, this.conf.severity));
|
|
82
|
+
}
|
|
83
|
+
return issues;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.UseMessageClass = UseMessageClass;
|
|
87
|
+
//# sourceMappingURL=use_message_class.js.map
|