Implement/integrate SonarQube 中的 ESLint?

Implement/integrate ESLint in SonarQube?

请问如何在我们的 Azure Pipeline 上实现 ESLint?我对 Azure Pipelines 和 SonarQube 的了解不够,对 ESLint 也不太了解。到目前为止,这是我的脚本。虽然这几乎来自可用任务。我想像这样在 SonarQube 上实现 ESLint link: 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",

您的 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 配置文件。

运行 在您的本地存储库中执行以下命令,然后推送到您的源服务器。

添加eslint依赖:

npm install eslint --save-dev

生成 ESLint 配置文件

./node_modules/.bin/eslint --init

您可以查看this blog