How important is code quality to your team? It should be at the top of the list, not only to make your customers happy but make your team happier when bugs arise and when features need to be added. Putting quality in your code in the future is a lot more expensive than doing it when the code is first written. How does your open-source solution compare to some of the most popular GitHub/ NuGet packages? Do you analyze repositories before using them or just adding them via NuGet? If not, you need to keep reading.
ChoETL |
Code Quality Rating |
8.08 |
Cinchoo ETL is a .NET library for reading and writing CSV, Fixed Length, XML, and JSON files. It supports reading and writing of custom POCO class objects. I am currently using ChoETL in a project where via ASP.NET, we allow customers to download and upload CSV files. Here are the results of my code analysis. I would like to note that I could not calculate unit test coverage since 157 tests are broken. The code quality rating shows there is a code violation every 8.08 lines of code.
|
Errors
|
Warnings
|
Information
|
Unit Test Coverage
|
|
0
|
65,074
|
14,568
|
UNKNOWN – Broken
|
|
Maintainability Index
|
Cyclomatic Complexity
|
Depth of Inheritance
|
Class Coupling
|
|
88
|
147,107
|
2,229
|
70,464
|
|
Lines of Source Code
|
Lines of Executable Code
|
Lines of Cloned Code
|
Code Commenting
|
|
643,902
|
231,796
|
22,190
|
Grade of F
|
Coding Standard Issues
Here are just some examples of what needs to be fixed from the near 80K violations.
Using string.Empty
Here is a common issue I see in most code bases I analyze,
- ele.Add(new XAttribute(kvp.Key.Replace("@", ""), value));
The issue here is that they are using ""which can affect performance. Instead usestring.Empty. Here is how it should look,
- ele.Add(new XAttribute(kvp.Key.Replace("@", string.Empty), value));
Variable Naming
Here is an issue of local variable names.
- ChoFallbackValueAttributeFallbackValueAttribute = (from a in mi.Attributes.AsTypedEnumerable<Attribute>() where typeof(ChoFallbackValueAttribute).IsAssignableFrom(a.GetType())select a).FirstOrDefault() as ChoFallbackValueAttribute;
The issue is that local variable names should start with lower-case letters. Here is how I would fix it.
- var fallbackValueAttribute = (from a in mi.Attributes.AsTypedEnumerable<Attribute>() where typeof(ChoFallbackValueAttribute).IsAssignableFrom(a.GetType()) select a).FirstOrDefault() as ChoFallbackValueAttribute;
Missing Accessibility Modifiers
All properties, methods, fields, events, etc. should have proper accessibility modifiers. Here is an example of the violation.
- ChoYamlRecordFieldConfigurationfieldConfig = null;
It should be coded like this (includes proper naming).
- private ChoYamlRecordFieldConfiguration _fieldConfig;
Braces Placement
Another common issue I see in code is the improper use of braces, usually not using them at all like in this example.
- if (methodInfo != null)
- return methodInfo.Invoke(target, args);
- else
- throw new ApplicationException(String.Format("Can't find {0} method in {1} type.", name, target.GetType().FullName));

David MccarterPosted Jul 30, 2022, 4:32 PM
In the past I have used CodeIt.Right from Submain.com. Now I use the analyzers built into Visual Studio 2022 using my .editConfig file: https://gist.github.com/RealDotNetDave/dbae4d97358ba4515dd52e5b8ca87671
Cicero FoscariniPosted Jul 26, 2022, 10:15 PM
Hi! Thank you for the article. I have one question though, Which tools did you use for this code analysis? Thank you very much