Opened 5 years ago

Closed 5 years ago

#1759 closed enhancement (done)

Add FxCop rules to HeuristicLab

Reported by: abeham Owned by: abeham
Priority: medium Milestone: HeuristicLab 3.3.7
Component: General Version: 3.3.7
Keywords: Cc:

Description (last modified by abeham)

There's a tutorial on the codeanalysis blog on how to write custom rules. They note that writing custom rules is not a supported feature. However, implementing a rule doesn't seem to be that complicated (depends of course) and we might benefit a lot from having the most important rules manifested and automatically tested.

The integration into the build seems quite easy. First, the rules are written as classes deriving from BaseIntrospectionRule in an assembly. The assembly has to be placed into a convenient location in the repository. The assembly also contains an additional xml file that provides metadata on these rules. Having this, a custom ruleset needs to be created in the solution folder. This ruleset references the rules in the assembly and defines whether a certain rule is a warning or error. Finally, the ruleset can be selected in the project properties in the tab "Code Analysis" and have it checked on build. Manual integration should also be possible easily as FxCop is essentially a command line program.

Official documentation on FxCop is hardly available, but there is a good summary (PDF) available from another party.

Rules implemented:

  • HL0001: Check if an after-deserialization hook is called AfterDeserialization and a before-serialization hook is called BeforeSerialization
  • HL0002: Check that there is at most one hook in each class

Further rules are interesting, but could not be realized in time:

  • Check if the logic in the cloning constructor is correct (cloner.Clone(x))
  • Check if the clone override exists and calls the correct method
  • Check if the StorableClass attribute is present
  • Check if the Storable attribute is only attached to properties (new requirement)
  • Check if AssemblyVersion and AssemblyFileVersion are correct

An integration into the builder infrastructure would be nice.

Change History (9)

comment:1 Changed 5 years ago by abeham

  • Owner changed from swagner to abeham
  • Status changed from new to accepted

comment:2 Changed 5 years ago by abeham

r7340: added project to include FxCop rules for HeuristicLab 3.3

Note that the first test rule wasn't a particular easy idea and it's not 100% correct. I basically wanted to check if the StorableHook attribute is attached to a method and check if it's called AfterDeserialization. However, there are two hook types and they're distinguished by a property. I've not yet found out how to check that so it just assumes that any StorableHook needs to be called AfterDeserialization. This is not generally correct, but I'm pretty sure we don't have any BeforeSerialization hooks.

I've not yet added this to the trunk, but tested it briefly and it worked nicely.

comment:3 Changed 5 years ago by abeham

  • Description modified (diff)

comment:4 Changed 5 years ago by abeham

r7350

  • Changed storable hook name rule to correctly distinguish between BeforeSerialization and AfterDeserialization hooks
  • Added a new rule that checks if more than one storable hook is defined in a class

comment:5 Changed 5 years ago by abeham

r7352

  • Added simple command file to execute FxCop rules from HeuristicLab.FxCop.dll on all HeuristicLab.*.dll files in the bin directory

comment:6 Changed 5 years ago by abeham

r7369: Added processor architecture detection

comment:7 Changed 5 years ago by abeham

  • Description modified (diff)
  • Owner changed from abeham to swagner
  • Status changed from accepted to reviewing

Since this doesn't really affect the release we could also move this ticket to the backlog.

comment:8 Changed 5 years ago by abeham

  • Owner changed from swagner to abeham
  • Status changed from reviewing to readytorelease

comment:9 Changed 5 years ago by mkommend

  • Resolution set to done
  • Status changed from readytorelease to closed
  • Version changed from 3.3.6 to 3.3.7
Note: See TracTickets for help on using tickets.