audaciaconsulting / Audacia.CodeAnalysis

MIT License
1 stars 4 forks source link

ACL1002 Warning added to a class with primary constructor #12

Closed j-r-morton closed 9 months ago

j-r-morton commented 10 months ago

Adding a primary constructor to a class seems to make the compiler think it's a big method instead of a class:

image

It would be preferable if this warning was supressed on class definitions. (note: this may now also start showing the more than X arguments warning, which also would be nice if disabled against a class? I think a similar idea was raised against primary constructors on records).

OwenLacey28 commented 9 months ago

I've looked into this and have got a minimal repo (below). Interestingly, this only happens when you inherit from a base class and call its constructor (with a paremeter), i.e it's triggered by the BaseClass(property) in the example below.


public class Test(int property) : BaseClass(property)
{
    public void MethodOne()
    {
        var one = string.Empty;
        var two = string.Empty;
        var three = string.Empty;
        var four = string.Empty;
        var five = string.Empty;
        var six = string.Empty;
    }

    public void MethodTwo()
    {
        var one = string.Empty;
        var two = string.Empty;
        var three = string.Empty;
        var four = string.Empty;
        var five = string.Empty;
    }
}

public class BaseClass
{
    protected BaseClass(int property)
    {
    }
}
OwenLacey28 commented 9 months ago

This issue is fixed in v1.7.0 of Audacia.CodeAnalysis