@abaplint/core 2.120.90 → 2.120.91
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/expressions/new_object.js +2 -0
- package/build/src/registry.js +1 -1
- package/build/src/rules/abapdoc_short_link.js +133 -0
- package/build/src/rules/downport.js +15 -7
- package/build/src/rules/forbidden_kernel_write.js +105 -0
- package/build/src/rules/index.js +2 -0
- package/package.json +1 -1
|
@@ -88,6 +88,8 @@ class NewObject {
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
else if (typeName === "#" && targetType) {
|
|
91
|
+
const tid = new _typed_identifier_1.TypedIdentifier(typeToken, input.filename, targetType);
|
|
92
|
+
input.scope.addReference(typeToken, tid, _reference_1.ReferenceType.InferredType, input.filename);
|
|
91
93
|
ret = targetType;
|
|
92
94
|
}
|
|
93
95
|
else if (typeName === "#") {
|
package/build/src/registry.js
CHANGED
|
@@ -0,0 +1,133 @@
|
|
|
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.AbapdocShortLink = exports.AbapdocShortLinkConf = void 0;
|
|
37
|
+
const Statements = __importStar(require("../abap/2_statements/statements"));
|
|
38
|
+
const Expressions = __importStar(require("../abap/2_statements/expressions"));
|
|
39
|
+
const issue_1 = require("../issue");
|
|
40
|
+
const _abap_rule_1 = require("./_abap_rule");
|
|
41
|
+
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
42
|
+
const _irule_1 = require("./_irule");
|
|
43
|
+
const _statement_1 = require("../abap/2_statements/statements/_statement");
|
|
44
|
+
const position_1 = require("../position");
|
|
45
|
+
const edit_helper_1 = require("../edit_helper");
|
|
46
|
+
class AbapdocShortLinkConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
47
|
+
}
|
|
48
|
+
exports.AbapdocShortLinkConf = AbapdocShortLinkConf;
|
|
49
|
+
class AbapdocShortLink extends _abap_rule_1.ABAPRule {
|
|
50
|
+
constructor() {
|
|
51
|
+
super(...arguments);
|
|
52
|
+
this.conf = new AbapdocShortLinkConf();
|
|
53
|
+
}
|
|
54
|
+
getMetadata() {
|
|
55
|
+
return {
|
|
56
|
+
key: "abapdoc_short_link",
|
|
57
|
+
title: "Use short form of ABAP Doc links",
|
|
58
|
+
shortDescription: `Reports ABAP Doc links to components of the current global class or interface which repeat the object name.`,
|
|
59
|
+
extendedInformation: `Links to components of the same repository object can omit the object name and start with a period,
|
|
60
|
+
{@link zif_foo.data:field} can be written as {@link .data:field}.
|
|
61
|
+
|
|
62
|
+
Only checks ABAP Doc inside the definition of the global class or interface.
|
|
63
|
+
|
|
64
|
+
https://github.com/SAP/abap-file-formats/issues/880`,
|
|
65
|
+
tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
|
|
66
|
+
badExample: `INTERFACE zif_foo PUBLIC.
|
|
67
|
+
"! Same as {@link zif_foo.data:bar}
|
|
68
|
+
DATA foo TYPE string.
|
|
69
|
+
DATA bar TYPE string.
|
|
70
|
+
ENDINTERFACE.`,
|
|
71
|
+
goodExample: `INTERFACE zif_foo PUBLIC.
|
|
72
|
+
"! Same as {@link .data:bar}
|
|
73
|
+
DATA foo TYPE string.
|
|
74
|
+
DATA bar TYPE string.
|
|
75
|
+
ENDINTERFACE.`,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
getConfig() {
|
|
79
|
+
return this.conf;
|
|
80
|
+
}
|
|
81
|
+
setConfig(conf) {
|
|
82
|
+
this.conf = conf;
|
|
83
|
+
}
|
|
84
|
+
runParsed(file, obj) {
|
|
85
|
+
var _a;
|
|
86
|
+
const issues = [];
|
|
87
|
+
const objectType = obj.getType();
|
|
88
|
+
if (objectType !== "CLAS" && objectType !== "INTF") {
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
const objectName = obj.getName().toLowerCase();
|
|
92
|
+
let definition = false;
|
|
93
|
+
for (const statement of file.getStatements()) {
|
|
94
|
+
const type = statement.get();
|
|
95
|
+
if (type instanceof Statements.ClassDefinition || type instanceof Statements.Interface) {
|
|
96
|
+
const name = (_a = statement.findFirstExpression(Expressions.ClassName)) !== null && _a !== void 0 ? _a : statement.findFirstExpression(Expressions.InterfaceName);
|
|
97
|
+
definition = (name === null || name === void 0 ? void 0 : name.getFirstToken().getStr().toLowerCase()) === objectName;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
else if (type instanceof Statements.EndClass || type instanceof Statements.EndInterface) {
|
|
101
|
+
definition = false;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
else if (definition === false || !(type instanceof _statement_1.Comment)) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const token = statement.getFirstToken();
|
|
108
|
+
const str = token.getStr();
|
|
109
|
+
if (str.startsWith(`"!`) === false) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const regex = /\{@link\s+((?:(\w+):)?([\w/]+))\./gi;
|
|
113
|
+
let match;
|
|
114
|
+
while ((match = regex.exec(str)) !== null) {
|
|
115
|
+
const kind = match[2];
|
|
116
|
+
if (match[3].toLowerCase() !== objectName
|
|
117
|
+
|| (kind !== undefined && kind.toLowerCase() !== objectType.toLowerCase())) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const row = token.getStart().getRow();
|
|
121
|
+
const col = token.getStart().getCol() + match.index + match[0].length - 1 - match[1].length;
|
|
122
|
+
const start = new position_1.Position(row, col);
|
|
123
|
+
const end = new position_1.Position(row, col + match[1].length);
|
|
124
|
+
const fix = edit_helper_1.EditHelper.deleteRange(file, start, end);
|
|
125
|
+
const message = `Use short form of ABAP Doc link, remove "${match[1]}"`;
|
|
126
|
+
issues.push(issue_1.Issue.atRange(file, start, end, message, this.getMetadata().key, this.conf.severity, fix));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return issues;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.AbapdocShortLink = AbapdocShortLink;
|
|
133
|
+
//# sourceMappingURL=abapdoc_short_link.js.map
|
|
@@ -3387,12 +3387,9 @@ ${indentation} output = ${uniqueName}.\n`;
|
|
|
3387
3387
|
}
|
|
3388
3388
|
}
|
|
3389
3389
|
/** NEW into a data reference creates data, CREATE OBJECT cannot: "target = NEW #|type( [value] )"
|
|
3390
|
-
* with a
|
|
3390
|
+
* with a target typed REF TO a data type becomes CREATE DATA plus the assignment of the value */
|
|
3391
3391
|
newDataReference(high, target, found, lowFile, highSyntax) {
|
|
3392
3392
|
var _a, _b, _c;
|
|
3393
|
-
if (target.getChildren().length !== 1 || !(((_a = target.getFirstChild()) === null || _a === void 0 ? void 0 : _a.get()) instanceof Expressions.TargetField)) {
|
|
3394
|
-
return undefined;
|
|
3395
|
-
}
|
|
3396
3393
|
const children = found.getChildren();
|
|
3397
3394
|
const value = found.findDirectExpression(Expressions.Source);
|
|
3398
3395
|
// NEW, the type, "(", optionally one value, ")"
|
|
@@ -3400,12 +3397,23 @@ ${indentation} output = ${uniqueName}.\n`;
|
|
|
3400
3397
|
return undefined;
|
|
3401
3398
|
}
|
|
3402
3399
|
const name = target.concatTokens();
|
|
3400
|
+
const typeExpr = found.findDirectExpression(Expressions.TypeNameOrInfer);
|
|
3401
|
+
const typeName = typeExpr === null || typeExpr === void 0 ? void 0 : typeExpr.concatTokens();
|
|
3403
3402
|
const spag = highSyntax.spaghetti.lookupPosition(high.getFirstToken().getStart(), lowFile.getFilename());
|
|
3404
|
-
|
|
3403
|
+
let type = undefined;
|
|
3404
|
+
if (typeName === "#") {
|
|
3405
|
+
// the type of the target, as inferred by the syntax check
|
|
3406
|
+
const typeToken = typeExpr.getFirstToken();
|
|
3407
|
+
const resolved = (_a = spag === null || spag === void 0 ? void 0 : spag.getData().references.find(r => r.referenceType === _reference_1.ReferenceType.InferredType
|
|
3408
|
+
&& r.position.getStart().equals(typeToken.getStart()))) === null || _a === void 0 ? void 0 : _a.resolved;
|
|
3409
|
+
type = resolved instanceof _typed_identifier_1.TypedIdentifier ? resolved.getType() : undefined;
|
|
3410
|
+
}
|
|
3411
|
+
else if (target.getChildren().length === 1 && ((_b = target.getFirstChild()) === null || _b === void 0 ? void 0 : _b.get()) instanceof Expressions.TargetField) {
|
|
3412
|
+
type = (_c = spag === null || spag === void 0 ? void 0 : spag.findVariable(name)) === null || _c === void 0 ? void 0 : _c.getType();
|
|
3413
|
+
}
|
|
3405
3414
|
if (!(type instanceof basic_1.DataReference)) {
|
|
3406
3415
|
return undefined;
|
|
3407
3416
|
}
|
|
3408
|
-
const typeName = (_c = found.findDirectExpression(Expressions.TypeNameOrInfer)) === null || _c === void 0 ? void 0 : _c.concatTokens();
|
|
3409
3417
|
const indentation = " ".repeat(high.getFirstToken().getStart().getCol() - 1);
|
|
3410
3418
|
let abap = `CREATE DATA ${name}` + (typeName === "#" ? "" : ` TYPE ${typeName}`) + ".";
|
|
3411
3419
|
if (value === undefined) {
|
|
@@ -3453,7 +3461,7 @@ ${indentation} output = ${uniqueName}.\n`;
|
|
|
3453
3461
|
}
|
|
3454
3462
|
}
|
|
3455
3463
|
else {
|
|
3456
|
-
|
|
3464
|
+
return undefined; // not an object, CREATE OBJECT does not apply
|
|
3457
3465
|
}
|
|
3458
3466
|
}
|
|
3459
3467
|
if (cdef && cdef.getMethodDefinitions === undefined) {
|
|
@@ -0,0 +1,105 @@
|
|
|
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.ForbiddenKernelWrite = exports.ForbiddenKernelWriteConf = void 0;
|
|
37
|
+
const Expressions = __importStar(require("../abap/2_statements/expressions"));
|
|
38
|
+
const Statements = __importStar(require("../abap/2_statements/statements"));
|
|
39
|
+
const _abap_rule_1 = require("./_abap_rule");
|
|
40
|
+
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
41
|
+
const issue_1 = require("../issue");
|
|
42
|
+
const _irule_1 = require("./_irule");
|
|
43
|
+
class ForbiddenKernelWriteConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
44
|
+
constructor() {
|
|
45
|
+
super(...arguments);
|
|
46
|
+
/** Objects allowed to use WRITE '@KERNEL', array of string regex matched against the object name.
|
|
47
|
+
* Empty, the default, allows every object
|
|
48
|
+
* @uniqueItems true
|
|
49
|
+
*/
|
|
50
|
+
this.allow = [];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.ForbiddenKernelWriteConf = ForbiddenKernelWriteConf;
|
|
54
|
+
class ForbiddenKernelWrite extends _abap_rule_1.ABAPRule {
|
|
55
|
+
constructor() {
|
|
56
|
+
super(...arguments);
|
|
57
|
+
this.conf = new ForbiddenKernelWriteConf();
|
|
58
|
+
this.allow = [];
|
|
59
|
+
}
|
|
60
|
+
getMetadata() {
|
|
61
|
+
return {
|
|
62
|
+
key: "forbidden_kernel_write",
|
|
63
|
+
title: "Forbidden kernel WRITE",
|
|
64
|
+
shortDescription: `Forbid WRITE '@KERNEL' outside the listed objects`,
|
|
65
|
+
extendedInformation: `The transpiler emits the literal of WRITE '@KERNEL ...' as raw JavaScript,
|
|
66
|
+
which runs with the privileges of the host. Open-abap uses this for its kernel classes, code compiled by a host it did not write should not.
|
|
67
|
+
|
|
68
|
+
allow is a list of regex, case insensitive, matched against the object name, eg. ["^CL_", "^KERNEL_"].
|
|
69
|
+
An empty list, the default, allows every object. To forbid WRITE '@KERNEL' everywhere use a regex matching no name, eg. ["^$"].`,
|
|
70
|
+
tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Security],
|
|
71
|
+
badExample: `WRITE '@KERNEL process.exit(1);'.`,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
getConfig() {
|
|
75
|
+
return this.conf;
|
|
76
|
+
}
|
|
77
|
+
setConfig(conf) {
|
|
78
|
+
this.conf = conf;
|
|
79
|
+
if (this.conf.allow === undefined) {
|
|
80
|
+
this.conf.allow = [];
|
|
81
|
+
}
|
|
82
|
+
this.allow = this.conf.allow.map(a => new RegExp(a, "i"));
|
|
83
|
+
}
|
|
84
|
+
runParsed(file, obj) {
|
|
85
|
+
var _a;
|
|
86
|
+
if (this.allow.length === 0 || this.allow.some(a => a.test(obj.getName()))) {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
const ret = [];
|
|
90
|
+
for (const s of file.getStatements()) {
|
|
91
|
+
if (!(s.get() instanceof Statements.Write)) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
// same check as the transpiler, statements/write.ts
|
|
95
|
+
const source = (_a = s.findDirectExpression(Expressions.Source)) === null || _a === void 0 ? void 0 : _a.concatTokens();
|
|
96
|
+
if ((source === null || source === void 0 ? void 0 : source.startsWith("'@KERNEL ")) === true) {
|
|
97
|
+
const message = "WRITE '@KERNEL' not allowed in " + obj.getName();
|
|
98
|
+
ret.push(issue_1.Issue.atStatement(file, s, message, this.getMetadata().key, this.conf.severity));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return ret;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.ForbiddenKernelWrite = ForbiddenKernelWrite;
|
|
105
|
+
//# sourceMappingURL=forbidden_kernel_write.js.map
|
package/build/src/rules/index.js
CHANGED
|
@@ -19,6 +19,7 @@ __exportStar(require("./abapdoc"), exports);
|
|
|
19
19
|
__exportStar(require("./abapdoc_html_tag"), exports);
|
|
20
20
|
__exportStar(require("./abapdoc_leading_at"), exports);
|
|
21
21
|
__exportStar(require("./abapdoc_parameter_names"), exports);
|
|
22
|
+
__exportStar(require("./abapdoc_short_link"), exports);
|
|
22
23
|
__exportStar(require("./abapdoc_shorttext_length"), exports);
|
|
23
24
|
__exportStar(require("./add_test_attributes"), exports);
|
|
24
25
|
__exportStar(require("./aff_and_xml"), exports);
|
|
@@ -93,6 +94,7 @@ __exportStar(require("./exporting"), exports);
|
|
|
93
94
|
__exportStar(require("./final_newline"), exports);
|
|
94
95
|
__exportStar(require("./fm_global_parameters_obsolete"), exports);
|
|
95
96
|
__exportStar(require("./forbidden_identifier"), exports);
|
|
97
|
+
__exportStar(require("./forbidden_kernel_write"), exports);
|
|
96
98
|
__exportStar(require("./forbidden_pseudo_and_pragma"), exports);
|
|
97
99
|
__exportStar(require("./forbidden_void_type"), exports);
|
|
98
100
|
__exportStar(require("./form_tables_obsolete"), exports);
|