code-analysis

C++ code analysis tools

こ雲淡風輕ζ 提交于 2019-12-31 22:35:12
问题 I'm currently in the process of learning C++, and because I'm still learning, I keep making mistakes. With a language as permissive as C++, it often takes a long time to figure out exactly what's wrong -- because the compiler lets me get away with a lot. I realize that this flexibility is one of C++'s major strengths, but it makes it difficult to learn the basic language. Is there some tool I can use to analyze my code and make suggestions based on best practices or just sensible coding?

Viewing Code Coverage Results outside of Visual studio

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-31 09:16:16
问题 I've got some unit tests, and got some code coverage data. Now, I'd like to be able to view that code coverage data outside of visual studio, say in a web browser. But, when I export the code coverage to an xml file, I can't do anything with it. Are there readers out there for this? Do I have to write an xml parser and then display it how I want it (seems like a waste since visual studio already does this.) Seems kinda silly to have to take a screenshot of my code coverage results as my

Running time/time complexity for while loop with square root

半腔热情 提交于 2019-12-31 03:39:04
问题 This question looks relatively simple, but I can't seem to find the running time in terms of n. Here is the problem: j = n; while(j >= 2) { j = j^(1/2) } I don't really need the total running time, I just need to know how to calculate the amount of times the second and third lines are hit (they should be the same). I'd like to know if there is some sort of formula for finding this, as well. I can see that the above is the equivalent of: for(j = n; n >= 2; j = j^(1/2) Please note that the type

Java for each loop being flagged as UR anomaly by PMD

安稳与你 提交于 2019-12-30 16:23:21
问题 I would like to confirm if this is a bug on PMD? How do I file a ticket if it is. public static void main(final String[] args) { for (final String string : args) { string.getBytes(); //UR Anomaly } for (int i = 0; i < args.length; i++) { args[i].getBytes(); } } Lines 1-3 are being flagged as UR anomaly, while rewriting it to iterate with a local variable is fine. Would like to eliminate as much PMD violations, but it is inconvenient to have to resort to old loop construct as a workaround.

Java for each loop being flagged as UR anomaly by PMD

牧云@^-^@ 提交于 2019-12-30 16:23:08
问题 I would like to confirm if this is a bug on PMD? How do I file a ticket if it is. public static void main(final String[] args) { for (final String string : args) { string.getBytes(); //UR Anomaly } for (int i = 0; i < args.length; i++) { args[i].getBytes(); } } Lines 1-3 are being flagged as UR anomaly, while rewriting it to iterate with a local variable is fine. Would like to eliminate as much PMD violations, but it is inconvenient to have to resort to old loop construct as a workaround.

Get FxCop to suppress warnings for a whole type?

白昼怎懂夜的黑 提交于 2019-12-30 08:17:23
问题 How can I suppress FxCop warnings for a whole type? namespace ConsoleApplication1 { public static class Serializer<T> { public static string Serialize(T obj) { return string.Empty; } public static T Deserialize(string str) { return default(T); } } I tried this, but it is not working for me: [assembly: SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Scope = "Type", Target = "ConsoleApplication1.Serializer'1")] 回答1: Unfortunately, this will not work. FxCop

CA1500 vs. SA1309 - Which one wins?

百般思念 提交于 2019-12-30 03:44:04
问题 I'll prefix by saying that I understand that both Code Analysis and StyleCop are meant as guidelines, and many people chose to ignore these anyway. But having said that, I'd like to see what the general consensus is with regard to these two rules. Rule CA1500 says don't make parameter names and private field names the same. Rule SA1309, on the other hand, says don't prefix members with underscore or "m_". This leaves us with little options for distinguishing private backing fields from their

The “Why” behind PMD's rules

六眼飞鱼酱① 提交于 2019-12-30 02:43:06
问题 Is there a good resource which describes the "why" behind PMD rule sets? PMD's site has the "what" - what each rule does - but it doesn't describe why PMD has that rule and why ignoring that rule can get you in trouble in the real world. In particular, I'm interested in knowing why PMD has the AvoidInstantiatingObjectsInLoops and OnlyOneReturn rules (the first seems necessary if you need to create a new object corresponding to each object in a collection, the second seems like it is a

How to fix a CA2000 IDisposable C# compiler warning, when using a global cache

此生再无相见时 提交于 2019-12-29 08:40:06
问题 CA2000 is a warning regarding the IDisposable interface: CA2000 : Microsoft.Reliability : In method 'ImportProcessor.GetContext(string)', call System.IDisposable.Dispose on object 'c' before all references to it are out of scope. My method is used to store a cache of context like so: public class RegionContext : IDisposable { /* Implement Dispose() here */ } private Dictionary<string, RegionContext> contextCache = new ..... (); public RegionContext GetContext(string regionCode) {

Custom threshold for CA1502

纵饮孤独 提交于 2019-12-29 07:11:53
问题 Is there any way to change the thresholds for CodeAnalysis rules? In particular, we would like our Build to fail when a method has a code complexity of more than 20. Unfortunately, rule CA1502 has a threshold of 25: The rule reports a violation when the cyclomatic complexity is more than 25. Can we somehow change this? 回答1: Yes, this is possible. Unfortunately, the only way to provide custom rule settings for a configurable rule is via a .fxcop project file, which doesn't integrate terribly