2025-02-05 08:29:52 +00:00
|
|
|
package com.freeleaps.devops.lint
|
|
|
|
|
|
|
|
|
|
import com.freeleaps.devops.enums.CodeLinterTypes
|
|
|
|
|
import com.freeleaps.devops.lint.LinterBase
|
|
|
|
|
|
|
|
|
|
class ESLint extends LinterBase {
|
2025-02-07 09:31:27 +00:00
|
|
|
def eslintVersion
|
|
|
|
|
def plugins
|
2025-02-07 07:18:40 +00:00
|
|
|
|
2025-02-07 09:31:27 +00:00
|
|
|
ESLint(steps, workspace, configs, eslintVersion, plugins) {
|
2025-02-05 08:29:52 +00:00
|
|
|
super(steps, workspace, configs, CodeLinterTypes.ESLINT)
|
2025-02-07 09:31:27 +00:00
|
|
|
this.eslintVersion = eslintVersion
|
|
|
|
|
this.plugins = plugins
|
2025-02-05 08:29:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def doLint() {
|
2025-02-07 08:16:43 +00:00
|
|
|
steps.dir(workspace) {
|
2025-02-07 09:31:27 +00:00
|
|
|
steps.log.info("${linterType.linter}", "Install eslint with version: ${eslintVersion}")
|
|
|
|
|
steps.sh("npm install -g eslint@${eslintVersion}")
|
2025-02-07 08:16:43 +00:00
|
|
|
steps.log.info("${linterType.linter}", "Install eslint dependencies...")
|
2025-02-07 09:31:27 +00:00
|
|
|
steps.sh("npm install -g ${plugins.join(' ')}")
|
2025-02-07 08:53:17 +00:00
|
|
|
// check if given config file is not end with .json
|
2025-02-07 09:02:11 +00:00
|
|
|
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")
|
2025-02-07 09:10:18 +00:00
|
|
|
configs = "${configs}.js"
|
2025-02-07 08:53:17 +00:00
|
|
|
}
|
2025-02-07 08:16:43 +00:00
|
|
|
steps.log.info("${linterType.linter}", "Running eslint...")
|
|
|
|
|
steps.sh("eslint --config ${configs} ${workspace}")
|
|
|
|
|
}
|
2025-02-05 08:29:52 +00:00
|
|
|
}
|
|
|
|
|
}
|