There have been some questions about this, but none of them solves my problem.
I use SonarQube to do code analysis on one of my projects, which contain a Migrations directory. I would like to exclude all the source files in that directory from the code analysis.
In the projects Configuration->Settings->Exclusions->Files->Source Files Exclusions I added "**/Migrations/.", but in the analysis results I still get issues in code files in that directory.
The directory structure of my project looks like this: \MyProject\Migrations\SourceFile.cs
What am I doing wrong? Am I entering the wildcard in the wrong place, or my wildcard is wrong?
In the logs I can see
13:06:23.460 INFO - Copy-paste detection exclusions:
13:06:23.476 **/Migrations/*.*
but then I can also see
13:06:12.076 INFO - Inspecting <MyProject>\Migrations\SourceFile.cs
That's the correct place to set it up. Please try simply /Migrations/** or /MyProject/Migrations/**. When you go to one of the issues you want to get rid of, you'll see what your "regex" path should start with.
And one more tip: To see result, you have to rebuild the project, run sonar again. And again, until you get it right.
I had to use a different setting.
Instead of Configuration->Settings->Exclusions->Files->Source Files Exclusions I had to use Configuration->Settings->Exclusions->Issues->Ignore Issues on Multiple Criteria.
In this setting, I had to set the RULE KEY PATTERN to *, and I had to set the path wildcard in the FILE PATH PATTERN, **/Migrations/. works perfectly.
Related
I'm wresting with SonarQube reporting errors on C# files which I didn't write. For example, I might import a particular piece of code from an open source library where I didn't want to take the entire library as a dependency.
This usually raises a lot of SQ warnings.
Instead of dealing with these one by one, is there a way to just mark the entire file to be ignored? I'n thinking something similar to the new #nullable disable directive.
Thanks very much.
Yes, there is way to remove or better to say exclude the particular files from being analysed by sonarqube.
You can use the sonar.exclusionswhich is a sonar analysis parameter, using this parameter you can exclude files or folders.
Here is the article from sonarqube on this https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/
Our Build fails due to such error:
The folder 'F:\TFS_Agents\Default_work\58\s\Sources\DotNet\foo\OnlineHelp\Syntax' does not exist...
I checked the original folder OnlineHelp, and there is no folder named Syntax inside. Instead there is an auto-generated file named
Syntax,_functions,_currencies_and_units.html
So i suggested to exclude the whole OnlineHelp folder like this:
exclude filter
But still get the same error. Did i do any mistakes with the filter?
The SonarQube Scanner for MSBuild has a known limitation with files containing commas, see SONARMSBRU-199 .
There's anyhow little value in analysing generated code (quality feedback not actionable by end-user), you're better off excluding projects made of generated code.
I am trying to run the kwinject command. The problem is that one of my Makefiles compiles a directory that I do not want to scan, so, is there a way to exclude these files?
I have tried with kwinject --ignore-files {directory-where-makefile-points-at/*} but it is not working.
Do you guys know if is that possible?
Yes it is possible.
According to kwinject --help (version 12.0.0.613), the option you should use is defined as:
-I, --ignore-files PATTERN[,PATTERN...]
Thus, you should just write a comma-separated list without any brackets. For example: --ignore-files somefile.c,*/googletest/* has been working for me when I want to ignore somefile.c and all googletest directories in my workspace.
Macoux Answer worth a try. This should help you achieve your goal.
i would recommend not to ignore the directory from analysis but ignore the results from the report. Here is the procedure to do that, https://developer.klocwork.com/resources/blog/analyze-3rd-party-code-exclude-it-results
if you ignore the directory from analysis then there are high chances that you may end up in missing dependent data flow issues.
Additionally, why do you want to ignore the directory?
if it is because of build time, you can try --incremental option with kwbuildproject. This can perform incremental/delta analysis for you.
If it is because of 3rd party code what you dont want to see as part of report, try this https://developer.klocwork.com/resources/blog/analyze-3rd-party-code-exclude-it-results
Add a module to the klocwork project that contains the code you want to suppress, and it will be suppressed.
Inside the publish profile (pubxml) created by VS you can add an exclude tag like the following:
<ExcludeFoldersFromDeployment>Themes;Core;Media</ExcludeFoldersFromDeployment>
Obviously this excludes these folders from being published. I would like to use a wildcard if possible to exclude folders that start with certain text. So Imagine I have a Modules folder that contains dozens of folders some starting test. I want to exclude these folders from being published. I was expecting to use a syntax like:
<ExcludeFoldersFromDeployment>Themes;Core;Media;Modules\Test*</ExcludeFoldersFromDeployment>
but by the fact I'm asking this question you know it doesn't work. Does anyone have any ideas?
Cheers
You can use MS Build wildcards to specify what to exclude.
If something like this doesn't work:
<ExcludeFoldersFromDeployment>Themes;Core;Media;Modules\Test\**</ExcludeFoldersFromDeployment>
Then find a way to exlude all the files... maybe like so:
<ExcludeFilesFromDeployment>Modules\Test\**\*.*</ExcludeFilesFromDeployment>
EDIT:
Here's a link that may help: "MSBuild Items", https://msdn.microsoft.com/en-us/library/ms171453.aspx#BKMK_Wildcards
I have Compile Views turned on and have just changed a big portion of my project so that a few of the views are not relevant at the moment.
I right clicked on them and chose Exclude from project.
However, these files are still be checked at compile time and come up in errors (as their ViewModel/model no longer exists).
The model/ViewModel themselves are excluded from the project and are not checked, but, these files will one day be included and I do not want to delete them.
So far, the only solution I have found is to highlight the entire content of the views and comment them out.
Whilst my solution does work, is this a bug or am I doing something wrong... or even, is there a better work around?
If the files are excluded from the project then they shouldn't be compiled.
What you might have is that the object files are still the output directory and it's these that are generating the errors.
You could either clean the project before excluding the files or simply delete the bin and obj directories to remove all the old output.