First, what is sonar?
Sonar is an open source platform for code quality Management that manages the quality of source code through plug-in forms, and can support including Java,c#,c/c++,pl/sql,cobol,javascrip, Groovy, etc. code quality management and detection in more than 20 programming languages
Sonar can detect code quality from the following seven dimensions, and as a developer, at a minimum, the top 5 code quality issues need to be addressed
1. do not follow the code standard sonar can be written by Code Rule Detection Tool specification code PMD,CHECKSTYLE,FINDBUGS etc.
2. potential flaw sonar can detect potential defects through code rule detection tools such as pmd,checkstyle,findbugs, etc.
3. poor complexity distribution files, classes, methods, etc., if the complexity is too high will be difficult to change, which makes it difficult for developers to understand them and if there is no automated unit testing, any component changes in the program will likely lead to the need for comprehensive regression testing
4. duplication Obviously the program contains a lot of copy and paste code is poor quality, sonar can show the source of repeated serious place
5. insufficient comments or too many comments will make the code less readable, especially when people change inevitably, the readability of the program will be greatly reduced and too much comment will cause the developer to spend too much time on reading the comments, also contrary to the original intention
6. lack of unit test Sonar makes it easy to count and present unit test coverage
7. bad design through sonar can find loops, show packages and packages, classes and classes interdependencies, can detect custom schema rules through sonar can manage third-party jar packages, can use LCOM4 to detect the application of a single task rule, detect coupling.
Citation from Open source China Community: Code Quality Management Platform Sonar
More code analysis tools can be viewed: analysis and comparison of common Java static code analysis tools
Second, how to use Sonar (eclipse/myeclipse)
The first thing to note is
Sonar's official website says the Eclipse plugin has been discontinued since the beginning of this October 2015.
Instead, use Sonarlint to accomplish the same function.
If remember correctly, this website is need FQ, waste a lot of my time.
Enter Sonarlint official website
Click Download to enter the following page
Drag the install picture to see how Eclipse installs
In Eclipse, you can click Eclipse Marketplace to search Sonarlint and install the displayed click-to-Install
MyEclipse can be help>install from the catalog to search Sonarlint, to install, is actually the same
Reboot after installation
Here you can see how Sonarlint online eclipse is using video tutorials
Iii. Examples of Use
Right-click Project->configure->enable sonarlint
You can see a change in the upper right corner of the item
Then right-click the project->sonarlint->anaylse all files to
Open the appropriate view to view
You can see in the file that the code is in the wrong place.
As a hint, I should return directly instead of assigning a temporary variable first
After modification, such as
Then I'm prompted to add the override annotations
As you can see, the warning disappears when the annotation is added.
This is the power of sonar, which can be found in many potential errors.
< transfer from:http://www.cnblogs.com/lzb1096101803/p/4945844.html>
Sonarlint (Sonar) Code Quality Management