@abaplint/core 2.120.62 → 2.120.64
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/5_syntax/_type_utils.js +1 -0
- package/build/src/abap/5_syntax/basic_types.js +40 -1
- package/build/src/ddic.js +1 -1
- package/build/src/objects/table.js +9 -3
- package/build/src/registry.js +1 -1
- package/build/src/rules/else_after_all_returns.js +162 -0
- package/build/src/rules/index.js +1 -0
- package/build/src/rules/xml_consistency.js +4 -2
- package/package.json +1 -1
|
@@ -509,6 +509,7 @@ class BasicTypes {
|
|
|
509
509
|
}
|
|
510
510
|
parseType(node, qualifiedName) {
|
|
511
511
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
512
|
+
var _l;
|
|
512
513
|
const typeName = node.findFirstExpression(Expressions.TypeName);
|
|
513
514
|
let text = (_a = node.findFirstExpression(Expressions.Type)) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase();
|
|
514
515
|
if (text === undefined) {
|
|
@@ -659,6 +660,9 @@ class BasicTypes {
|
|
|
659
660
|
length = parseInt(int.concatTokens(), 10);
|
|
660
661
|
}
|
|
661
662
|
}
|
|
663
|
+
else if (node.get() instanceof Statements.Parameter) {
|
|
664
|
+
length = (_l = this.findParameterLength(node)) !== null && _l !== void 0 ? _l : length;
|
|
665
|
+
}
|
|
662
666
|
found = new Types.CharacterType(length, { qualifiedName: qualifiedName }); // fallback
|
|
663
667
|
if (this.isOccurs(node)) {
|
|
664
668
|
found = new Types.TableType(found, { withHeader: concat.includes(" WITH HEADER LINE"), keyType: Types.TableKeyType.default }, qualifiedName);
|
|
@@ -1028,11 +1032,43 @@ class BasicTypes {
|
|
|
1028
1032
|
throw new Error("findValue, unexpected");
|
|
1029
1033
|
}
|
|
1030
1034
|
findDecimals(node) {
|
|
1031
|
-
var _a, _b;
|
|
1035
|
+
var _a, _b, _c;
|
|
1032
1036
|
const dec = (_b = (_a = node.findDirectExpression(Expressions.Decimals)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.Integer)) === null || _b === void 0 ? void 0 : _b.concatTokens();
|
|
1033
1037
|
if (dec) {
|
|
1034
1038
|
return parseInt(dec, 10);
|
|
1035
1039
|
}
|
|
1040
|
+
if (node.get() instanceof Statements.Parameter) {
|
|
1041
|
+
// PARAMETERS spells it seq("DECIMALS", Source) instead of the Decimals expression
|
|
1042
|
+
const source = (_c = this.findParameterAddition(node, "DECIMALS")) === null || _c === void 0 ? void 0 : _c.concatTokens();
|
|
1043
|
+
if (source && /^\d+$/.test(source)) {
|
|
1044
|
+
return parseInt(source, 10);
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
return undefined;
|
|
1048
|
+
}
|
|
1049
|
+
// PARAMETERS spells it seq("LENGTH", Constant) instead of the Length expression
|
|
1050
|
+
findParameterLength(node) {
|
|
1051
|
+
const constant = this.findParameterAddition(node, "LENGTH");
|
|
1052
|
+
if (constant === undefined) {
|
|
1053
|
+
return undefined;
|
|
1054
|
+
}
|
|
1055
|
+
const length = this.parseInt(constant.concatTokens());
|
|
1056
|
+
return length === undefined || isNaN(length) ? undefined : length;
|
|
1057
|
+
}
|
|
1058
|
+
// finds the expression following a direct keyword token, "VISIBLE LENGTH" is not "LENGTH"
|
|
1059
|
+
findParameterAddition(node, keyword) {
|
|
1060
|
+
var _a;
|
|
1061
|
+
const children = node.getChildren();
|
|
1062
|
+
for (let i = 0; i < children.length - 1; i++) {
|
|
1063
|
+
const child = children[i];
|
|
1064
|
+
const next = children[i + 1];
|
|
1065
|
+
if (child instanceof nodes_1.ExpressionNode
|
|
1066
|
+
|| child.getFirstToken().getStr().toUpperCase() !== keyword
|
|
1067
|
+
|| ((_a = children[i - 1]) === null || _a === void 0 ? void 0 : _a.getFirstToken().getStr().toUpperCase()) === "VISIBLE") {
|
|
1068
|
+
continue;
|
|
1069
|
+
}
|
|
1070
|
+
return next instanceof nodes_1.ExpressionNode ? next : undefined;
|
|
1071
|
+
}
|
|
1036
1072
|
return undefined;
|
|
1037
1073
|
}
|
|
1038
1074
|
findLength(node) {
|
|
@@ -1053,6 +1089,9 @@ class BasicTypes {
|
|
|
1053
1089
|
}
|
|
1054
1090
|
}
|
|
1055
1091
|
if (val === undefined) {
|
|
1092
|
+
if (node.get() instanceof Statements.Parameter) {
|
|
1093
|
+
return this.findParameterLength(node);
|
|
1094
|
+
}
|
|
1056
1095
|
return undefined;
|
|
1057
1096
|
}
|
|
1058
1097
|
const intExpr = val.findFirstExpression(Expressions.Integer);
|
package/build/src/ddic.js
CHANGED
|
@@ -147,7 +147,7 @@ class DDIC {
|
|
|
147
147
|
return new Types.PackedType(length, 0, { qualifiedName: qualifiedName });
|
|
148
148
|
}
|
|
149
149
|
else {
|
|
150
|
-
return new Types.PackedType(8, 0, { qualifiedName: qualifiedName });
|
|
150
|
+
return new Types.PackedType(8, decimals !== null && decimals !== void 0 ? decimals : 0, { qualifiedName: qualifiedName });
|
|
151
151
|
}
|
|
152
152
|
case "C":
|
|
153
153
|
if (length) {
|
|
@@ -113,11 +113,17 @@ class Table extends _abstract_object_1.AbstractObject {
|
|
|
113
113
|
}
|
|
114
114
|
const ret = [];
|
|
115
115
|
for (const p of this.parsedData.fields) {
|
|
116
|
-
if (p.KEYFLAG === "X" && p.FIELDNAME === ".INCLUDE") {
|
|
117
|
-
|
|
116
|
+
if (p.KEYFLAG === "X" && (p.FIELDNAME === ".INCLUDE" || p.FIELDNAME.startsWith(".INCLU-"))) {
|
|
117
|
+
let lookup = new ddic_1.DDIC(reg).lookupTableOrView(p.PRECFIELD).type;
|
|
118
|
+
if (lookup instanceof _typed_identifier_1.TypedIdentifier) {
|
|
119
|
+
lookup = lookup.getType();
|
|
120
|
+
}
|
|
121
|
+
// same naming as in parseType(), "--AP" are .APPENDS and get no suffix
|
|
122
|
+
const postfix = p.FIELDNAME.startsWith(".INCLU-") && p.FIELDNAME !== ".INCLU--AP"
|
|
123
|
+
? p.FIELDNAME.substring(".INCLU-".length) : "";
|
|
118
124
|
if (lookup instanceof Types.StructureType) {
|
|
119
125
|
for (const c of lookup.getComponents()) {
|
|
120
|
-
ret.push(c.name);
|
|
126
|
+
ret.push(c.name + postfix);
|
|
121
127
|
}
|
|
122
128
|
}
|
|
123
129
|
}
|
package/build/src/registry.js
CHANGED
|
@@ -0,0 +1,162 @@
|
|
|
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.ElseAfterAllReturns = exports.ElseAfterAllReturnsConf = 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 Structures = __importStar(require("../abap/3_structures/structures"));
|
|
43
|
+
const Expressions = __importStar(require("../abap/2_statements/expressions"));
|
|
44
|
+
const nodes_1 = require("../abap/nodes");
|
|
45
|
+
const edit_helper_1 = require("../edit_helper");
|
|
46
|
+
const _statement_1 = require("../abap/2_statements/statements/_statement");
|
|
47
|
+
class ElseAfterAllReturnsConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
48
|
+
}
|
|
49
|
+
exports.ElseAfterAllReturnsConf = ElseAfterAllReturnsConf;
|
|
50
|
+
class ElseAfterAllReturns extends _abap_rule_1.ABAPRule {
|
|
51
|
+
constructor() {
|
|
52
|
+
super(...arguments);
|
|
53
|
+
this.conf = new ElseAfterAllReturnsConf();
|
|
54
|
+
}
|
|
55
|
+
getMetadata() {
|
|
56
|
+
return {
|
|
57
|
+
key: "else_after_all_returns",
|
|
58
|
+
title: "Else after all returns",
|
|
59
|
+
shortDescription: `Finds ELSE branches that are redundant because all prior branches exit unconditionally.`,
|
|
60
|
+
extendedInformation: `When every branch preceding ELSE ends with RETURN, EXIT, or CONTINUE (or a non-resumable RAISE / LEAVE), ` +
|
|
61
|
+
`the ELSE keyword adds no logical value and can be removed by de-indenting its body.`,
|
|
62
|
+
tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Styleguide, _irule_1.RuleTag.Quickfix],
|
|
63
|
+
badExample: `IF x = 1.\n RETURN.\nELSE.\n WRITE 'hello'.\nENDIF.`,
|
|
64
|
+
goodExample: `IF x = 1.\n RETURN.\nENDIF.\nWRITE 'hello'.`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
getConfig() {
|
|
68
|
+
return this.conf;
|
|
69
|
+
}
|
|
70
|
+
setConfig(conf) {
|
|
71
|
+
this.conf = conf;
|
|
72
|
+
}
|
|
73
|
+
runParsed(file, _obj) {
|
|
74
|
+
const issues = [];
|
|
75
|
+
const structure = file.getStructure();
|
|
76
|
+
if (structure === undefined) {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
for (const ifNode of structure.findAllStructures(Structures.If)) {
|
|
80
|
+
const elseNode = ifNode.findDirectStructure(Structures.Else);
|
|
81
|
+
if (elseNode === undefined) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (this.allBranchesExit(ifNode)) {
|
|
85
|
+
const elseStatement = elseNode.findFirstStatement(Statements.Else);
|
|
86
|
+
const endifStatement = ifNode.findDirectStatement(Statements.EndIf);
|
|
87
|
+
if (elseStatement === undefined || endifStatement === undefined) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const fix = edit_helper_1.EditHelper.merge(edit_helper_1.EditHelper.replaceRange(file, elseStatement.getFirstToken().getStart(), elseStatement.getLastToken().getEnd(), "ENDIF."), edit_helper_1.EditHelper.deleteStatement(file, endifStatement));
|
|
91
|
+
// eslint-disable-next-line max-len
|
|
92
|
+
issues.push(issue_1.Issue.atStatement(file, elseStatement, "Redundant ELSE: all prior branches exit unconditionally", this.getMetadata().key, this.conf.severity, fix));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return issues;
|
|
96
|
+
}
|
|
97
|
+
// Returns true if every branch before the ELSE ends with an unconditional exit.
|
|
98
|
+
allBranchesExit(ifNode) {
|
|
99
|
+
// Main IF body
|
|
100
|
+
const mainBody = ifNode.findDirectStructure(Structures.Body);
|
|
101
|
+
if (!this.bodyEndsWithExit(mainBody)) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
// Each ELSEIF body
|
|
105
|
+
for (const elseifNode of ifNode.findDirectStructures(Structures.ElseIf)) {
|
|
106
|
+
const elseifBody = elseifNode.findDirectStructure(Structures.Body);
|
|
107
|
+
if (!this.bodyEndsWithExit(elseifBody)) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
bodyEndsWithExit(body) {
|
|
114
|
+
if (body === undefined) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
const last = this.lastNonCommentStatement(body);
|
|
118
|
+
if (last === undefined) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
return this.isExit(last);
|
|
122
|
+
}
|
|
123
|
+
collectStatements(node) {
|
|
124
|
+
const result = [];
|
|
125
|
+
for (const child of node.getChildren()) {
|
|
126
|
+
if (child instanceof nodes_1.StatementNode) {
|
|
127
|
+
result.push(child);
|
|
128
|
+
}
|
|
129
|
+
else if (child instanceof nodes_1.StructureNode) {
|
|
130
|
+
result.push(...this.collectStatements(child));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
lastNonCommentStatement(node) {
|
|
136
|
+
const all = this.collectStatements(node);
|
|
137
|
+
for (let i = all.length - 1; i >= 0; i--) {
|
|
138
|
+
if (!(all[i].get() instanceof _statement_1.Comment)) {
|
|
139
|
+
return all[i];
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
isExit(node) {
|
|
145
|
+
const s = node.get();
|
|
146
|
+
if (s instanceof Statements.Return
|
|
147
|
+
|| s instanceof Statements.Exit
|
|
148
|
+
|| s instanceof Statements.Continue) {
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
if (s instanceof Statements.Raise) {
|
|
152
|
+
return !node.concatTokens().toUpperCase().includes("RESUMABLE");
|
|
153
|
+
}
|
|
154
|
+
if (s instanceof Statements.Leave) {
|
|
155
|
+
const tokens = node.concatTokens().toUpperCase();
|
|
156
|
+
return !tokens.includes("LIST-PROCESSING") && node.findFirstExpression(Expressions.AndReturn) === undefined;
|
|
157
|
+
}
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.ElseAfterAllReturns = ElseAfterAllReturns;
|
|
162
|
+
//# sourceMappingURL=else_after_all_returns.js.map
|
package/build/src/rules/index.js
CHANGED
|
@@ -69,6 +69,7 @@ __exportStar(require("./empty_event"), exports);
|
|
|
69
69
|
__exportStar(require("./empty_line_in_statement"), exports);
|
|
70
70
|
__exportStar(require("./empty_statement"), exports);
|
|
71
71
|
__exportStar(require("./empty_structure"), exports);
|
|
72
|
+
__exportStar(require("./else_after_all_returns"), exports);
|
|
72
73
|
__exportStar(require("./exit_or_check"), exports);
|
|
73
74
|
__exportStar(require("./expand_macros"), exports);
|
|
74
75
|
__exportStar(require("./exporting"), exports);
|
|
@@ -48,6 +48,8 @@ class XMLConsistencyConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
|
48
48
|
this.textAndTranslationLengthSeverity = severity_1.Severity.Error;
|
|
49
49
|
/** Problem severity for data element(DTEL) field checks */
|
|
50
50
|
this.dataElementSeverity = severity_1.Severity.Error;
|
|
51
|
+
/** Problem severity for transparent table checks */
|
|
52
|
+
this.transparentTableSeverity = severity_1.Severity.Error;
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
exports.XMLConsistencyConf = XMLConsistencyConf;
|
|
@@ -335,11 +337,11 @@ class XMLConsistency {
|
|
|
335
337
|
if (obj.getTableCategory() === Objects.TableCategory.Transparent) {
|
|
336
338
|
if (!((_c = obj.getDeliveryClass()) === null || _c === void 0 ? void 0 : _c.trim())) {
|
|
337
339
|
const message = `Transparent table must have delivery class(CONTFLAG in DD02V) set`;
|
|
338
|
-
issues.push(issue_1.Issue.atRow(file, 1, message, this.getMetadata().key, this.conf.
|
|
340
|
+
issues.push(issue_1.Issue.atRow(file, 1, message, this.getMetadata().key, this.conf.transparentTableSeverity));
|
|
339
341
|
}
|
|
340
342
|
if (!((_d = obj.getSizeCategory()) === null || _d === void 0 ? void 0 : _d.trim())) {
|
|
341
343
|
const message = `Transparent table must have size category(TABKAT in DD09L) set`;
|
|
342
|
-
issues.push(issue_1.Issue.atRow(file, 1, message, this.getMetadata().key, this.conf.
|
|
344
|
+
issues.push(issue_1.Issue.atRow(file, 1, message, this.getMetadata().key, this.conf.transparentTableSeverity));
|
|
343
345
|
}
|
|
344
346
|
}
|
|
345
347
|
return issues;
|