All files / src/rules empty_statement.ts

100% Statements 55/55
100% Branches 7/7
100% Functions 5/5
100% Lines 55/55

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 551x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 9362x 9362x 9362x 9362x 9362x 27934x 27934x 27934x 27934x 27934x 27934x 27934x 9362x 9362x 8898x 8898x 9362x 9362x 216x 216x 9362x 9362x 246x 246x 246x 246x 246x 246x 246x 1368x 10x 10x 10x 10x 10x 10x 1368x 1368x 1368x 246x 246x 246x 9362x
import {Issue} from "../issue";
import {Empty} from "../abap/2_statements/statements/_statement";
import {ABAPRule} from "./_abap_rule";
import {BasicRuleConfig} from "./_basic_rule_config";
import {EditHelper} from "../edit_helper";
import {Position} from "../position";
import {RuleTag} from "./_irule";
import {ABAPFile} from "../abap/abap_file";
 
export class EmptyStatementConf extends BasicRuleConfig {
}
 
export class EmptyStatement extends ABAPRule {
 
  private conf = new EmptyStatementConf();
 
  public getMetadata() {
    return {
      key: "empty_statement",
      title: "Remove empty statement",
      shortDescription: `Checks for empty statements (an empty statement is a single dot)`,
      tags: [RuleTag.Quickfix, RuleTag.SingleFile],
    };
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: EmptyStatementConf) {
    this.conf = conf;
  }
 
  public runParsed(file: ABAPFile) {
    const issues: Issue[] = [];
 
    const statements = file.getStatements();
 
    let previousEnd = new Position(1, 1);
 
    for (const sta of statements) {
      if (sta.get() instanceof Empty) {
        const token = sta.getFirstToken();
        const fix = EditHelper.deleteRange(file, previousEnd, token.getEnd());
 
        const issue = Issue.atStatement(file, sta, "Remove empty statement", this.getMetadata().key, this.conf.severity, fix);
        issues.push(issue);
      }
 
      previousEnd = sta.getLastToken().getEnd();
    }
 
    return issues;
  }
}