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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 29368x 29368x 29368x 29368x 29368x 29368x 29368x 29368x 1x 14684x 14684x 14684x 14684x 14684x 14684x 43927x 43927x 43927x 43927x 43927x 43927x 43927x 14684x 14684x 17x 17x 17x 17x 14684x 14684x 14120x 14120x 14684x 14684x 267x 267x 267x 14684x 14684x 14951x 14951x 14951x 14951x 14951x 14951x 14951x 14684x 14684x 339x 339x 339x 339x 339x 339x 16x 16x 339x 16x 16x 339x 16x 16x 339x 339x 1695x 1695x 1695x 36x 36x 36x 17x 17x 17x 17x 17x 17x 17x 36x 1695x 339x 339x 14684x 14684x 17x 17x 3x 17x 4x 14x 10x 10x 17x 17x 14684x 14684x 36x 8x 36x 8x 8x 20x 20x 14684x 14684x 36x 8x 36x 8x 28x 20x 20x 4x 4x 20x 20x 36x 14684x | import {ABAPRule} from "./_abap_rule";
import {Issue} from "../issue";
import {NamingRuleConfig} from "./_naming_rule_config";
import {Parameter, SelectOption, SelectionScreen} from "../abap/2_statements/statements";
import {IStatement} from "../abap/2_statements/statements/_statement";
import {NameValidator} from "../utils/name_validator";
import {BlockName, FieldSub, InlineField} from "../abap/2_statements/expressions";
import {StatementNode, ExpressionNode} from "../abap/nodes";
import {IRuleMetadata, RuleTag} from "./_irule";
import {ABAPFile} from "../abap/abap_file";
export class SelectionScreenNamingConf extends NamingRuleConfig {
/** The pattern for selection-screen parameters */
public parameter: string = "^P_.+$";
/** The pattern for selection-screen select-options */
public selectOption: string = "^S_.+$";
/** The pattern for selection-screen screen elements */
public screenElement: string = "^SC_.+$";
}
export class SelectionScreenNaming extends ABAPRule {
private conf = new SelectionScreenNamingConf();
private regex = this.compile();
public getMetadata(): IRuleMetadata {
return {
key: "selection_screen_naming",
title: "Selection screen naming conventions",
shortDescription: `Allows you to enforce a pattern, such as a prefix, for selection-screen variable names.`,
tags: [RuleTag.Naming, RuleTag.SingleFile],
};
}
private getDescription(expected: string, actual: string): string {
return this.conf.patternKind === "required" ?
`Selection-Screen variable name does not match pattern ${expected}: ${actual}` :
`Selection-Screen variable name must not match pattern ${expected}: ${actual}`;
}
public getConfig() {
return this.conf;
}
public setConfig(conf: SelectionScreenNamingConf) {
this.conf = conf;
this.regex = this.compile();
}
private compile() {
return {
parameter: new RegExp(this.conf.parameter, "i"),
selectOption: new RegExp(this.conf.selectOption, "i"),
screenElement: new RegExp(this.conf.screenElement, "i"),
ignorePatterns: NameValidator.compileIgnorePatterns(this.conf),
};
}
public runParsed(file: ABAPFile) {
const issues: Issue[] = [];
if (this.conf.patternKind === undefined) {
this.conf.patternKind = "required";
}
let parameterCheckDisabled: boolean = false;
let selectOptionDisabled: boolean = false;
let screenElementDisabled: boolean = false;
if (this.conf.parameter === undefined || this.conf.parameter.length === 0) {
parameterCheckDisabled = true;
}
if (this.conf.selectOption === undefined || this.conf.selectOption.length === 0) {
selectOptionDisabled = true;
}
if (this.conf.screenElement === undefined || this.conf.screenElement.length === 0) {
screenElementDisabled = true;
}
for (const stat of file.getStatements()) {
if ((stat.get() instanceof Parameter && !parameterCheckDisabled)
|| (stat.get() instanceof SelectOption && !selectOptionDisabled)
|| (stat.get() instanceof SelectionScreen && !screenElementDisabled)) {
const fieldNode = this.getFieldForStatementNode(stat);
const regex = this.getRegexForStatement(stat.get());
if (fieldNode && NameValidator.violatesRule(fieldNode.getFirstToken().getStr(), regex, this.conf, this.regex.ignorePatterns)) {
issues.push(Issue.atToken(
file,
fieldNode.getFirstToken(),
this.getDescription(this.getPatternForStatement(stat.get()), fieldNode.getFirstToken().getStr()),
this.getMetadata().key,
this.conf.severity));
}
}
}
return issues;
}
private getPatternForStatement(statement: IStatement): string {
let pattern = "";
if (statement instanceof Parameter) {
pattern = this.conf.parameter;
} else if (statement instanceof SelectOption) {
pattern = this.conf.selectOption;
} else if (statement instanceof SelectionScreen) {
pattern = this.conf.screenElement;
}
return pattern;
}
private getRegexForStatement(statement: IStatement): RegExp {
if (statement instanceof Parameter) {
return this.regex.parameter;
} else if (statement instanceof SelectOption) {
return this.regex.selectOption;
}
return this.regex.screenElement;
}
private getFieldForStatementNode(statNode: StatementNode): ExpressionNode | undefined {
if (statNode.get() instanceof Parameter) {
return statNode.findFirstExpression(FieldSub);
} else if (statNode.get() instanceof SelectOption) {
return statNode.findFirstExpression(FieldSub);
} else if (statNode.get() instanceof SelectionScreen) {
let ret = statNode.findFirstExpression(InlineField);
if (ret === undefined && statNode.concatTokens().toUpperCase().includes(" BEGIN OF TABBED BLOCK")) {
ret = statNode.findFirstExpression(BlockName);
}
return ret;
} else {
return undefined;
}
}
}
|