StyleCop report (code style cleanup)

Bug #1388211 reported by Alan Horkan
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Pinta
Invalid
Undecided
Unassigned

Bug Description

I ran StyleCop -- a C# source code analysis program -- against Pinta and got a very long report, over 10,000 style warnings. (I'll attach the log but it is XML and not particularly readable, so I'll attempt to summarize some of the key points).

There are many spacing complaints, there seem to be several cases where Pinta uses more spaces than recommended but I'll ignore those. Also the same warnings get repeated far too many times to be readable, so I'll try to summarize.

SA1027 : CSharp.Spacing : Tabs are not allowed. Use spaces instead. -
AboutDialog.cs
AboutDialogAction.cs
AboutPintaTabPage.cs
AutoHideBox.cs
CloseAllDocumentsAction.cs
CloseDocumentAction.cs
DockContainer.cs
... and lots, lots more other Dialogs and Actions files.

There are lots of warnings about being stricter with the placement of braces:
SA1503 : CSharp.Layout : The body of the if statement must be wrapped in opening and closing curly brackets. - D:\devel\Pinta\Pinta\DockLibrary\DockItem.cs:436
SA1500 : CSharp.Layout : If a statement spans multiple lines, the opening curly bracket must be placed on its own line. - D:\devel\Pinta\Pinta\DockLibrary\DockBar.cs:60

this comes up lots of times too:
SA1200 : CSharp.Ordering : All using directives must be placed inside of the namespace. -
DockBar.cs:32
probably not important though
http://stackoverflow.com/questions/1071797/is-sa1200-all-using-directives-must-be-placed-inside-the-namespace-stylecop-pu

There is some minor detail in the way the copyright notice is formatted that results in StyleCop failing to recognise the copyright notice in many files
SA1634 : CSharp.Documentation : The file header must contain a copyright tag. - D:\devel\Pinta\Pinta\Dialogs\AboutPintaTabPage.cs:1

I'd like to clean up some of these after I get my other changes sorted (don't want to get started on more than one branch), posting this report in case anyone else wants to do any of it before me though.

Revision history for this message
Alan Horkan (horkana) wrote :
Revision history for this message
Alan Horkan (horkana) wrote :

Ideally there would be a pre-commit script that warned developers about this too
It seems git has a precommit-hook feature to run check scripts but I'm not that familiar with GIT yet

... or failing that some settings files that developers could optionally setup to work with their development environment.

Stylecop is not windows only as I previously thought, it seems to be also be available for MonoDevelop/XamarinStudio
http://addins.monodevelop.com/Project/Index/54

Revision history for this message
Alan Horkan (horkana) wrote :

Apparently others have tried to run stylecop with xbuild and had difficulties
https://stylecop.codeplex.com/workitem/7642

Revision history for this message
Alan Horkan (horkana) wrote :

I looked finding a linux equivalent to StyleCop and found Gendarme which is different but does some of the same things by different means (analysing the bytecode rather than the sourcecode).

Gendarme can be installed with Mono, and run by Travis CI
I'll attached a sample .travis.yml configuration file and a gendarme.sh shell script

It isn't pretty, but if anyone else cares to follow on it's a start.

Ideally I'd suggest it more as a way to avoid introducing any new violations than being overly worried about rewriting new code.

Revision history for this message
Alan Horkan (horkana) wrote :

Gendarme shell script that is called by previous Travis CI configuration.

Revision history for this message
Alan Horkan (horkana) wrote :

I will not have time to work on this.

I hope that including automated scripts such as gendarme will help make it easier for developers conform to the coding style you want for Pinta.

Revision history for this message
Alan Horkan (horkana) wrote :

Change summary to better describe what this report is about. In general automated code checking would be good, specifically I've provided a configuration file and a script that makes Travis CI run a program called gendarme to test the Pinta code.

Revision history for this message
Cameron White (cameronwhite91) wrote :

The code is now automatically formatted by 'dotnet format' and a .editorconfig is provided

Changed in pinta:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.