Software Quality

For large teams working in same code base, enforcing coding rules and conventions can be difficult. Code analysis tools are very helpful to ensure necessary coding conventions are being followed naturally.

The idea behind code analysis is to examine a piece of code against recognized set of rules. These rules include spelling checks, possible null references exceptions, matching of parameter names in method overriding, forbid catching general exceptions, so on and so forth.

Running code Analysis
– To run code analysis on demand, select Analyze > Run Code Analysis option.
– Depending upon settings in your ruleset, Error or Warnings will be reported in Code Analysis window.
– Alternatively, you can also enable code analysis upon Build. Right click on Project > Properties and go to Build tab. Select checkbox, Enable code analysis on Build.
– This option will report code analysis errors every time the project is built.

Note that, enabling code analysis can result in tons of errors/ warnings in your code. This does not necessarily mean all are potential bugs. Again, the examination is performed against the set of rules selected in ruleset. There might be a case when you would like to customize the rule set or create a new one.

Creating your own Ruleset
– Right click on project and add new item,
– From project templates select Code analysis ruleset
– Apply basic set of rules such as Microsoft Minimum Recommended settings.
– Check / Uncheck rules as per your requirement.
– Chose whether you want to report anomaly in the code as Error or Warning against each rule.
– Save the change.
– You can now apply your customized ruleset to the project as described above.

Code analysis is a good place to report spell checking errors. It is generally a good idea to enforce all spell checking rules during code analysis. However, you might have certain domain specific nomenclatures in the code that are not in the dictionary. It would be annoying to see code analysis fail for this reason. The workaround this is to maintain a custom dictionary of words that are accepted as valid during code analysis.

– Right click on your project and select Add Existing Item.
– Navigate to the custom dictionary xml on your disk and Add as a link.
– Right click on the file in Solution Explorer and select Properties.
– Select type as Code analysis dictionary
– From now on, the words described in Custom Dictionary will be considered as valid words during spell check.