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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 21101x 21101x 21101x 21101x 63052x 63052x 63052x 63052x 63052x 63052x 63052x 63052x 63052x 63052x 63052x 63052x 63052x 63052x 63052x 63052x 63052x 63052x 63052x 21101x 21101x 20207x 20207x 21101x 21101x 374x 374x 21101x 21101x 389x 389x 389x 389x 389x 389x 389x 389x 389x 13x 13x 376x 376x 376x 376x 376x 376x 376x 376x 376x 376x 389x 8x 8x 2x 2x 2x 2x 8x 376x 376x 376x 21101x 21101x | import {Issue} from "../issue";
import {ABAPRule} from "./_abap_rule";
import {BasicRuleConfig} from "./_basic_rule_config";
import * as Structures from "../abap/3_structures/structures";
import * as Expressions from "../abap/2_statements/expressions";
import {IRuleMetadata, RuleTag} from "./_irule";
import {ABAPFile} from "../abap/abap_file";
import {Release} from "../version";
export class NoInlineInOptionalBranchesConf extends BasicRuleConfig {
}
export class NoInlineInOptionalBranches extends ABAPRule {
private conf = new NoInlineInOptionalBranchesConf();
public getMetadata(): IRuleMetadata {
return {
key: "no_inline_in_optional_branches",
title: "Don't declare inline in optional branches",
shortDescription: `Don't declare inline in optional branches`,
extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#dont-declare-inline-in-optional-branches
Considered optional branches:
* inside IF/ELSEIF/ELSE
* inside LOOP
* inside WHILE
* inside CASE/WHEN, CASE TYPE OF
* inside DO
* inside SELECT loops
Not considered optional branches:
* TRY/CATCH/CLEANUP`,
tags: [RuleTag.Styleguide, RuleTag.SingleFile],
};
}
public getConfig() {
return this.conf;
}
public setConfig(conf: NoInlineInOptionalBranchesConf) {
this.conf = conf;
}
public runParsed(file: ABAPFile) {
const output: Issue[] = [];
const release = this.reg.getConfig().getRelease();
if (release === Release.v700
|| release === Release.v702
|| this.reg.getConfig().isOpenABAP()) {
return [];
}
const struc = file.getStructure();
if (struc === undefined) {
return []; // syntax error
}
const candidates = [
...struc.findAllStructures(Structures.If),
...struc.findAllStructures(Structures.Loop),
...struc.findAllStructures(Structures.While),
...struc.findAllStructures(Structures.Case),
...struc.findAllStructures(Structures.CaseType),
...struc.findAllStructures(Structures.Do),
...struc.findAllStructures(Structures.Select)];
for (const c of candidates) {
const inline = c.findFirstExpression(Expressions.InlineData);
if (inline) {
const message = "Don't declare inline in optional branches";
const issue = Issue.atToken(file, inline.getFirstToken(), message, this.getMetadata().key, this.getConfig().severity);
output.push(issue);
}
}
return output;
}
} |