Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 42199x 42199x 42199x 42199x 42199x 42199x 1x 21100x 21100x 21100x 21100x 21100x 21100x 204490x 204490x 204490x 204490x 204490x 204490x 204490x 204490x 204490x 21100x 21100x 20205x 20205x 21100x 21100x 375x 375x 375x 375x 21100x 21100x 392x 388x 388x 4x 4x 4x 4x 4x 4x 4x 4x 21100x 21100x 20x 20x 20x 34x 7x 34x 11x 27x 16x 16x 34x 20x 20x 20x 21100x 21100x 7x 7x 7x 14x 3x 3x 3x 14x 7x 7x 21100x 21100x | import {ABAPRule} from "./_abap_rule";
import {BasicRuleConfig} from "./_basic_rule_config";
import {Issue} from "../issue";
import {TokenNodeRegex, TokenNode} from "../abap/nodes";
import {INode} from "../abap/nodes/_inode";
import {AbstractToken} from "../abap/1_lexer/tokens/abstract_token";
import {IRuleMetadata, RuleTag} from "./_irule";
import {ABAPFile} from "../abap/abap_file";
export class ForbiddenIdentifierConf extends BasicRuleConfig {
/** List of forbideen identifiers, array of string regex
* @uniqueItems true
*/
public check: string[] = [];
}
export class ForbiddenIdentifier extends ABAPRule {
private conf = new ForbiddenIdentifierConf();
private checks: RegExp[] = [];
public getMetadata(): IRuleMetadata {
return {
key: "forbidden_identifier",
title: "Forbidden Identifier",
shortDescription: `Forbid use of specified identifiers, list of regex.`,
extendedInformation: `Used in the transpiler to find javascript keywords in ABAP identifiers,
https://github.com/abaplint/transpiler/blob/bda94b8b56e2b7f2f87be2168f12361aa530220e/packages/transpiler/src/validation.ts#L44`,
tags: [RuleTag.SingleFile],
};
}
public getConfig() {
return this.conf;
}
public setConfig(conf: ForbiddenIdentifierConf): void {
this.conf = conf;
if (this.conf.check === undefined) {
this.conf.check = [];
}
this.checks = this.conf.check.map(c => new RegExp(c, "i"));
}
public runParsed(file: ABAPFile): Issue[] {
if (this.checks.length === 0) {
return [];
}
let ret: Issue[] = [];
for (const s of file.getStatements()) {
ret = ret.concat(this.traverse(s, file));
}
return ret;
}
private traverse(node: INode, file: ABAPFile): Issue[] {
let ret: Issue[] = [];
for (const c of node.getChildren()) {
if (c instanceof TokenNodeRegex) {
ret = ret.concat(this.check(c.get(), file));
} else if (c instanceof TokenNode) {
continue;
} else {
ret = ret.concat(this.traverse(c, file));
}
}
return ret;
}
private check(token: AbstractToken, file: ABAPFile): Issue[] {
const str = token.getStr();
const ret: Issue[] = [];
for (const reg of this.checks) {
if (reg.exec(str)) {
const message = "Identifer \"" + str + "\" not allowed";
ret.push(Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity));
}
}
return ret;
}
}
|