Disclaimer: The following are some of the techniques on to the Web search, due to the distance of this writing over a period of time, can no longer find the original URL,
Not signed copyright, owned by the original author appropriate way, to express my gratitude.
Previously: local installation SonarQube Community8.1 Community Edition code quality control has been explained in detail SonarQube Community Edition installation method
This article will guide you how to use IDEA plug-sonarlint code quality inspection and repair.
son Lint
Menu path: File - Setting-Plugin input SonarLint search plugin
SonarLint is an IDE extension that helps you detect and fix quality issues as you write code. Like a spell checker, SonarLint squiggles flaws so they can be fixed before committing code.
You can get it directly from the IntelliJ IDEA Plugin Repository, and it will then detect new bugs and quality issues as you code (Java, Kotlin, Ruby, JavaScript, PHP and Python).
If your project is analyzed on SonarQube or on SonarCloud, SonarLint can connect to the server to retrieve the appropriate quality profiles and settings for that project. Java 8 is required to run SonarLint.
main idea:
SonarLint is an IDE extensions can help you detect and fix quality problems when writing code. Like the spell checker, SonarLint will draw a line defect in the code below, in order to fix these defects before submitting code.
You can get it directly from the IntelliJIDEA plugin repository, when you write code (Java, Kotlin, Ruby, JavaScript, PHP and Python) then it will detect new errors and quality problems.
If you analyze your project on SonarQube or SonarCloud, SonarLint can connect to the server to retrieve the appropriate quality of the project profiles and settings. Run SonarLint demand Java 8.
Configure the plugin
1, placed Token
Open local SonarQube management background, enter the account password, the default admin / admin
Create a project
In an arbitrary circle above, click New Project
Create a token
Get token
After the success of plug-in installed, open the plug-in configuration interface, path: File - Setting-Other Setting
Open SonarLint General Settings, in accordance with the input of FIG.
把上一步的token输入(写博客截图,忘记保存了token,下面是错误的)
2、绑定到当前项目
打开SonarLint Project Settings
connection选择刚刚的配置“local”,选择我们刚刚创建的项目
3、项目文件分析
配置好以后打开IDEA,查看控制台SonarLint选项卡
3.1、单个文件分析
点击左侧按钮分析,会分析当前这被打开的文件,比如笔者本地打开tts_offline.js
他会立马分析tts_offline.js这个文件
3.2、项目全局分析
右键项目:选择SonarLint--Analyze with SonarLint
检测结果
登录SonarQube管理后台 http://localhost:9000后台效果,查看质检效果
3.3、maven方式使用SonarQube
各位看官,可以使用以上方法去检查项目潜在质量问题,当然也可以使用maven,maven配置如下
代码
<profiles> <profile> <id>sonar</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <sonar.host.url>http://127.0.0.1:9000/</sonar.host.url> </properties> </profile> </profiles> <plugins> <plugin> <groupId>org.sonarsource.scanner.maven</groupId> <artifactId>sonar-maven-plugin</artifactId> <version>3.6.0.1398</version> </plugin> </plugins>
maven使用方法:
mvn sonar:sonar
4 笔者自己的方法
以上方法在提交代码的时候浪费大量时间检查质量,笔者在网络上找到一个办法,直接用命令行方式运行
codeAnalysis.bat
mvn sonar:sonar -Dsonar.projectKey=test -Dsonar.host.url=http://localhost:9000 -Dsonar.login=be2a8b0cf932f7294680895e152049439675b912
保存以上文件,双击执行即可把质量问题提交到sonarQube平台
如果卸载SonarLint,请参考:IDEA中关闭sonar代码质量检测