All files / src/rules line_break_style.ts

100% Statements 56/56
100% Branches 10/10
100% Functions 6/6
100% Lines 56/56

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 561x 1x 1x 1x 1x 1x 1x 1x 1x 11120x 11120x 11120x 11120x 33165x 33165x 33165x 33165x 33165x 33165x 33165x 33165x 33165x 11120x 11120x 272x 272x 11120x 11120x 10557x 10557x 11120x 11120x 266x 266x 11120x 11120x 338x 338x 338x 356x 283x 283x 1927x 1x 1x 1x 1x 1x 1927x 283x 356x 338x 338x 338x 11120x 11120x
import {Issue} from "../issue";
import {BasicRuleConfig} from "./_basic_rule_config";
import {IObject} from "../objects/_iobject";
import {IRule, IRuleMetadata, RuleTag} from "./_irule";
import {IRegistry} from "../_iregistry";
 
export class LineBreakStyleConf extends BasicRuleConfig {
}
 
export class LineBreakStyle implements IRule {
  private conf = new LineBreakStyleConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "line_break_style",
      title: "Makes sure line breaks are consistent in the ABAP code",
      shortDescription: `Enforces LF as newlines in ABAP files
 
abapGit does not work with CRLF`,
      tags: [RuleTag.Whitespace, RuleTag.SingleFile],
    };
  }
 
  public initialize(_reg: IRegistry) {
    return this;
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: LineBreakStyleConf) {
    this.conf = conf;
  }
 
  public run(obj: IObject): Issue[] {
    const output: Issue[] = [];
 
    for (const file of obj.getFiles()) {
      if (file.getFilename().endsWith(".abap")) {
        const rows = file.getRawRows();
        for (let i = 0; i < rows.length; i++) {
          if (rows[i].endsWith("\r") === true) {
            const message = "Line contains carriage return";
            const issue = Issue.atRow(file, i + 1, message, this.getMetadata().key, this.conf.severity);
            output.push(issue);
            break; // only one finding per file
          }
        }
      }
    }
 
    return output;
  }
 
}