freeleaps-ops/first-class-pipeline/src/com/freeleaps/devops/lint/ESLint.groovy

36 lines
1.1 KiB
Groovy
Raw Normal View History

package com.freeleaps.devops.lint
import com.freeleaps.devops.enums.CodeLinterTypes
import com.freeleaps.devops.lint.LinterBase
class ESLint extends LinterBase {
def deps = [
'eslint-define-config',
'eslint-config-prettier',
'eslint-plugin-prettier',
'eslint-plugin-vue',
'@typescript-eslint/eslint-plugin',
'@typescript-eslint/parser',
'typescript'
]
ESLint(steps, workspace, configs) {
super(steps, workspace, configs, CodeLinterTypes.ESLINT)
}
def doLint() {
steps.dir(workspace) {
steps.log.info("${linterType.linter}", "Install eslint dependencies...")
steps.sh("npm install -g ${deps.join(' ')}")
// check if given config file is not end with .json
if (!configs.endsWith('.js')) {
steps.log.warn("${linterType.linter}", "Invalid eslint configuration file, must be a JS file, convert file as valid JS file...")
steps.sh("mv ${configs} ${configs}.js")
configs = "${configs}.json"
}
steps.log.info("${linterType.linter}", "Running eslint...")
steps.sh("eslint --config ${configs} ${workspace}")
}
}
}