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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 42220x 42220x 42220x 42220x 42220x 42220x 42220x 42220x 42220x 42220x 1x 21117x 21117x 21117x 21117x 21117x 21117x 244918x 244918x 244918x 244918x 244918x 244918x 244918x 244918x 244918x 244918x 244918x 244918x 244918x 244918x 244918x 244918x 244918x 244918x 244918x 244918x 244918x 21117x 21117x 23x 23x 23x 23x 21117x 21117x 20205x 20205x 21117x 21117x 380x 380x 380x 21117x 21117x 21497x 21497x 21497x 21497x 21497x 21497x 21497x 21497x 21117x 21117x 393x 393x 21117x 21117x 603x 603x 603x 583x 583x 20x 20x 20x 21117x 21117x 20x 20x 20x 20x 20x 20x 20x 20x 20x 21117x 21117x | import {Issue} from "../issue";
import {IRule, RuleTag} from "./_irule";
import {IObject} from "../objects/_iobject";
import {IRegistry} from "../_iregistry";
import {FunctionGroup} from "../objects/function_group";
import {NamingRuleConfig} from "./_naming_rule_config";
import {NameValidator} from "../utils/name_validator";
import {FunctionModuleDefinition} from "../abap/types/function_module_definition";
import {Position} from "../position";
export class FunctionModuleParameterNamesConf extends NamingRuleConfig {
/** The pattern for importing parameters */
public importing: string = "^I._.+$";
/** The pattern for exporting parameters */
public exporting: string = "^E._.+$";
/** The pattern for changing parameters */
public changing: string = "^C._.+$";
/** The pattern for tables parameters */
public tables: string = "^T._.+$";
}
export class FunctionModuleParameterNames implements IRule {
private conf = new FunctionModuleParameterNamesConf();
private regex = this.compile();
public getMetadata() {
return {
key: "function_module_parameter_names",
title: "Function module parameter naming conventions",
shortDescription: `Allows you to enforce a pattern, such as a prefix, for function module parameter names`,
extendedInformation: `Checks the parameters of function modules in function groups,
with a separate pattern for importing, exporting, changing and tables parameters.`,
tags: [RuleTag.Naming, RuleTag.SingleFile],
badExample: `FUNCTION z_get_name.
*" IMPORTING
*" VALUE(CUSTOMER) TYPE STRING
*" EXPORTING
*" VALUE(NAME) TYPE STRING
ENDFUNCTION.`,
goodExample: `FUNCTION z_get_name.
*" IMPORTING
*" VALUE(IV_CUSTOMER) TYPE STRING
*" EXPORTING
*" VALUE(EV_NAME) TYPE STRING
ENDFUNCTION.`,
};
}
private getDescription(expected: string, actual: string): string {
return this.conf.patternKind === "required" ?
"Function module parameter name does not match pattern " + expected + ": " + actual :
"Function module parameter name must not match pattern " + expected + ": " + actual;
}
public getConfig() {
return this.conf;
}
public setConfig(conf: FunctionModuleParameterNamesConf) {
this.conf = conf;
this.regex = this.compile();
}
private compile() {
return {
importing: new RegExp(this.conf.importing, "i"),
exporting: new RegExp(this.conf.exporting, "i"),
changing: new RegExp(this.conf.changing, "i"),
tables: new RegExp(this.conf.tables, "i"),
ignorePatterns: NameValidator.compileIgnorePatterns(this.conf),
};
}
public initialize(_reg: IRegistry) {
return this;
}
public run(obj: IObject): Issue[] {
if (this.conf.patternKind === undefined) {
this.conf.patternKind = "required";
}
if (!(obj instanceof FunctionGroup)) {
return [];
}
return obj.getModules().flatMap(module => this.checkModule(obj, module));
}
private checkModule(obj: FunctionGroup, module: FunctionModuleDefinition): Issue[] {
// the parameters are only defined in the XML, so report at the start of the module file, if it exists
const file = obj.getModuleFile(module) || obj.getMainABAPFile();
if (file === undefined) {
return [];
}
// the directions are the names of the configured patterns
return module.getParameters()
.filter(p => NameValidator.violatesRule(p.name, this.regex[p.direction], this.conf, this.regex.ignorePatterns))
.map(p => Issue.atPosition(file, new Position(1, 1), this.getDescription(this.conf[p.direction], p.name),
this.getMetadata().key, this.conf.severity));
}
}
|