package com.freeleaps.devops.lint

interface Linter {
  def lint()
}

abstract class LinterBase implements Linter {
  def steps
  def workspace
  def configs
  def linterType

  LinterBase(steps, workspace, configs, linterType) {
    this.steps = steps
    this.workspace = workspace
    this.configs = configs
    this.linterType = linterType
  }

  def lint() {
    steps.log.info("${linterType.linter}", "Linting ${linterType.language.language} code")
    steps.log.info("${linterType.linter}", "Workspace sets to: ${workspace}")

    if (configs == null || configs.isEmpty()) {
      steps.log.error("${linterType.linter}", "Not set configurations file, linter configuration file is required")
    }
    steps.log.info("${linterType.linter}", "Using ${configs} as configurations file")

    doLint()
    steps.log.info("${linterType.linter}", "Code linting has been completed")
  }

  abstract def doLint()
}