To ensure a proper maintenance of coding it is essential to write code in a “clean” and neat way. Throughout years, several global SW Factories have adopted a set of rules for coding, addressing clearness and legibility and making coding itself accessible to those developers who will have to maintain it throughout time. The DotNet environment is no exception to the rule. CODEPLEX, the Open Source Community for DotNet programmers and developers, has published a valuable product, namely StyleCop, for the analysis of source code and the highlight of any style errors, as alerts and warning messages, suggesting programmers to solve the mistake before making their own work available and visible to other members of the Team. StyleCop is an easy and effective product; in fact, no doubt a programme written according to suggested style rules is far much easy to read and effective. StyleCop, however, has a great limit: the programme only notifies violations to style rules. Any correction action has to be taken by programmers themselves. What is frustrating is that violations often consist in trivialities, which could automatically be solved. This is where the idea to implement a product capable of automatically perform rule fixing suggested by StyleCop comes from. To maximize product fruition, it has been designed as a Visual Studio extension, in order to have access to a set of strong mechanisms the development environment offers.
SetupProduct setup consists in an easy procedure, only taking a few seconds.
Preparation to use AlmaStyleFixAlmaStyleFix optionsOnce AlmaStyleFix has been setup, VisualStudio TOOLS menu will display AlmaStyleFix Settings options. Within the menu, a configuration window will be displayed (see below):
The various options are described below:
It is advised to initially set up developer name and company, since this information will be uploaded at the start of any code file, in the copyright section, by AlmaStyleFix itself. Style rule customizationIt is possible to choose the set of style rules to use, via means of the option window panel provided by StyleCop. To access it, just right button click on the project and select “StyleCop Settings” from the drop-down menu, as shown in the picture below:
By doing this, rules to use can be selected/deselected. AlmaStyleFix will then automatically use the new pool of rules. To save time, a pool of rules compatible with Italian comment has been attached to AlmaStyleFix. In order to install it, it is required to overwrite the “Settings.Stylecop” file of the “C:\Program Files (x86)\StyleCop 4.7” folder with the attached file. Otherwise, each user can select the list of style rules to enable, project per project, by setting them from StyleCop Settings menu. It is always advised to link the setting file of own projects with the original one, that is: the one included in the set up folder, to make sure any modification is sent to any and all projects. In order to do so, it is requested to selected the option “Merge with the following settings File” and then select the “C:\Program Files (x86)\StyleCop 4.7\ Settings.Stylecop”, within the StyleCop options. Right button of the mouse on the project -> StyleCopSettings-> Select the window “settings file” ->”merge with…”, as shown in the picture.
To access the program files folder, Visual Studio has to be run by an Administrator user (or with Admin rights).
Use of AlmaStyleFixBefore launching AlmaStyleFix, it is necessary to solve any and all compilation mistakes. Elsewhere, the programme will not be able to work and an error message will be displayed. AlmaStyleFix will exclusively analyze the current document, which has to be a C# code file. To launch the programme, just click on the right button of the mouse on any part of the document; then select AlmaStyleFix from the drop-down menu, as shown in the screenshot:
As shown in the screenshot below, the programme automatically corrects what can automatically be corrected, whereas it notifies violations to style rules by using the highlight tool (if enabled).
By pointing the highlighted line with the mouse cursor, a suggestion in tooltip box will display the text of violation, so that programmers can learn how to intervene in order to solve the problem In the example, a missing “summary” has been automatically generated, but it is necessary for programmers to manually intervene in order to insert some text. In case of problemsPrevious code can be restored anytime by using the combination of “CTRL + Z” keys. In case come StyleCop rules disable the recompile feature of code (indeed it may happen, but that cannot be blamed on me!), is it advised to disable the specific rules. To find out which rule is responsible for any issue, StyleCop can be executed (right button of the mouse on project-> Run StyleCop): the related warning message, within which the rule coding generating the violation alert is present, will be displayed. It is strongly advised to recompile code once the fixing has been performed, in order to avoid new issues.
|