VSCode 配置 Sonar Lint

安裝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ī)則
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容