@abaplint/core 2.120.84 → 2.120.85
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/abaplint.d.ts
CHANGED
|
@@ -2429,7 +2429,6 @@ declare abstract class Expression implements IStatementRunnable {
|
|
|
2429
2429
|
|
|
2430
2430
|
declare class ExpressionNode extends AbstractNode<ExpressionNode | TokenNode> {
|
|
2431
2431
|
private readonly expression;
|
|
2432
|
-
private tokenCount;
|
|
2433
2432
|
constructor(expression: IStatementRunnable);
|
|
2434
2433
|
addChild(_n: ExpressionNode | TokenNode): void;
|
|
2435
2434
|
get(): IStatementRunnable;
|
|
@@ -6402,7 +6401,7 @@ declare class Result {
|
|
|
6402
6401
|
private static fromChain;
|
|
6403
6402
|
peek(): Token;
|
|
6404
6403
|
peekAt(offset: number): Token | undefined;
|
|
6405
|
-
shift(node:
|
|
6404
|
+
shift(node: TokenNode): Result;
|
|
6406
6405
|
wrapConsumed(consumedTokens: number, node: ExpressionNode): Result;
|
|
6407
6406
|
popNode(): ExpressionNode | TokenNode | undefined;
|
|
6408
6407
|
getNodes(): (ExpressionNode | TokenNode)[];
|
|
@@ -25,23 +25,25 @@ class Result {
|
|
|
25
25
|
return this.tokens[this.tokenIndex + offset];
|
|
26
26
|
}
|
|
27
27
|
shift(node) {
|
|
28
|
-
return Result.fromChain(this.tokens, this.tokenIndex + 1, { node, previous: this.nodes }, this.nodeCount + 1);
|
|
28
|
+
return Result.fromChain(this.tokens, this.tokenIndex + 1, { node, tokenCount: 1, previous: this.nodes }, this.nodeCount + 1);
|
|
29
29
|
}
|
|
30
30
|
wrapConsumed(consumedTokens, node) {
|
|
31
31
|
let current = this.nodes;
|
|
32
32
|
let currentCount = this.nodeCount;
|
|
33
|
+
let tokenCount = 0;
|
|
33
34
|
const children = [];
|
|
34
35
|
while (consumedTokens > 0) {
|
|
35
36
|
if (current === undefined) {
|
|
36
37
|
break;
|
|
37
38
|
}
|
|
38
39
|
children.push(current.node);
|
|
39
|
-
consumedTokens = consumedTokens - current.
|
|
40
|
+
consumedTokens = consumedTokens - current.tokenCount;
|
|
41
|
+
tokenCount = tokenCount + current.tokenCount;
|
|
40
42
|
current = current.previous;
|
|
41
43
|
currentCount--;
|
|
42
44
|
}
|
|
43
45
|
node.setChildren(children.reverse());
|
|
44
|
-
this.nodes = { node, previous: current };
|
|
46
|
+
this.nodes = { node, tokenCount, previous: current };
|
|
45
47
|
this.nodeCount = currentCount + 1;
|
|
46
48
|
return this;
|
|
47
49
|
}
|
|
@@ -70,7 +72,7 @@ class Result {
|
|
|
70
72
|
this.nodes = undefined;
|
|
71
73
|
this.nodeCount = 0;
|
|
72
74
|
for (const node of n) {
|
|
73
|
-
this.nodes = { node, previous: this.nodes };
|
|
75
|
+
this.nodes = { node, tokenCount: node.countTokens(), previous: this.nodes };
|
|
74
76
|
this.nodeCount++;
|
|
75
77
|
}
|
|
76
78
|
}
|
|
@@ -7,7 +7,6 @@ const _abstract_node_1 = require("./_abstract_node");
|
|
|
7
7
|
class ExpressionNode extends _abstract_node_1.AbstractNode {
|
|
8
8
|
constructor(expression) {
|
|
9
9
|
super();
|
|
10
|
-
this.tokenCount = 0;
|
|
11
10
|
this.expression = expression;
|
|
12
11
|
}
|
|
13
12
|
addChild(_n) {
|
|
@@ -18,13 +17,15 @@ class ExpressionNode extends _abstract_node_1.AbstractNode {
|
|
|
18
17
|
}
|
|
19
18
|
setChildren(children) {
|
|
20
19
|
super.setChildren(children);
|
|
21
|
-
for (const child of this.getChildren()) {
|
|
22
|
-
this.tokenCount = this.tokenCount + child.countTokens();
|
|
23
|
-
}
|
|
24
20
|
return this;
|
|
25
21
|
}
|
|
22
|
+
// not stored on the node, saves a field per ExpressionNode, the statement parser tracks counts itself
|
|
26
23
|
countTokens() {
|
|
27
|
-
|
|
24
|
+
let count = 0;
|
|
25
|
+
for (const child of this.getChildren()) {
|
|
26
|
+
count = count + child.countTokens();
|
|
27
|
+
}
|
|
28
|
+
return count;
|
|
28
29
|
}
|
|
29
30
|
getFirstToken() {
|
|
30
31
|
for (const child of this.getChildren()) {
|
package/build/src/registry.js
CHANGED
package/build/src/rules/index.js
CHANGED
|
@@ -173,6 +173,7 @@ __exportStar(require("./prefer_pragmas"), exports);
|
|
|
173
173
|
__exportStar(require("./prefer_abap_bool"), exports);
|
|
174
174
|
__exportStar(require("./prefer_abap_bool_values"), exports);
|
|
175
175
|
__exportStar(require("./prefer_raise_exception_new"), exports);
|
|
176
|
+
__exportStar(require("./prefer_raise_message"), exports);
|
|
176
177
|
__exportStar(require("./prefer_string_template"), exports);
|
|
177
178
|
__exportStar(require("./prefer_returning_to_exporting"), exports);
|
|
178
179
|
__exportStar(require("./prefer_xsdbool"), exports);
|
|
@@ -0,0 +1,118 @@
|
|
|
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.PreferRaiseMessage = exports.PreferRaiseMessageConf = void 0;
|
|
37
|
+
const issue_1 = require("../issue");
|
|
38
|
+
const _abap_rule_1 = require("./_abap_rule");
|
|
39
|
+
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
40
|
+
const _irule_1 = require("./_irule");
|
|
41
|
+
const Statements = __importStar(require("../abap/2_statements/statements"));
|
|
42
|
+
const Expressions = __importStar(require("../abap/2_statements/expressions"));
|
|
43
|
+
class PreferRaiseMessageConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
44
|
+
constructor() {
|
|
45
|
+
super(...arguments);
|
|
46
|
+
/** List of exception class names to ignore, case insensitive */
|
|
47
|
+
this.ignoreExceptionClasses = [];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.PreferRaiseMessageConf = PreferRaiseMessageConf;
|
|
51
|
+
class PreferRaiseMessage extends _abap_rule_1.ABAPRule {
|
|
52
|
+
constructor() {
|
|
53
|
+
super(...arguments);
|
|
54
|
+
this.conf = new PreferRaiseMessageConf();
|
|
55
|
+
}
|
|
56
|
+
getMetadata() {
|
|
57
|
+
return {
|
|
58
|
+
key: "prefer_raise_message",
|
|
59
|
+
title: "Prefer RAISE EXCEPTION with MESSAGE",
|
|
60
|
+
shortDescription: `Prefer RAISE EXCEPTION with MESSAGE instead of supplying parameter TEXT`,
|
|
61
|
+
extendedInformation: `Reports RAISE EXCEPTION statements where parameter TEXT is supplied.
|
|
62
|
+
|
|
63
|
+
Use a message class instead, so the text is translatable and can be found via where-used.
|
|
64
|
+
|
|
65
|
+
Exception classes can be excluded via configuration "ignoreExceptionClasses".`,
|
|
66
|
+
tags: [_irule_1.RuleTag.SingleFile],
|
|
67
|
+
goodExample: `RAISE EXCEPTION TYPE zcx_error MESSAGE e001(zclass).`,
|
|
68
|
+
badExample: `RAISE EXCEPTION TYPE zcx_error
|
|
69
|
+
EXPORTING text = 'hello world'.`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
getConfig() {
|
|
73
|
+
return this.conf;
|
|
74
|
+
}
|
|
75
|
+
setConfig(conf) {
|
|
76
|
+
this.conf = conf;
|
|
77
|
+
}
|
|
78
|
+
runParsed(file) {
|
|
79
|
+
var _a, _b, _c, _d;
|
|
80
|
+
var _e;
|
|
81
|
+
const issues = [];
|
|
82
|
+
const ignore = ((_e = this.conf.ignoreExceptionClasses) !== null && _e !== void 0 ? _e : []).map(c => c.toUpperCase());
|
|
83
|
+
for (const statement of file.getStatements()) {
|
|
84
|
+
if (!(statement.get() instanceof Statements.Raise)) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const concat = statement.concatTokens().toUpperCase();
|
|
88
|
+
if (!concat.startsWith("RAISE EXCEPTION ") && !concat.startsWith("RAISE RESUMABLE EXCEPTION ")) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
else if (concat.includes(" MESSAGE")) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
let className;
|
|
95
|
+
let parameters;
|
|
96
|
+
const newObject = (_b = (_a = statement.findDirectExpression(Expressions.Source)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.MethodCallChain)) === null || _b === void 0 ? void 0 : _b.findDirectExpression(Expressions.NewObject);
|
|
97
|
+
if (newObject) {
|
|
98
|
+
className = (_c = newObject.findDirectExpression(Expressions.TypeNameOrInfer)) === null || _c === void 0 ? void 0 : _c.concatTokens();
|
|
99
|
+
parameters = newObject.findDirectExpression(Expressions.ParameterListS);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
className = (_d = statement.findDirectExpression(Expressions.ClassName)) === null || _d === void 0 ? void 0 : _d.concatTokens();
|
|
103
|
+
parameters = statement.findDirectExpression(Expressions.ParameterListS);
|
|
104
|
+
}
|
|
105
|
+
if (className === undefined || ignore.includes(className.toUpperCase())) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const text = parameters === null || parameters === void 0 ? void 0 : parameters.findDirectExpressions(Expressions.ParameterS).find(p => { var _a; return ((_a = p.findDirectExpression(Expressions.ParameterName)) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase()) === "TEXT"; });
|
|
109
|
+
if (text) {
|
|
110
|
+
const message = "Prefer RAISE EXCEPTION with MESSAGE, " + className + " raised with parameter TEXT";
|
|
111
|
+
issues.push(issue_1.Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return issues;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.PreferRaiseMessage = PreferRaiseMessage;
|
|
118
|
+
//# sourceMappingURL=prefer_raise_message.js.map
|