SonarQube Pre-commit analysis for JavaScript - sonarqube

I need to find a way to do a pre-commit incremental analysis with rules supplied by SonarQube 5.4 hosted on a server. The most important files to analyze are JavaScript files, and we are working in C# using ASP.NET framework, so installing Eclipse for a large team is not feasible.
I have tried Sonar-Scanner 2.8, but it does not pick up the analysis already done on the server (shows all issues as new), and it also does not react to exclusions. Documentation on that matter is outdated, as, for example, incremental analysis is not supported anymore, and issues analysis is not documented properly regarding what it does,
Some relevant parts from sonar-project.properties:
sonar.exclusions=**/Scripts/*angular*.js,**/Scripts/*bootstrap*.js,**/Scripts/*d3*.js,**/Scripts/*jquery*.js,**/Scripts/*modernizr*.js,**/Scripts/*respond*.js,**/Scripts/*toolkit*.js,**/tbshared/**/*.*,**/Scripts/*reference*.js,**/packages/**/*.*,**/Scripts/angular*.map,**/Scripts/*.json,**/Scripts/*.css,**/Scripts/i18n/*.*
...
#Enable HTML
sonar.issuesReport.html.enable=true
#Enable console output
sonar.issuesReport.console.enable
#Enable incremental analysis
sonar.analysis.mode=issues

Maybe one day SonarLint for Visual Studio will be extended to cover more languages than just C#.
But as of today you can take a look at:
SonarLint for Command Line
GitHub Plugin
All those links are available in SonarQube documentation on page "Local and Branch Analysis".

Related

Difference between using TSLINT vs Sonarqube?

For many years i have used the available linting files provided in the angular projects created through CLI. Mainly TSLINT rules to lint the project.
I have also learnt that even SONARQUBE checks for code quality through a remote server.
But can someone explain what exactly is the main functional difference between USING A LINT FILE vs using SONARQUBE ?
Which system is best to use ?
Or is it we can use both of them together ?
Some differences have been highlighted here.
What is SonarQube?
SonarQube provides an overview of the overall health of your source code and even more importantly, it highlights issues found on new code. With a Quality Gate set on your project, you will simply fix the Leak and start mechanically improving.
What is TSLint?
An extensible static analysis tool that checks TypeScript code for readability, maintainability, and functionality errors. It is widely supported across modern editors & build systems and can be customized with your own lint rules, configurations, and formatters.
Both tools can be classified as static code analysis tool, aiming to find potential problems in your code. TSLint is more customisable w.r.t. coding rules, and SonarQube does more than static code analysis because it also provides feedback on security/vulnerabilities issues.

Sonar Qube report generation either as csv,xml or pdf

I'm using sonarqube-7.3 version. I want to make report from sonarqube either as csv, xml or pdf. I have googled it and found that we can make pdf report using sonar-pdfreport-plugin. I have dowload the version sonar-pdfreport-plugin-1.4 and pasted it in the extension/pluggin folder. But I can't restart the server. Anyone please provide a solution for getting report for the version provided above.
In general, SonarQube is not meant to be used as some reporting tool, but more as part of CI pipeline and users can use it's UI to manage code quality issues.
However, PDF reporting is available in the commercial Enterprise Edition of SonarQube for portfolios (groups of projects) as part of Governance. You can find details here https://www.sonarsource.com/plans-and-pricing/enterprise/
The plugin you are mentioning is most likely not updated for the 7.3 version

How to set reporting level for sonar preview analysis

We are using the sonar github plugin to generate preview analysis for pull request as described here. This works beautifully but because we are working with a lot of legacy code is it possible to:
Set a minimum level for preview analysis (major and above)?
Ignore existing existing issues and only report on new ones?

Using sonar in pretty big team

We have something about 20 people in our team and we are using sonar for now to analyse new code before submiting it to the main stream. So each designer uses it's own Sonar installed on his machine.
What I'm trying to do is to create a one instance of the Sonar which each designer will be able to use. The only concern I have is what will happen if:
One designer will launch analysis on one revision of file and right after that the second designer will launch analysis on another revision of this file (in the worst case we can have a bunch of such a files). First designer won't be able to see his violations and won't be able to see code he wrote at all. Do we have some mechanism to overcome this?
What will happen if two designers will analyse the same project at the same time? AFAIK, Sonar won't allow them to do so. Any workaround for this?
Of course, we can, somaehow, create a project on the sonar side for each team member, but this has it's drawbacks, such as issues, marked as false positive in one proect won't appear as such an issues in another project and so on.
Any ideas on such an issues?
What you probably want to set up is:
a central Sonar instance that analyses the code base on a regular basis (for instance every day) based on the code located in the repository. This instance should be the reference and the project manager(s) will use it to monitor the project.
ask the developers to run local analyses before commiting their code:
either using Sonar Eclipse if you're coding in Java, C++ or Python. Everything is perfectly described in the documentation, more precisely the "Checking code prior to commit" section
or using the Issues Report plugin if your language is not supported yet in Sonar Eclipse.

Is SonarQube Replacement for Checkstyle, PMD, FindBugs?

We are working on a web project from scratch and are looking at the following static code analysis tools.
Conventions (Checkstyle)
Bad practices (PMD)
Potential bugs (FindBugs)
The project is built on Maven. Instead of using multiple tools for the purpose, I was looking at a single flexible solution and came across SonarQube.
Is it true that we can achieve the results from Checkstyle, PMD and Findbugs with SonarQube?
Sonar will run CheckStyle, FindBugs and PMD, as well as a few other "plugins" such as Cobertura (code coverage) by default for Java projects. The main added value, however, is that it stores the history in a database. You can then see the trend. Are you improving the code base or are you doing the opposite? Only a tool with memory can tell you that.
You should run Sonar in your CI system so that even things that take some time to execute (such as CPD – copy paste detector) can run. And you'll have your history. Whereas with an Eclipse plugin, for example, you'll detect violations sooner – which is great – but you will be tempted to run it less often if it starts taking too long, or run less "quality plugins" (such as skipping CPD or skipping code coverage analysis). And you won't have history.
Also, Sonar generates visual reports, "Dashboard" style. Which makes it very easy to grasp. With Sonar in Jenkins, you'll be able to show developers and your management the effects of the work that was performed on the quality of the code base over the last few weeks and months.
Sonar uses these 3 tools as plugins and aggregates the data from all three giving addition value by showing graphs and such from these tools. So they are complementary to sonar.
Yes and no. In addition to the other answers.
SonarQube is currently on the way to deprecate PMD, Checkstyle and Findbugs and use their own technology to analyze Java code (called SonarJava). They do it, because they don't want to spend their time fixing, upgrading (or waiting on it) those libraries (e.g. for Java 8), which for example uses outdated libraries.
They also got a new set of plugins for your personal IDE called SonarLint.
Sonar is great, but if you want to use the mentioned tools separately and still have nice graphs, you can use the Analysis Collector Plugin as part of your Jenkins CI build. A slight advantage of this is that you can check in your PMD/Findbugs/Checkstyle configuration into your SCM and have it integrated into your Maven build, rather than relying on a separate Sonar server.
... a few years later: no, it is not! SonarQube supposes to be able to cover all the rules with its own analyzer, but there are still rules from PMD or CheckStyle not covered by SonarQube. See for example: PMD ReturnFromFinallyBlock.
Sonar is much more than these tools alone.
The greatest benefits is the gui, which lets you configure anything easily.
The statistics it offers are very detailed (lines of code etc).
And it even offers great support for test coverage etc :)
Here you can take a good look:
http://nemo.sonarsource.org/
I would still use these tools in addition to sonar because they can fail the maven build when someone violates a rule. Where as sonar is more retrospective.
Well at least since SonarQube 6.3+ it seems to be that Findbugs is (at the moment) no longer supported as a plugin. Sonarsource is working on replacements of Findbugs-rules with its own Java-plugin.
They even had a list for the replacement status of each rule here, but it got removed by now.
See https://community.sonarsource.com/t/where-is-dist-sonarsource-com-content/5353 for more details.

Resources