feat(lint): enhance ESLint integration by adding version and plugin support
Signed-off-by: 孙振宇 <>
This commit is contained in:
parent
ab424b3d65
commit
f9a0b7893a
@ -1,4 +1,5 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
parser: "@typescript-eslint/parser",
|
||||
parserOptions: {
|
||||
ecmaVersion: 6,
|
||||
|
||||
@ -10,8 +10,9 @@ class CodeLintExecutor {
|
||||
def workspace
|
||||
def configs
|
||||
def linterType
|
||||
def component
|
||||
|
||||
CodeLintExecutor(steps, workspace, configs, linterType) {
|
||||
CodeLintExecutor(steps, workspace, configs, linterType, component) {
|
||||
this.steps = steps
|
||||
this.workspace = workspace
|
||||
this.configs = configs
|
||||
@ -43,7 +44,11 @@ class CodeLintExecutor {
|
||||
linter = new PyLint(steps, workspace, configs)
|
||||
break
|
||||
case CodeLinterTypes.ESLINT:
|
||||
linter = new ESLint(steps, workspace, configs)
|
||||
if (component.eslintVersion == null || component.eslintVersion.isEmpty()) {
|
||||
steps.log.error("CodeLintExecutor", "ESLint version is required")
|
||||
return
|
||||
}
|
||||
linter = new ESLint(steps, workspace, configs, component.eslintVersion, component.eslintPlugins)
|
||||
break
|
||||
default:
|
||||
steps.log.error("CodeLintExecutor", "Unknown linter type")
|
||||
|
||||
@ -4,25 +4,21 @@ import com.freeleaps.devops.enums.CodeLinterTypes
|
||||
import com.freeleaps.devops.lint.LinterBase
|
||||
|
||||
class ESLint extends LinterBase {
|
||||
def eslintVersion
|
||||
def plugins
|
||||
|
||||
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) {
|
||||
ESLint(steps, workspace, configs, eslintVersion, plugins) {
|
||||
super(steps, workspace, configs, CodeLinterTypes.ESLINT)
|
||||
this.eslintVersion = eslintVersion
|
||||
this.plugins = plugins
|
||||
}
|
||||
|
||||
def doLint() {
|
||||
steps.dir(workspace) {
|
||||
steps.log.info("${linterType.linter}", "Install eslint with version: ${eslintVersion}")
|
||||
steps.sh("npm install -g eslint@${eslintVersion}")
|
||||
steps.log.info("${linterType.linter}", "Install eslint dependencies...")
|
||||
steps.sh("npm install -g ${deps.join(' ')}")
|
||||
steps.sh("npm install -g ${plugins.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...")
|
||||
|
||||
4
first-class-pipeline/tests/Jenkinsfile
vendored
4
first-class-pipeline/tests/Jenkinsfile
vendored
@ -47,6 +47,10 @@ executeFreeleapsPipeline {
|
||||
lintEnabled: true,
|
||||
// linter used to specify the code linter
|
||||
linter: 'eslint',
|
||||
// eslintVersion used to specify the eslint version
|
||||
eslintVersion: '7.32.0',
|
||||
// eslintPlugins used to specify the eslint plugins
|
||||
eslintPlugins: ['eslint-plugin-vue@8.0.3'],
|
||||
// linterConfig used to specify the code linter configuration file path, if not set, will use the default configuration
|
||||
// linterConfig: '.eslintrc.js',
|
||||
// sastEnabled used to specify whether to enable SAST scan
|
||||
|
||||
@ -142,7 +142,7 @@ def generateComponentStages(component, configurations) {
|
||||
|
||||
def linterType = CodeLinterTypes.parse(component.linter)
|
||||
|
||||
def codeLintExecutor = new CodeLintExecutor(this, env.workroot + "/" + component.root + "/", component.linterConfig, linterType)
|
||||
def codeLintExecutor = new CodeLintExecutor(this, env.workroot + "/" + component.root + "/", component.linterConfig, linterType, component)
|
||||
codeLintExecutor.execute()
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user