All files / src printer.ts

93.75% Statements 15/16
50% Branches 3/6
100% Functions 3/3
93.75% Lines 15/16
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        2x             4x 4x     1x   1x 1x 1x 1x 1x 1x     1x       1x 1x         1x       2x  
import { IChecker } from "./checker/interface";
import { Query } from "./reader/query";
import { IFormat } from "./formatter/interface";
 
import chalk from "chalk";
 
class Printer {
  public verbosity: number;
  public format: IFormat;
 
  constructor(verbosity: number, format: IFormat) {
    this.verbosity = verbosity;
    this.format = format;
  }
  public printCheck(checker: IChecker, tokenised: Query, prefix: string) {
    const result = checker.check(tokenised);
 
    Eif (this.verbosity) {
      const queryForPrint = JSON.stringify(tokenised.getContent());
      const promptForPrint = `Linting Query: ${queryForPrint}`;
      const tokenisedForPrint = JSON.stringify(tokenised, null, 4);
      console.log(chalk.blue(promptForPrint));
      console.log(chalk.yellow(`${tokenisedForPrint}`));
    }
 
    Iif (result.content) {
      console.log(this.format.getMessage(prefix, result));
    }
 
    Eif (this.verbosity) {
      console.log("\n-------------------------\n");
    }
  }
 
  public warnAboutFileNotFound(file: string) {
    console.log(`Can't open file ${file}. Does it exist?`);
  }
}
 
export { Printer };