【问题标题】:Implement/integrate ESLint in SonarQube?在 SonarQube 中实现/集成 ESLint?
【发布时间】:2021-04-13 22:56:05
【问题描述】:

我想问一下如何在我们的 Azure Pipeline 上实现 ESLint?我对 Azure Pipelines 和 SonarQube 没有足够的了解,而且我对 ESLint 也不太确定。到目前为止,这是我的脚本。虽然这几乎来自可用的任务。我想在 SonarQube 上实现 ESLint,如下链接:https://docs.sonarqube.org/pages/viewpage.action?pageId=11639183

steps:
  - task: NodeTool@0
    inputs:
      versionSpec: '10.x'
      checkLatest: true
    displayName: 'Install Node.js'

  - task: Npm@1
    inputs:
      command: 'install'
    displayName: 'NPM Install'
    
  - script: |
      npm bin -g
    displayName: 'Check path'

  - task: Npm@1
    inputs:
      command: 'custom'
      customCommand: 'test' #from the package.json

这里的这个来自 npm bin -g:

##[debug]   /home/vsts/work/_temp/5b2e34ae-e8f8-4e24-a539-9d41f7435789.sh
/bin/bash --noprofile --norc /home/vsts/work/_temp/5b2e34ae-e8f8-4e24-a539-9d41f7435789.sh
/opt/hostedtoolcache/node/10.23.1/x64/bin
##[debug]Exit code 0 received from tool '/bin/bash'
##[debug]STDIO streams have closed for tool '/bin/bash'
##[debug]task result: Succeeded
##[debug]Processed: ##vso[task.complete result=Succeeded;done=true;]

这是上一个任务的错误。

##[debug]Agent.BuildDirectory=/home/vsts/work/1
##[debug]rm -rf /home/vsts/work/1/npm
##[debug]removing directory
##[debug]task result: Failed
##[error]Error: Npm failed with return code: 1
##[debug]Processed: ##vso[task.issue type=error;]Error: Npm failed with return code: 1
##[debug]Processed: ##vso[task.complete result=Failed;]Error: Npm failed with return code: 1

这是我的 package.json 的一些副本:

"scripts": {
    "lint": "npm run lint:lwc && npm run lint:aura",
    "linter": "./node_modules/.bin/eslint ./",
    "lint:aura": "eslint **/aura/**",
    "lint:lwc": "eslint **/lwc/**",
    "test": "npm run test:unit",

【问题讨论】:

    标签: azure-devops sonarqube yaml eslint


    【解决方案1】:

    您的 yaml 管道中没有用于运行 linter 的任务或命令。您可以添加脚本任务或 npm 任务来运行 linter。见下文:

    添加一个 npm 任务来运行 linter。

    - task: Npm@1
      inputs:
        command: 'install'
      displayName: 'NPM Install'
    
    - task: Npm@1
      displayName: 'Linter'
      inputs:
        command: 'custom'
        customCommand: 'run linter'
    

    或者添加一个脚本任务来运行 linter:

    - task: Npm@1
      inputs:
        command: 'install'
      displayName: 'NPM Install'
    
    - script: |
        npm run linter
        npm run lint  #run npm run lint:lwc && npm run lint:aura in your package.json
    

    在您可以在 azure 管道中运行上述 linter 命令之前。你需要在你的项目中添加 eslint 依赖,并在你的本地机器上生成你的 ESLint 配置文件。

    在本地 repo 上运行以下命令,然后推送到源服务器。

    添加 eslint 依赖:

    npm install eslint --save-dev
    

    生成 ESLint 配置文件

    ./node_modules/.bin/eslint --init
    

    您可以查看this blog

    【讨论】:

    • 您好,感谢您的回答。我能够继续前进。虽然我仍然遇到错误。我有 .eslintrc 并将其推送到根文件夹。 (其中 package.json 也是如此)但是,我仍然遇到错误。非常遗憾。我是 Azure 和 ESLint 的新手。 ##[debug]从工具 '/bin/bash' 收到的退出代码 1 ##[debug]STDIO 流已为工具 '/bin/bash' 关闭 ##[error]Bash 以代码 '1' 退出。 ##[debug]Processed:##vso[task.issue type=error;]Bash 退出,代码为“1”。 ##[debug]任务结果:失败##[debug]已处理:##vso[task.complete result=Failed;done=true;]
    • 没关系,我刚刚在任务中添加了 continueOnError。但是我想问为什么它会抛出错误?
    • @PercyJackson 您的测试可能有问题。您可以通过Enabling system diagnostics 对更详细的日志进行故障排除
    猜你喜欢
    • 2015-12-07
    • 2019-03-10
    • 2017-06-09
    • 2016-11-03
    • 2016-10-18
    • 1970-01-01
    • 2019-08-04
    • 2017-08-13
    • 2017-10-04
    相关资源
    最近更新 更多