Lint for C# ?

D

Davej

http://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis#.NET

Is anyone here using a lint-like program for C# ? I just found a bug
that would be easy to search for: I'd like to see a warning for an if
that follows another if with no space between them if the second if is
followed by one or more else if's.

Would Lint or these other style tools have warned about this?

if (...)
{
....
}
if (...)
{
....
}
else if (...)
{
....
}
else if (...)
{
....
}
else if (...)
{
....
}
 
A

Arne Vajhøj

http://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis#.NET

Is anyone here using a lint-like program for C# ? I just found a bug
that would be easy to search for: I'd like to see a warning for an if
that follows another if with no space between them if the second if is
followed by one or more else if's.

Would Lint or these other style tools have warned about this?

if (...)
{
...
}
if (...)
{
...
}
else if (...)
{
...
}
else if (...)
{
...
}
else if (...)
{
...
}

StyleCop does give warning/error on this.

<quote>
SA1513: ClosingCurlyBracketMustBeFollowedByBlankLine

Cause
A closing curly bracket within a C# element, statement, or expression is
not followed by a blank line.

Rule Description
To improve the readability of the code, StyleCop requires blank lines in
certain situations, and prohibits blank lines in other situations. This
results in a consistent visual pattern across the code, which can
improve recognition and readability of unfamiliar code.

A violation of this rule occurs when a closing curly bracket is not
followed by a blank line.
</quote>

StyleCop is available here:
http://stylecop.codeplex.com/

You may want to disable many of its rules as it is pretty strict
by default.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top