code-analysis

Accessing an implemented abstract property in the constructor causes CA2214: Do not call overridable methods in constructors

*爱你&永不变心* 提交于 2020-01-13 08:17:24
问题 public abstract class MyBase { public abstract bool MyProperty { get; protected set; } } public class MyClass : MyBase { public MyClass() { this.MyProperty = true; } public override bool MyProperty { get; protected set; } } The constructor MyClass() causes CA2214: Do not call overridable methods in constructors. This normally only shows if one calls a virtual method defined in the same class as the constructor. e.g. Accessing MyProperty inside MyBase 's constructor. Here I am calling a non

Tell pydev to exclude an entire package from analysis?

眉间皱痕 提交于 2020-01-13 04:37:07
问题 Today I'm on a mission to remove little red X's from my django project in pydev. Mostly, this involves fixing import problems with pydev. I'm using South for database migrations. South (if you don't know) generates python modules, and pydev doesn't like them. I don't want to edit the south code since it's generated. Is there a way to instruct pydev to exclude certain packages from analysis? Something like #@UndefinedVariable , except for the entire module? Ideally I'd like to ignore packages

Run Roslyn Code Analyzers on Build Server

邮差的信 提交于 2020-01-12 18:34:33
问题 I'm trying to create custom static analysis rules against my code base such that compiler errors will be generated if a developer fails to follow my companies coding convention. It seems with Visual Studio 2015, Roslyn Code Analyzers are the way to accomplish this. The MSDN articles I've read indicate Code Analyzers are packaged up as NuGet or VSIX packages. That's great for adding red squiggles in Visual Studio, but I want to make sure the compiler errors are also generated on my Jenkins

How to get an XML report out of MSBuild Code Analysis

依然范特西╮ 提交于 2020-01-12 08:02:13
问题 Running MSBuild with /p:RunCodeAnalysis=true on 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? 回答1: The XML report is generated by default. The file name is MyAssembly.dll.CodeAnalysisLog.xml or MyApplication.exe.CodeAnalysisLog.xml , you should be able to find it in the output folder for you project. To change name of the XML

The CA2104 warning: Is there any way to mark a class as `Immutable` to suppress it?

*爱你&永不变心* 提交于 2020-01-11 08:05:20
问题 Consider the following code, which provokes CA2104: Do not declare read only mutable reference types. public class Test { // This provokes CA2104: "Do not declare read only mutable reference types". protected readonly ImmutableClass ImmutableMember; } public class ImmutableClass { } Does anyone know of a way to mark a class as immutable in a way that would suppress warning CA2104? I tried decorating MutableClass with [ImmutableObject(true)] with no hope of success (since that attribute is

Detect Recursive calls in C# code

為{幸葍}努か 提交于 2020-01-09 12:51:32
问题 I want to find all recursive calls in my code. If I open file in Visual Studio, I get "Recursive call" icon on left side of Editor. I want to inspect whole solution for such calls. I used Resharper Command Line tools and VS's add-in Resharper - Code Inspection with no luck, this rule is not applied in their ruleset. Is there any way that i could inspect whole solution - i really don't want to open each file and check for that blue-ish "Recursive call" icon :) Edit: I am interested in single

Why does Cppcheck not find this obvious array out-of-bounds error?

人盡茶涼 提交于 2020-01-03 09:03:37
问题 I installed the Cppcheck tool for static code analysis of my C++ project and got the feeling that it performs poorly. For example, can anyone tell me why Cppcheck is unable to find an array out-of-bounds error in the following code? void f(int c) { char *p = new char[10]; p[c] = 42; } void g() { f(100); } There's an online demo where this code can be conveniently checked using Cppcheck. All it comes up with is a memory leak at line 4, no signs of a potential buffer overflow. 回答1: Because it

Misra standard for embedded software

情到浓时终转凉″ 提交于 2020-01-03 07:19:09
问题 I have a requirement to make a large amount of code MISRA compliant. First question: Can somebody to give an estimation for passing well written code for embedded system based on experience. I understand that "well written" is poorly defined and vague so i ask for raw estimation. Second question: Any recommendation for tool that can be customizable (i.e allowing suppress specific warnings) and used in automatic build environment (i.e command line interface) Any other useful suggestions that

Specifying code analysis setting in TFS 2010 build

心已入冬 提交于 2020-01-03 04:09:27
问题 In the build definition of TFS 2010, when "Perform Code Analysis" set to "Always" how can I specify a custom code analysis rules file? The build flavour is "Release". I prefer not to set "AsConfigured" for "Perform Code Analysis" so that the settings are picked from proj file. Thanks. 回答1: You should be able to use the "MSBuild Arguments" entry in your build process parameters configuration to provide a /property command line entry that will be passed to MSBuild, thereby allowing override of

How to Check References of Annotated Methods

 ̄綄美尐妖づ 提交于 2020-01-03 03:49:05
问题 I'm trying to find a way to check my classes for references of methods with a particular annotation (think "Deprecated"). As far as i see it, analysing byte code won't work because it doesn't contain any annotations. Using APT doesn't really help because i need the references to the methods, not the annotated methods themselves. So, what options do i have? The best i can come up with is compiling a list of the annotated methods followed by a full code analysis, checking every method call