Questions tagged [code-analysis]

Code Analysis is the process of analyzing the code of the application to discover, review, validate or verify certain properties of the application. This is useful during the process of development and for testing the application before it is put in production mode, especially for checking the security related aspects.

Filter by
Sorted by
Tagged with
1 vote
0 answers
34 views

error CS1056: Unexpected character '$' during code analysis [duplicate]

When I am running the build in C# code analysis from the command line with msbuild on some code I get: (CoreCompile target) -> SLIP.cs(10,51): error CS1056: Unexpected character '$' [....Libraries....
Gerhard's user avatar
  • 6,860
2 votes
1 answer
53 views

Generate a 'readonly record struct' using Roslyn

I can't generate a readonly record struct using Roslyn. My code: using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; var tree = SyntaxFactory.CompilationUnit() .AddMembers( ...
ASi's user avatar
  • 21
-1 votes
0 answers
14 views

How to get all the assembly names of a C# solution while analyzing one of the assembly?

I am creating a Code Analyzer assembly which can have dependency rules to govern other C# solution and assemblies. To create such rules, I have a class that inherits DiagnosticAnalyzer which contains ...
Swati Dayal's user avatar
-2 votes
1 answer
43 views

How can I see debug info about the VS Code Cpptools extension's IntelliSense and Code Analysis?

I've setup VS Code with the ms-vscode.cpptools extension to open my C++ project and I see the IntelliSense and Code Analysis tools running. But I never see anything in my code to suggest they're ...
parsley72's user avatar
  • 8,479
0 votes
0 answers
34 views

dotnet Code Analysis ignoring certain entries in .editorconfig file

In a test project I am trying to ignore certain Code Analysis warnings, but I am struggling to understand what I am missing. I have a simple dotnet6.0 console app with the following structure. Project ...
William James's user avatar
0 votes
2 answers
287 views

How can you distinguish between a standard library call, a third-party library call, and an API call from the repository?

I am working on a project where I have to determine whether a particular call or import is: From the standard library of the language (Python) I'm using. (I am already considering to use sys....
Exploring's user avatar
  • 2,525
0 votes
0 answers
19 views

Clarification needed: core differences between two receipt selection code snippets

I've been going through some exam questions and stumbled upon two different implementations for a receipt selection task. I'm trying to understand the key differences between these two code snippets. ...
Bishop_1's user avatar
  • 101
1 vote
0 answers
49 views

Async method's return decorated with "NotNullIfNotNull" still returns variable that may be null

According to this documentation I can decorate a method with NotNullIfNotNull attribute. However the following code does not work: using System.Diagnostics.CodeAnalysis; var a = await Test("abc&...
Luke Vo's user avatar
  • 18k
2 votes
1 answer
96 views

Why is Visual Studio saying this cast from System.Int32 to System.Byte is redundant?

I'm trying to retrieve a type of Byte for a unit test, yet when I do a simple cast as shown below, I get the code analysis info in VS that the cast is redundant. Why? Clearly the cast is needed to ...
rory.ap's user avatar
  • 34.1k
0 votes
1 answer
27 views

Generic not-null validator for CA1062 in .NET 6

I have a generic method that ensures an IEnumerable is not null or empty. public static void IsNotNullOrEmpty<T>(IEnumerable<T> enumerable) { if (enumerable == null || !enumerable.Any()...
user246392's user avatar
  • 2,433
0 votes
0 answers
25 views

How do code analysis, AST generation and SARIF report work in MSBuild?

Recently, I became curios about mechanism of code analysis in MSBuild. I searched a lot, specially in MSDN but could not get a firm grasp on how exactly this process is done. I want to know what ...
noone's user avatar
  • 1
0 votes
0 answers
25 views

Making multiple microservices in single project in sonarqube

Sonar showing multiple projects Folder structure of microservices in system Hi Everyone! Recently I started learning microservices architecture. I developed it with spring boot maven but when it comes ...
Shubham Patel's user avatar
0 votes
1 answer
161 views

GitLab Code Quality job throws 'dotnet not found'

I'm trying to perform Code Quality test using GitLab CQ tool applying to my .NET 7 project. I'm a quite new it this, so, firstly I added default trigger to my .gitlab-ci.yml for getting this job ...
anatol's user avatar
  • 1,688
0 votes
1 answer
54 views

Visual Studio: Prevent CodeAnalysis from running on cs files included via nuget

I'm referencing the BlingFireNuget package in my csproj. It adds a bunch of files to my project, including a couple cs files, like BlingFireUtils.cs. These are adding hundreds of code analysis ...
UnionP's user avatar
  • 1,301
0 votes
2 answers
47 views

MIPS - and instruction of zero - Register

I've got the instruction to understand a MIPS - code. One line of it is the following one: and $t6, $zero, $zero Which purpose does it have ? There is the and - instruction of two zero - constants. So ...
Coder's user avatar
  • 11
-3 votes
1 answer
592 views

Sonarqube Refactor the below code to reduce its cognitive complexity. Complexity is 33, we should reduce to 15 [duplicate]

As the below code is having nested if conditions, sonarcube complexity is increasing. Need to reduce the cognitive complexity from 33 to 15 allowed. I have tried placing only one try block and one ...
A R's user avatar
  • 1
2 votes
0 answers
59 views

Visual Studio 2019, Code Analysis [Warning C6386: Buffer overrun], C

Warning C6386, as described by Microsoft, "...indicates that the writable extent of the specified buffer might be smaller than the index used to write to it. This defect can cause buffer overrun&...
yuno's user avatar
  • 31
0 votes
1 answer
187 views

ReSharper stopped tracking Visual Studio code analysis after VS was updated to 17.5

I have some C# solutions which use StyleCop analyser and Ruleset file with some custom rules. Then I have updated Visual Studio from 17.4 to 17.5.1 and ReSharper stopped tracking violations of rules. ...
Lgeprorok's user avatar
0 votes
0 answers
96 views

How to determine Java Version per Android OS version

I was looking (hoping) for a simple mapping from each android OS version to a version of Java. More specifically. I am focusing on the Android OS side (not the application side), the ART: what version ...
triom's user avatar
  • 1
0 votes
1 answer
50 views

Warning when nullable int is involved in an arithmetic operation

The following code doesn't produce any warning or error: int? test1 = null; var test2 = test1 + 123; test1++; var test3 = test1; test2 and test3 end up being null. I find this rather unintuitive and ...
Jez's user avatar
  • 28k
1 vote
1 answer
861 views

difference between overall code and new code in sonarqube

I am new to sonarqube and I don't understand how it works. I have downloaded the latest sonarqube image, I run a simple container and the application starts, everything ok. Community Edition Version 9....
Manu's user avatar
  • 81
0 votes
0 answers
51 views

Can you efficiently analyse the type of method parameters in Python

I am making a PyCharm plugin that will generate code examples based on a Python class. The user will be able to select a class and the plugin will generate code examples that utilise the attributes ...
Svetoslav Tsenov's user avatar
0 votes
0 answers
18 views

Starting in pydev 10.1.1 class-methods of types get error 'should have self as first parameter'

I have a python class that is a type. So the super is not object but type. Befoer pydev version 10.1.1 the first parameter had to be 'cls'. Now errors are reporting that it should be 'self'. Pylint ...
Mathijs's user avatar
  • 23
0 votes
0 answers
33 views

Why sonarqube doesnot show code coverage percentage of a specific file eventhough it's unit test classes are written.?

I am using the latest SonarQube Enterprise Version. I have a python file named project/projectName/script/fileName.py. This file has many methods written. Also, I have the unit test written for the ...
Geo Joseph's user avatar
3 votes
0 answers
125 views

How to resolve Security code scan SCS0016 in API controller

We have implemented weather API controller to update weather data and inherited ControllerBase in API controller with APIController action filter like below and enabled security code scan. using ...
Amrutha's user avatar
  • 31
0 votes
0 answers
45 views

MsBuild: Fail the Build when referenced Projects outside of the solution have Code Analaysis warnings

In one of our .net Projects we have a Build/Publish discrepancy. The Build succeeds but the publish fails. The reason for that: We have a lot of shared Projects which are just dependencies but are not ...
Dres Baumann's user avatar
0 votes
1 answer
94 views

How can I select the entire import statements using regular expressions?

I'm writing a static code analysis tool in Python. Here's a sample of a code that needs to be analyzed: import { component$, useClientEffect$, } from '@builder.io/qwik' import Swiper from '...
Mohammad Miras's user avatar
1 vote
1 answer
187 views

Dynamically compile code from .Net Standard 2.0

I'm developing a .Net Standard 2.0 library offering dynamic compilation but there are always missing references. A consumer using .Net Core, calls an Api with his source code as text, implementing a ...
Adam Paquette's user avatar
0 votes
1 answer
156 views

Some of ReSharper settings not visible

I have downloaded ReSharper to Visual Studio 2022. I need to run code analysis to check if all varables are named correctly in camelCase. Also I want to implement custom rule that no double or float ...
vytaute's user avatar
  • 1,292
2 votes
1 answer
73 views

CAExcludePath is being ignored during Visual Studio code analysis

I have a Visual Studio C++ application project MyApp and a Visual Studio C++ library project Lib. The MyApp project has Lib project added as a project reference, as well as $(ProjectDir)..\Lib; added ...
DLT's user avatar
  • 139
0 votes
0 answers
28 views

How to get a usable report from dotnet code analysis

I have a .NEt 7 project and I want to get the Code Analysis results as XML (or other) to stuff them into Gitlab. But how to do that? dotnet build MySolution.sln Has no obvious paramaters and the ...
Christian Sauer's user avatar
2 votes
1 answer
414 views

SuppressMessage compiler warning CS1591 for generated code (xsd.exe)

I'm using the tool xsd.exe in several projects to generate classes for my data model. When turning on documentation file generation in my csproj the compiler starts to show lots of warnings of type: ...
walkslowly's user avatar
0 votes
0 answers
93 views

Make block statements a compile error in C# via Rider or Visual Studio

We found the following bug in our code as a result of a git merge. public static void error(ref string test) { var diff = 123 - new Random().Next(); if (diff == 0) test = $"diff ==...
rollsch's user avatar
  • 2,534
0 votes
1 answer
51 views

C6386 warning passing WCHAR param to StringCchCopy - how to resolve?

This code is giving me the following code analysis warning: C6386 Buffer overrun while writing to m_NID.szTip. bool CCenterCursorOnScreenDlg::SetTrayIconTipText() { if (StringCchCopy(m_NID.szTip,...
Andrew Truckle's user avatar
0 votes
0 answers
33 views

Are there any tools which has APIs for code review?

I need a tool which uses API for code review. In here the API should code review a File not a repository and it also should support multi languages. Most of the tools like CodeScene review an entire ...
Agil Yathushan's user avatar
0 votes
2 answers
423 views

How to configure Coverity for IAR ARM (iccarm)

I configured Coverity with The build is successful, but I receive Recoverable errors in the system headers (see build-log.txt) For me it’s not clear why these errors occur (build is successful) and ...
ge45mue's user avatar
  • 677
2 votes
1 answer
32 views

Suppressing FXCOP error for vb.net Method

I want to suppress FXCOP error(CA1811) for specific vb.net function. Like <SuppressMessage()> in c#, do we alternative of this in VB.net? I am new to vb.net.
Karthik Karnam's user avatar
0 votes
0 answers
88 views

Unity3D / GlobalSuppressions.cs is excluded from the project solution as soon as Visual Studio is closed + an awkward fix

Due to an annoyingly high number of "new() can be simplified" messages (sorry, but I'd like to see what's new) I decided to use a global suppression file to keep my error list clean. I ...
ge.go's user avatar
  • 65
0 votes
1 answer
49 views

Protect RunCustomQuery(string SqlQuery, List<IDbDataParameter> SqlParameters) from injection

We use a class, DBLinker, to connect to various databases and run queries. It relies on its core method, RunCustomQuery(string p_strSqlQuery, List<IDbDataParameter> p_lisParameters) to return ...
Jean-David Lanz's user avatar
1 vote
0 answers
479 views

NuGet version conflict issue on CodeAnalysis.Common when trying to use a Source Generator

I have a .NET 6 MVC app, and a class library. In the class library, I wanted to use a source generator. I added the NuGet package Microsoft.CodeAnalysis.Analyzers and Microsoft.CodeAnalysis.CSharp....
NibblyPig's user avatar
  • 51.2k
1 vote
0 answers
61 views

How to extract props of a react component using static code analyzer?

I'm creating a code analyzer for react. For example, if we have Cart.js: const Cart = ({ products, discount, shipment, payment }) => { return <div> { ...
Big boy's user avatar
  • 1,133
3 votes
2 answers
743 views

The difference between new VS code analysis options "Show compiler errors and warnings for:" and "Run background code analysis for:"

I have just installed the latest update 17.3 for Visual Studio 2022 and noticed that code analysis settings changed. Now there are two options for code analysis scope: "Show compiler errors and ...
SENya's user avatar
  • 1,053
2 votes
2 answers
498 views

VSC run code analysis __float128 is not supported on this target

Every time I run code analysis in C++ project I receive __float128 is not supported on this target Is any possibility to turn off those kind of clang errors? I have been searching answer for hours, ...
www987's user avatar
  • 31
6 votes
2 answers
1k views

How to exclude node_modules from WebStorm code analysis (named 'Problems' on the bottom-left corner)

I am relying on this extensively on my workflow, but for some reasons this feature is now warning me of all the problems coming from node_modules, which obviously I'm not interested in. How can I ...
A Mehmeto's user avatar
  • 1,624
0 votes
2 answers
183 views

Mutable members should not be stored on ArrayList - Sonar vulnerability

I have sonar "Mutable members should not be stored or returned directly" issue in my java class. I have fixed it by below code but still sonar is giving me the same error public class ...
Mario R's user avatar
  • 151
1 vote
1 answer
789 views

Roslyn - how to get property names and types in a class using Roslyn?

I created a VSIX project to read properties of a class, trying to get their names and varriable types as doing sth like below using Roslyn; string filePath = Path.GetDirectoryName(dte.Solution....
Ali CAKIL's user avatar
  • 383
1 vote
1 answer
320 views

csharp_prefer_simple_using_statement / IDE0063 Not Appearing When Expected

I am not seeing the code analysis rule csharp_prefer_simple_using_statement aka "Use simple 'using' statement (IDE0063)" produce output when expected. I added some dummy code to a method in ...
pbristow's user avatar
  • 1,997
0 votes
1 answer
142 views

Taint analysis does not have flow path for non constant field of a class as its source

I have this simple Test class, where I'm trying to mimic a path problem. with Message1 as source and Console.WriteLine(Message1) as sink. class Test { private const string Message1 = &...
Manu Nair's user avatar
0 votes
1 answer
3k views

How to disable code analysis in Visual Studio 2022 Preview?

I read https://learn.microsoft.com/visualstudio/code-quality/analyzers-faq#code-analysis-solution-property-page but in my Visual Studio 2022 Preview, I cannot use it. How to disable Code Analysis ...
Vy Do's user avatar
  • 47.1k
2 votes
1 answer
72 views

is there a tool or any quick way to extract db tables automatically from my php codes?

I recently started to re-engineer a PHP-mysql project which was created about 7 years ago. I have only php and html codes and no mysql database or any document which shows the database structures. Is ...
MAli Fahimi's user avatar

1
2 3 4 5
38