安裝SonarQube插件
在VScode的擴展里面,安裝SonarQube support for Visual Studio Code extension志膀,
在安裝了 SonarQube 之后唱歧,使用打開 VSCode 命令搜索功能岖免,輸入 Sonar,搜索結果如下:
sonar lint 全局配置文件
(1)選擇 Create global config with credentials to servers
(2)選擇Open global.json合愈,sonar lint 全局配置文件被打開叮贩,
{
"$schema": "https://raw.githubusercontent.com/silverbulleters/sonarqube-inject-vsc/master/schemas/global.json",
"servers": [
{
"id": "localhost",
"url": "http://localhost:9000",
"token": "YOUR_SONARQUBE_AUTH_TOKEN"
},
{
"id": "my-company-server",
"url": "http://my-company.com",
"token": "YOUR_SONARQUBE_AUTH_TOKEN"
}
]
}
(3)接下來只需要自定義上圖對應字段(上圖兩個配置項只需定義一個即可)
- id:與具體工程關聯(lián)的唯一標識符,在具體工程配置文件中會用到
- url:sonar server 所在的地址
- token:能進入 sonar server 的用于驗證用戶身份的一串字符
sonar lint 工程配置文件
(1)選擇 Create local sonarlinet config with project binding
(2)選擇 Open sonarlint.json佛析,sonar lint 工程配置文件被打開益老,
{
"serverId": "my-company-server",
"projectKey": "my-project"
}
(3)接下來自定義上圖對應字段,
- serverId:即配置全局文件時的 id
- projectKey:sonar server 上的工程唯一標識
其他命令
- Analyze current file:重新分析當前文件
- Analyze current project:重新分析當前工程所有文件
- Update bindings to SonarQube server:更新來自 Sonar Server 的規(guī)則