DotNetAnalyzers / StyleCopAnalyzers

An implementation of StyleCop rules using the .NET Compiler Platform
MIT License
2.64k stars 506 forks source link

Code fix for SA1134 (Each attribute should be placed on its own line of code) mucks up formatting on property autogetters/autosetters. #1938

Open yaakov-h opened 8 years ago

yaakov-h commented 8 years ago

Using VS2015 Update 1, StyleCop.Analyzers 1.0.0-RC2

Code before applying code fixes:

namespace SA1134PropertyCodeFix
{
    using System;

    class Blah
    {
        [Blah] public object Foo { get; set; }

        public object Bar { [Blah] get; set; }

        public object Baz { get; [Blah] set; }
    }

    class BlahAttribute : Attribute
    {
    }
}

Code after applying code fixes:

namespace SA1134PropertyCodeFix
{
    using System;

    class Blah
    {
        [Blah]
        public object Foo { get; set; }

        public object Bar {
    [Blah]
    get; set; }

        public object Baz { get;
    [Blah]
    set; }
    }

    class BlahAttribute : Attribute
    {
    }
}

Expected code after applying code fixes:

namespace SA1134PropertyCodeFix
{
    using System;

    class Blah
    {
        [Blah]
        public object Foo { get; set; }

        public object Bar
        {
            [Blah]
            get;
            set;
        }

        public object Baz
        {
            get;
            [Blah]
            set;
        }
    }

    class BlahAttribute : Attribute
    {
    }
}
sharwell commented 8 years ago

I think we need to figure out #1746 before the semantics of this code fix will be clear.

JeremyMorton commented 8 years ago

I would definitely like to see attributes on an autogetter or autosetter not trigger SA1134 (as attributes on parameters or type parameters don't). All of my autogetters are marked as [Pure], for example, but I would rather not turn off this rule for everything.