安裝SonarQube插件
在VScode的擴(kuò)展里面,安裝SonarQube support for Visual Studio Code extension,
在安裝了 SonarQube 之后,使用打開(kāi) VSCode 命令搜索功能,輸入 Sonar,搜索結(jié)果如下:
sonar lint 全局配置文件
(1)選擇 Create global config with credentials to servers
(2)選擇Open global.json,sonar lint 全局配置文件被打開(kāi),
{
"$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)接下來(lái)只需要自定義上圖對(duì)應(yīng)字段(上圖兩個(gè)配置項(xiàng)只需定義一個(gè)即可)
- id:與具體工程關(guān)聯(lián)的唯一標(biāo)識(shí)符,在具體工程配置文件中會(huì)用到
- url:sonar server 所在的地址
- token:能進(jìn)入 sonar server 的用于驗(yàn)證用戶(hù)身份的一串字符
sonar lint 工程配置文件
(1)選擇 Create local sonarlinet config with project binding
(2)選擇 Open sonarlint.json,sonar lint 工程配置文件被打開(kāi),
{
"serverId": "my-company-server",
"projectKey": "my-project"
}
(3)接下來(lái)自定義上圖對(duì)應(yīng)字段,
- serverId:即配置全局文件時(shí)的 id
- projectKey:sonar server 上的工程唯一標(biāo)識(shí)
其他命令
- Analyze current file:重新分析當(dāng)前文件
- Analyze current project:重新分析當(dāng)前工程所有文件
- Update bindings to SonarQube server:更新來(lái)自 Sonar Server 的規(guī)則