FAQ Database Discussion Community


Disadvantages of using the `-Wextra` flag when compiling in GCC

c,gcc,code-analysis,compiler-warnings,compiler-flags
I know that one should always compile with both -Wall and -Wextra as they enable warnings and help us to understand our mistake, if any. I've read that the -Wextra compiler flag is not recommended to use because it is too verbose with a lot of false positives. I was...

How to exclude a directory from the code analysis?

sonarqube,code-analysis
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...

What is the runtime of the following code

algorithm,code-analysis
The code is as follows: Ans = 1; while( N > 0) { Ans = Ans*2; N = N/2; } I can not figure out how N = N/2 will effect the runtime. I tried to find a pattern by checking how many times the loop would run if N...

TFSBuild: Disabling Code-Analysis for one project

visual-studio-2012,tfs,tfs2012,tfsbuild,code-analysis
We have a large VS2012 solution (~250 projects) that is 90% C#. 2 of the 3 C++ projects use the 'v110' Platform Toolset. The third has to use the 'v110_xp' toolset for compatibility with a third party library. Our nightly TFS (2012) build is configured with 'Perform Code Analysis' set...

Exclude folder from Analyze > Run Inspection by Name

intellij-idea,code-analysis,intellij-idea-14,code-inspection
Is it possible to exclude a folder when I want to analyze the code in IntelliJ IDEA? Usage example: Analyze > Run Inspection by Name... > Missorted modifiers It founds a lot of results, but some of them are from folders that contain generated Java files. I want to exclude...

In Visual Studio 2013 how do I limit code analysis to my code and not to referenced assemblies?

visual-studio,visual-studio-2013,code-analysis,ilmerge
I have a solution in Visual Studio 2013 (c# code) that has a reference to a third-party assembly that I added with NuGet (ICSharpCode.SharpZipLib). When I run the "Code Analysis" on the solution I get lots of warnings coming from the third-party assembly. How do I tell VS that I...

Does a loop invariant need to be defined both before and after the loop?

algorithm,loops,code-analysis
I've been really confused so far about loop invariants and their specific properties. Do they need to be true both BEFORE and AFTER the loop? Or just at some point in the loop body itself? For example: int sum = 0; for (int = 0; i < 10; i++) {...

What does the following code analysis mean?

java,intellij-idea,code-analysis
I have an object instantiated like the following in only one place in my code(AggregateFunctions). private String selectColumns() { String query = "SELECT "; if (this.distinctResults) { query = query + "DISTINCT "; } SelectColumn selectColumn = new SelectColumn(this); if (!this.applyAggregation) { for (Object object : this.columns) { query =...

WPF code analyze : CA2202 Do not dispose objects multiple timesObject

c#,wpf,code-analysis
in my WPF application code i got the following Warnings: CA2202 Do not dispose objects multiple times Object 'fs' can be disposed more than once in method 'MainWindow.TestResults_Click(object, RoutedEventArgs)'. To avoid generating a System.ObjectDisposedException you should not call Dispose more than one time on an object. : Lines: 429 yesMonitor...

Is there a way to pass data (other than through the property bag) between an analyzer and a code fix provider in Roslyn?

c#,code-analysis,roslyn
with the new RC release, I was excited to see that there now was a property bag to allow raised diagnostics to have additional data, a major use case of which was, in my opinion, to be able to have data computed in the analyzer carried over into a code...

GetAnalyzerDiagnosticsAsync returns nothing if a DiagnosticAnalyzer has an empty Initialize

c#,code-analysis,roslyn
I am writing a method which gets all the Diagnostics for a Project for a set of DiagnosticAnalyzers: private static async Task<ImmutableArray<Diagnostic>> GetDiagnosticsAsync( Project project, ImmutableArray<DiagnosticAnalyzer> analyzers) { var compilation = await project.GetCompilationAsync(); var withAnalyzers = compilation.WithAnalyzers(analyzers); var diagnostics = await withAnalyzers.GetAnalyzerDiagnosticsAsync(); return diagnostics; } This works fine if all...

Correct way to check the type of an expression in Roslyn analyzer?

c#,.net,code-analysis,roslyn
I'm writing a code analyzer with Roslyn, and I need to check if an ExpressionSyntax is of type Task or Task<T>. So far I have this: private static bool IsTask(ExpressionSyntax expression, SyntaxNodeAnalysisContext context) { var type = context.SemanticModel.GetTypeInfo(expression).Type; if (type == null) return false; if (type.Equals(context.SemanticModel.Compilation.GetTypeByMetadataName("System.Threading.Tasks.Task"))) return true; if...

Should nDepend's output folder be added to source control?

visual-studio,code-analysis,ndepend
Background I am new to nDepend and wish to use it on a project that will be maintained with multiple developers in Subversion. I am quite keen on keeping historic nDepend analysis results and notice that nDepend does that quite well by default by placing such results in the folder...

Solution for CA2227 or better approach?

c#,visual-studio,code-analysis
I'm only using Code Analysis for cleaning, organizing and ensuring these changes are globally performed for all instances of a particular warning. I'm down to the final, and it's CA2227. CA2227 Collection properties should be read only Change '' to be read-only by removing the property setter. Note this is...

How to satisfy CA2202 (Do not dispose objects multiple times)

c#,code-analysis
This question may seem to you duplicate of CA2202, how to solve this case which has an accepted answer. But you may realize that accepted answer has 5 down votes based on poor quality. Also any other up voted answers are not actually solves the issue. Most of them...

Resolving parameter type in Roslyn

c#,code-analysis,roslyn
I'm using Roslyn to implement custom business rules. At the moment, I'm a bit stuck, I have to validate the type of a parameter when a method is being invoked. There are no issues validating that the method is being invoked or that is contains parameters. I have resolve an...

How to get an XML report out of MSBuild Code Analysis

c#,visual-studio,msbuild,code-analysis
Running MSBuild with /p:RunCodeAnalysis=trueon a C# project does generate the code analysis warnings on the build output, but what's the switch that lets me export these warnings (only the code analysis warnings not the entire build output) to an XML file?