fix(lint): enhance ESLint configuration handling and improve caching for npm and yarn

Signed-off-by: 孙振宇 <>
This commit is contained in:
孙振宇 2025-02-07 16:53:17 +08:00
parent bdb5d7e1a5
commit f9d10df52d
2 changed files with 8 additions and 2 deletions

View File

@ -65,7 +65,7 @@ class DependenciesResolver {
if (cachingEnabled) { if (cachingEnabled) {
steps.dir(this.workspace) { steps.dir(this.workspace) {
steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', includes: '**/*', path: '.npm-cache']]) { steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', includes: '**/*', path: '.npm-cache', cacheValidityDecidingFile: 'package-lock.json']]) {
steps.sh "npm install --cache .npm-cache" steps.sh "npm install --cache .npm-cache"
} }
} }
@ -87,7 +87,7 @@ class DependenciesResolver {
if (cachingEnabled) { if (cachingEnabled) {
steps.dir(this.workspace) { steps.dir(this.workspace) {
steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', includes: '**/*', path: '.yarn-cache']]) { steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', includes: '**/*', path: '.yarn-cache', cacheValidityDecidingFile: 'yarn.lock']]) {
steps.sh "yarn install --cache-folder .yarn-cache" steps.sh "yarn install --cache-folder .yarn-cache"
} }
} }

View File

@ -23,6 +23,12 @@ class ESLint extends LinterBase {
steps.dir(workspace) { steps.dir(workspace) {
steps.log.info("${linterType.linter}", "Install eslint dependencies...") steps.log.info("${linterType.linter}", "Install eslint dependencies...")
steps.sh("npm install -g ${deps.join(' ')}") steps.sh("npm install -g ${deps.join(' ')}")
// check if given config file is not end with .json
if (!configs.endsWith('.json')) {
steps.log.warn("${linterType.linter}", "Invalid eslint configuration file, must be a JSON file, convert file as valid JSON file...")
steps.sh("mv ${configs} ${configs}.json")
configs = "${configs}.json"
}
steps.log.info("${linterType.linter}", "Running eslint...") steps.log.info("${linterType.linter}", "Running eslint...")
steps.sh("eslint --config ${configs} ${workspace}") steps.sh("eslint --config ${configs} ${workspace}")
} }