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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 18018x 18018x 18018x 18018x 18018x 54005x 54005x 54005x 54005x 54005x 54005x 54005x 54005x 54005x 54005x 54005x 54005x 54005x 54005x 54005x 54005x 18018x 18018x 12x 12x 18018x 18018x 17377x 17377x 18018x 18018x 303x 303x 18018x 18018x 311x 311x 311x 311x 311x 1778x 1778x 1778x 1778x 149x 149x 1629x 1629x 1778x 6x 6x 1623x 1778x 12x 12x 12x 12x 12x 1623x 1623x 311x 311x 311x 18018x 18018x | import {Issue} from "../issue";
import {Comment, NativeSQL} from "../abap/2_statements/statements/_statement";
import {ABAPRule} from "./_abap_rule";
import {BasicRuleConfig} from "./_basic_rule_config";
import {EditHelper} from "../edit_helper";
import {IRuleMetadata, RuleTag} from "./_irule";
import {VirtualPosition} from "../virtual_position";
import {ABAPFile} from "../abap/abap_file";
export class MaxOneStatementConf extends BasicRuleConfig {
}
export class MaxOneStatement extends ABAPRule {
private conf = new MaxOneStatementConf();
public getMetadata(): IRuleMetadata {
return {
key: "max_one_statement",
title: "Max one statement per line",
shortDescription: `Checks that each line contains only a single statement.`,
extendedInformation:
`Does not report empty statements, use rule empty_statement for detecting empty statements.
Does not report anything for chained statements.
https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#no-more-than-one-statement-per-line
https://docs.abapopenchecks.org/checks/11/`,
tags: [RuleTag.Styleguide, RuleTag.Quickfix, RuleTag.SingleFile],
badExample: `WRITE foo. WRITE bar.`,
goodExample: `WRITE foo.\nWRITE bar.`,
};
}
private getMessage(): string {
return "Only one statement is allowed per line";
}
public getConfig() {
return this.conf;
}
public setConfig(conf: MaxOneStatementConf) {
this.conf = conf;
}
public runParsed(file: ABAPFile) {
const issues: Issue[] = [];
let prev: number = 0;
let reported: number = 0;
for (const statement of file.getStatements()) {
const term = statement.getTerminator();
if (statement.get() instanceof Comment
|| statement.get() instanceof NativeSQL
|| term === ",") {
continue;
}
const pos = statement.getStart();
if (pos instanceof VirtualPosition) {
continue;
}
const row = pos.getRow();
if (prev === row && row !== reported && statement.getFirstToken().getStr() !== ".") {
const fix = EditHelper.insertAt(file, pos, "\n");
const issue = Issue.atPosition(file, pos, this.getMessage(), this.getMetadata().key, this.conf.severity, fix);
issues.push(issue);
reported = row;
}
prev = row;
}
return issues;
}
} |