>
> Hello everyone,
>
> I am a beginner with using Gendarme, but my interest in it took off
> after a few production bugs at work. There are two coding errors I
> frequently run into. The first is when someone writes a property
> ("Foo") to access a private field ("foo") with a similar name but
> different casing, and instead of the get accessor returning the field
> (lower case) it returns the property (upper case). This usually
> causes a stack overflow exception.
That would be a nice rule. Smokey had a slightly more general rule
that checked for a method which always called itself which found a
number of bad getters in the system assemblies.
> The second error is when code
> running on worker threads throws an exception that isn't caught by a
> try/catch, which will either kill the thread or the entire process.
As of .NET 2.0 it will normally kill the process. Rolf recently added
a similar rule for delegates used with p/invoke and I think he's
intending to add a similar rule for threads, thread pools, and maybe
thread timers.
>
>
> I'd like to develop rules to check for these two coding practices, and
> contribute them back to the project. Where can the best documentation
> be found for writing rules? Is the API for rules built entirely off
> of Cecil, or is there a separate API?
<http://groups.google.com/group/gendarme/web> has some advice for
writing rules. Rules tend to use Cecil pretty heavily, but they also
make use of stuff in the framework directory, especially the rocks
stuff. If you have questions to may want to try the #gendarme channel
on irc.gimp.net: there is normally someone awake there pretty much all
the time.
-- Jesse
>
>
> On Feb 13, 2009, at 7:07 AM, Chris wrote:
>
>>
>> Hello everyone,
>>
>> I am a beginner with using Gendarme, but my interest in it took off
>> after a few production bugs at work. There are two coding errors I
>> frequently run into. The first is when someone writes a property
>> ("Foo") to access a private field ("foo") with a similar name but
>> different casing, and instead of the get accessor returning the field
>> (lower case) it returns the property (upper case). This usually
>> causes a stack overflow exception.
>
> That would be a nice rule. Smokey had a slightly more general rule
> that checked for a method which always called itself which found a
> number of bad getters in the system assemblies.
>
Note that gendarme does have this rule:
Gendarme.Rules.Correctness#BadRecursiveInvocationRule. I didn't see it
the first time because gendarme seems to now return a non-zero exit
code which broke my test script...
-- Jesse
On Fri, 2009-02-13 at 07:07 -0800, Chris wrote:
> Hello everyone,
>
> I am a beginner with using Gendarme, but my interest in it took off
> after a few production bugs at work. There are two coding errors I
> frequently run into. The first is when someone writes a property
> ("Foo") to access a private field ("foo") with a similar name but
> different casing, and instead of the get accessor returning the field
> (lower case) it returns the property (upper case). This usually
> causes a stack overflow exception.
As Jesse pointed out Gendarme already has such a rule. However if you
find out any case that are not reported by Gendarme (always a
possibility) then please report them to us.
> The second error is when code
> running on worker threads throws an exception that isn't caught by a
> try/catch, which will either kill the thread or the entire process.
That's very similar to a very recent rule added to Gendarme (which check
for delegates passed to native code). You can read the source from:
http://anonsvn.mono-project.com/viewvc/trunk/mono-tools/gendarme/rules/Gendarme.Rules.Interoperability/DelegatesPassedToNativeCodeMustIncludeExceptionHandlingRule.cs?revision=126597&view=markup
Be warned that it's a bit more complex than the average rule.
> I'd like to develop rules to check for these two coding practices, and
> contribute them back to the project. Where can the best documentation
> be found for writing rules? Is the API for rules built entirely off
> of Cecil, or is there a separate API?
Cecil provides almost everything you need to write rules.
The Gendarme framework provides the "how" (i.e. runner) rules are
executed against the code being analyzed. The framework also include
helper classes and extension methods (referred to rocks) to ease rule
creation (e.g. enhance rule readability) and promote code sharing.
Sadly the framework documentation is not complete. The best way to start
is to read the source of existing rules (e.g. similar to the one you
wish to implement). A code editor that support "code completion" can be
very helpful to find out the "rocks" available to help you.
Sebastien