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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11088x 11088x 11088x 11088x 11088x 33124x 33124x 33124x 33124x 33124x 33124x 33124x 33124x 33124x 33124x 33124x 33124x 11088x 11088x 10568x 10568x 11088x 11088x 244x 244x 11088x 11088x 268x 268x 268x 268x 268x 268x 40x 38x 38x 2x 2x 2x 2x 2x 2x 268x 268x 268x 11088x 11088x | import {Issue} from "../issue";
import {ABAPRule} from "./_abap_rule";
import * as Expressions from "../abap/2_statements/expressions";
import {BasicRuleConfig} from "./_basic_rule_config";
import {IRuleMetadata, RuleTag} from "./_irule";
import {LanguageVersion, Release, releaseAtLeast} from "../version";
import {EditHelper} from "../edit_helper";
import {ABAPFile} from "../abap/abap_file";
export class PreferXsdboolConf extends BasicRuleConfig {
}
export class PreferXsdbool extends ABAPRule {
private conf = new PreferXsdboolConf();
public getMetadata(): IRuleMetadata {
return {
key: "prefer_xsdbool",
title: "Prefer xsdbool over boolc",
shortDescription: `Prefer xsdbool over boolc`,
extendedInformation: `Activates if language version is v740sp08 or above.
https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#use-xsdbool-to-set-boolean-variables`,
tags: [RuleTag.Styleguide, RuleTag.Upport, RuleTag.Quickfix, RuleTag.SingleFile],
badExample: `DATA(sdf) = boolc( 1 = 2 ).`,
goodExample: `DATA(sdf) = xsdbool( 1 = 2 ).`,
};
}
public getConfig() {
return this.conf;
}
public setConfig(conf: PreferXsdboolConf) {
this.conf = conf;
}
public runParsed(file: ABAPFile): Issue[] {
const issues: Issue[] = [];
if (!releaseAtLeast(this.reg.getConfig().getRelease(), Release.v740sp08)
&& this.reg.getConfig().getLanguageVersion() !== LanguageVersion.Cloud) {
return [];
}
for (const s of file.getStructure()?.findAllExpressions(Expressions.Source) || []) {
if (s.concatTokens().toUpperCase().startsWith("BOOLC( ") === false) {
continue;
}
const token = s.getFirstToken();
const message = "Prefer xsdbool over boolc";
const fix = EditHelper.replaceToken(file, token, "xsdbool");
issues.push(Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity, fix));
}
return issues;
}
}
|