All files / src issue.ts

96.22% Statements 153/159
86.66% Branches 26/30
100% Functions 16/16
96.22% Lines 153/159

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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 1591x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 89x 89x 89x 89x 89x 89x 89x 89x 89x 89x 89x 89x 1x 1x 255x 255x 1x 1x 1098x 1098x 1098x 1098x 1098x 1098x 1098x 1098x 1098x 1098x 1098x 1098x 1098x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 376x 376x 376x 376x 376x 376x 376x 376x 376x 376x 376x 1x 1x 957x 957x 957x 957x 957x 957x 957x 957x 957x 957x 957x 1x 1x 435x 435x 435x 435x 435x 435x 435x 435x 435x 435x 435x 1x 1x 2958x 2958x 2958x       2958x 2958x   2958x     2958x 1x 1x 1x 1x 1x 1x 136x 136x 1x 1x 749x 749x 1x 1x 14x 14x 1x 1x 13x 13x 1x 1x 19x 19x 1x 1x 394x 394x 1x 1x 13x 13x 1x 1x
import {IFile} from "./files/_ifile";
import {Position, VirtualPosition} from "./position";
import {Token} from "./abap/1_lexer/tokens/_token";
import {Identifier} from "./abap/4_file_information/_identifier";
import {StatementNode} from "./abap/nodes";
import {IEdit} from "./edit_helper";
import {Severity} from "./severity";
 
interface IIssueData {
  filename: string;
  message: string;
  key: string;
  start: Position;
  end: Position;
  severity: Severity;
  fix?: IEdit;
}
 
export class Issue {
  private readonly data: IIssueData;
 
  //////////////////////////
 
  public static atRow(file: IFile, row: number, message: string, key: string, severity?: Severity) {
    const start = new Position(row, 1);
    const end = new Position(row, file.getRawRows()[row - 1].length + 1);
    severity = severity ?? Severity.Error;
    return new Issue({
      filename: file.getFilename(),
      message,
      key,
      start,
      end,
      severity,
    });
  }
 
  public static atStatement(file: IFile, statement: StatementNode, message: string, key: string, severity?: Severity, fix?: IEdit) {
    return this.atRange(file, statement.getStart(), statement.getEnd(), message, key, severity, fix);
  }
 
  public static atPosition(file: IFile, start: Position, message: string, key: string, severity?: Severity, fix?: IEdit) {
    const row = start.getRow();
    const end = new Position(row, file.getRawRows()[row - 1].length + 1);
    severity = severity ?? Severity.Error;
    return new Issue({
      filename: file.getFilename(),
      message,
      key,
      start,
      end,
      fix,
      severity,
    });
  }
 
  public static atRowRange(file: IFile, row: number, startCol: number,
                           endCol: number, message: string, key: string, severity?: Severity, fix?: IEdit) {
    const start = new Position(row, startCol);
    const end = new Position(row, endCol);
    severity = severity ?? Severity.Error;
    return new Issue({
      filename: file.getFilename(),
      message,
      key,
      start,
      end,
      fix,
      severity,
    });
  }
 
  public static atRange(file: IFile, start: Position, end: Position, message: string, key: string, severity?: Severity, fix?: IEdit) {
    severity = severity ?? Severity.Error;
    return new Issue({
      filename: file.getFilename(),
      message,
      key,
      start,
      end,
      fix,
      severity,
    });
  }
 
  public static atToken(file: IFile, token: Token, message: string, key: string, severity?: Severity, fix?: IEdit) {
    severity = severity ?? Severity.Error;
    return new Issue({
      filename: file.getFilename(),
      message,
      key,
      start: token.getStart(),
      end: token.getEnd(),
      severity,
      fix,
    });
  }
 
  public static atIdentifier(identifier: Identifier, message: string, key: string, severity?: Severity, fix?: IEdit) {
    severity = severity ?? Severity.Error;
    return new Issue({
      filename: identifier.getFilename(),
      message,
      key,
      start: identifier.getStart(),
      end: identifier.getEnd(),
      severity,
      fix,
    });
  }
 
  public constructor(data: IIssueData) {
    this.data = data;
 
    if (this.data.start instanceof VirtualPosition) {
      // no quick fixes inside macros
      this.data.fix = undefined;
    }
 
    if (this.data.start.getCol() < 1) {
      throw new Error("issue, start col < 1");
    } else if (this.data.end.getCol() < 1) {
      throw new Error("issue, end col < 1");
    }
  }
 
  public getData(): IIssueData {
    return this.data;
  }
 
  public getMessage(): string {
    return this.data.message;
  }
 
  public getKey(): string {
    return this.data.key;
  }
 
  public getStart(): Position {
    return this.data.start;
  }
 
  public getEnd(): Position {
    return this.data.end;
  }
 
  public getFilename(): string {
    return this.data.filename;
  }
 
  public getFix() {
    return this.data.fix;
  }
 
  public getSeverity() {
    return this.data.severity;
  }
 
}