Code Monkey home page Code Monkey logo

gendarme's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gendarme's Issues

[Patch] DeclareEventsExplicitlyRule raised on generated code

The DeclareEventsExplicitlyRule is raised when using a lambda expression for an event.
using System;

sealed class Test
{
        class TestEventArgs : EventArgs
        {
                public TestEventArgs (int x)
                {
                        this.X = x;
                }

                public int X { get; private set; }
        }

        event EventHandler<TestEventArgs> TestEvent;

        public Test ()
        {
                TestEvent += (o,e) => Console.WriteLine ("Test: {0}", e.X); // <-------- Gendarme complains about this line

                if (TestEvent != null)
                        TestEvent (this, new TestEventArgs (42));
        }

        static void Main ()
        {
                new Test ();
        }
}

3. DeclareEventsExplicitlyRule

Problem: An event handler was declared without the 'event' keyword
* Severity: High, Confidence: High
* Target:   Test
* Location: System.EventHandler`1<Test/TestEventArgs> Test::<>f__am$cache0

Solution: Add the missing 'event' keyword to your event handler declaration
More info available at: https://github.com/spouliot/gendarme/wiki/Gendarme.Rules.Correctness.DeclareEventsExplicitlyRule(2.10)

Misleading advice

In the rule https://github.com/spouliot/gendarme/wiki/Gendarme.Rules.Performance.AvoidConcatenatingCharsRule(2.10) it is said that boxing is used on parameters of value-type. However, here http://programmers.stackexchange.com/questions/266369/should-i-use-tostring-when-concatenating-string-and-integer-variables-in-c it is actually shown as false positive, since all of the arguments will be converted to string first by Concat method, which will call ToString() internally. So, calling ToString() method explicitly is redundant.

InitializationERROR: Unknown custom metadata item kind: 6

Gendarme v2.10.0.0

When I try from gendarme-wizard, got below error in Analysis Results page.
Stack trace: Microsoft.Cci.Pdb.PdbDebugException: Unknown custom metadata item kind: 6
at Microsoft.Cci.Pdb.PdbFunction.ReadCustomMetadata(BitAccess bits)
at Microsoft.Cci.Pdb.PdbFunction..ctor(String module, ManProcSym proc, BitAccess bits)
at Microsoft.Cci.Pdb.PdbFunction.LoadManagedFunctions(String module, BitAccess bits, UInt32 limit, Boolean readStrings)
at Microsoft.Cci.Pdb.PdbFile.LoadFuncsFromDbiModule(BitAccess bits, DbiModuleInfo info, IntHashTable names, ArrayList funcList, Boolean readStrings, MsfDirectory dir, Dictionary`2 nameIndex, PdbReader reader)
at Microsoft.Cci.Pdb.PdbFile.LoadFunctions(Stream read, BitAccess bits, Boolean readAllStrings, Int32& age, Guid& guid)
at Microsoft.Cci.Pdb.PdbFile.LoadFunctions(Stream read, Boolean readAllStrings, Int32& age, Guid& guid)
at Mono.Cecil.Pdb.PdbReader.PopulateFunctions()
at Mono.Cecil.Pdb.PdbReader.ProcessDebugHeader(ImageDebugDirectory directory, Byte[] header)
at Mono.Cecil.ModuleDefinition.ProcessDebugHeader()
at Gendarme.Framework.Rocks.ModuleRocks.LoadDebuggingSymbols(ModuleDefinition self)
at Gendarme.Framework.Runner.Initialize()
at Gendarme.GuiRunner.Execute()

It gives the result without any error, when I click on Back and then again click on Next.

It also fails on console with,
InitializationERROR: Unknown custom metadata item kind: 6

False Positive - AvoidRepetitiveCallsToPropertiesRule

The code down below triggers the AvoidRepetitiveCallsToPropertiesRule, however there is no reason to cache the property sins we always return before a second call to the property is made.

public bool MethodAccessException() 
{
    if (aError) {
        Debug (this.GetType().Name, "Some Message");
        return false;
    }

    ....

    if (bError) {
        Debug (this.GetType().Name, "A other Message");
        return false;
    }

    ....
}

Detect unhandled exceptions?

Is it possible to detect unhandled exceptions with Gendarme? I want to see if none of the callers catch an exception of a method which throws, causing an uncaught exception to occur.

DisposableFieldsShouldBeDisposedRule gives false positives on generic classes

Code sample ( https://gist.github.com/3736634 ):

    public class GenericClassWithDisposableField<T> : IDisposable
    {
        private IDisposable dataTable;
        public void Dispose()
        {
            dataTable.Dispose();
        }
    }

    [Test]
    public void GenericClass_Disposal()
    {
        AssertRuleSuccess<GenericClassWithDisposableField<Object>>();
    }

This does report dataTable as not being disposed. Removing generic parameter from the parent class makes the test pass.

AvoidUncalledPrivateCodeRule fires on events and proprties

The AvoidUncalledPrivateCodeRule fires on events and properties (add_, remove_, get_, set_). It is quite common to have an event which only utilizes add_ and not remove_. get_ and set_ are caught only when they are not from automatic properties, but it is still quite common to have a get_ or set_ which follow the basic pattern of:

int x;
int X {
    get { return x; }
    set { x = value; }
}

or other trivial thing, in which it is not necessary to warn about unused code. For example, a method may set 'x' directly, rather than using the property, in which case Gendarme will complain that the setter was never utilized.

using System;

class Test
{
    event EventHandler<EventArgs> TestEvent; // <----- Gendarme complains that add_ and remove_ are never used

    int _i;

    int TestProp {  // <----- Gendarme complains that get_ and set_ are never used
        get { return _i; }
        set { _i = value; }
    }

    int TestProp2 { get; set; } // <----- Gendarme recognizes these as automatically generated

    static void Main ()
    {
        new Test ();
    }
}

2. AvoidUncalledPrivateCodeRule

Problem: This private or internal (assembly-level) member does not have callers in the assembly, is not invoked by the common language runtime, and is not invoked by a delegate.
* Severity: High, Confidence: Normal
* Target:   System.Void Test::add_TestEvent(System.EventHandler`1<System.EventArgs>)
* Details:  The private method code is not used in its declaring type.

Solution: Remove the unused code or add code to call it.
More info available at: https://github.com/spouliot/gendarme/wiki/Gendarme.Rules.Performance.AvoidUncalledPrivateCodeRule(2.10)


3. AvoidUncalledPrivateCodeRule

Problem: This private or internal (assembly-level) member does not have callers in the assembly, is not invoked by the common language runtime, and is not invoked by a delegate. 
* Severity: High, Confidence: Normal
* Target:   System.Void Test::remove_TestEvent(System.EventHandler`1<System.EventArgs>)
* Details:  The private method code is not used in its declaring type.

Solution: Remove the unused code or add code to call it.
More info available at: https://github.com/spouliot/gendarme/wiki/Gendarme.Rules.Performance.AvoidUncalledPrivateCodeRule(2.10)

4. AvoidUncalledPrivateCodeRule

Problem: This private or internal (assembly-level) member does not have callers in the assembly, is not invok
* Severity: High, Confidence: Normal
* Target:   System.Int32 Test::get_TestProp()
* Details:  The private method code is not used in its declaring type.

Solution: Remove the unused code or add code to call it.
More info available at: https://github.com/spouliot/gendarme/wiki/Gendarme.Rules.Performance.AvoidUncalledPri


5. AvoidUncalledPrivateCodeRule

Problem: This private or internal (assembly-level) member does not have callers in the assembly, is not invok
* Severity: High, Confidence: Normal
* Target:   System.Void Test::set_TestProp(System.Int32)
* Details:  The private method code is not used in its declaring type.

Solution: Remove the unused code or add code to call it.
More info available at: https://github.com/spouliot/gendarme/wiki/Gendarme.Rules.Performance.AvoidUncalledPri

DoubleCheckLockingRule and MemoryBarrier (instead of volatile field)

DoubleCheckLockingRule proposes the use of the volatile keyword when using .NET >= 2.0.

This is right but according to http://blogs.msdn.com/b/brada/archive/2004/05/12/130935.aspx using a MemoryBarrier is a better solution.

So we need to, either mention this in the rule documentation, or change the rule so it proposes this as the good example. Or maybe have another rule in the Performance rules set that checks for this (since using volatile is actually correct wrt Concurrency, but less performant).

Prevent usage of new TimeSpan(_,_,_)

Not issue but new feature (for the wishlist):

I just saw in a piece of code:
TimeSpan SIX_HOURS = new TimeSpan(0, 6, 0);

Which is clearly wrong, because that is 6 minutes.
What Gendarme could do in this cases is always flag this constructor as "Bad practice", and propose the usage of other APIs such as TimeSpan.FromMinutes(), TimeSpan.FromSeconds(), and so on...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.