Skip to content

[Bug]: How to force ignoring methods with attributes #1925

Description

@MSchleinkoferV

Description

If tags precede methods it is not possible to disable re-formatting.

[someTag]
public void MyMethod()
{
   // how to keep formatting untouched here
}

Steps to Reproduce

// csharpier-ignore is applied to code:

internal class CSharpierTest
{
    public void WillBeFormatted()
    {
        var x = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30;

        var y = x + 100;
    }

    // csharpier-ignore
    public void IsNotFormatted()
    {
        var x = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30;

        var y = x + 100;

    }

    [AttributeUsage(AttributeTargets.Method)]
    public class TagAttribute : Attribute { }

    [Tag]
    // csharpier-ignore
    public void ShallNotBeFormatted_ButRemovesSpaceLines()
    {
        var x = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30;

        var y = x + 100;

    }

    // csharpier-ignore
    [Tag]
    public void ShallNotBeFormatted_ButFormats()
    {
        var x = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30;

        var y = x + 100;

    }
}

Expected Behavior

Only the first method should be re-formatted:

internal class CSharpierTest
{
    public void WillBeFormatted()
    {
        var x =
            1
            + 2
            + 3
            + 4
            + 5
            + 6
            + 7
            + 8
            + 9
            + 10
            + 11
            + 12
            + 13
            + 14
            + 15
            + 16
            + 17
            + 18
            + 19
            + 20
            + 21
            + 22
            + 23
            + 24
            + 25
            + 26
            + 27
            + 28
            + 29
            + 30;

        var y = x + 100;
    }

    // csharpier-ignore
    public void IsNotFormatted()
    {
        var x = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30;

        var y = x + 100;

    }

    [AttributeUsage(AttributeTargets.Method)]
    public class TagAttribute : Attribute { }

    [Tag]
    // csharpier-ignore
    public void ShallNotBeFormatted_ButRemovesSpaceLines()
    {
        var x = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30;

        var y = x + 100;

    }

    // csharpier-ignore
    [Tag]
    public void ShallNotBeFormatted_ButFormats()
    {
        var x = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30;

        var y = x + 100;

    }
}

Actual Behavior

As shown in ShallNotBeFormatted_ButRemovesSpaceLines(), although re-formatting is suppressed as expected, empty lines are removed. Without [Tag], it works as expected (see IsNotFormatted()).
It is not possible to suppress re-formatting with // csharpier-ignore before the tag (see ShallNotBeFormatted_ButFormats()):

internal class CSharpierTest
{
    public void WillBeFormatted()
    {
        var x =
            1
            + 2
            + 3
            + 4
            + 5
            + 6
            + 7
            + 8
            + 9
            + 10
            + 11
            + 12
            + 13
            + 14
            + 15
            + 16
            + 17
            + 18
            + 19
            + 20
            + 21
            + 22
            + 23
            + 24
            + 25
            + 26
            + 27
            + 28
            + 29
            + 30;

        var y = x + 100;
    }

    // csharpier-ignore
    public void IsNotFormatted()
    {
        var x = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30;

        var y = x + 100;

    }

    [AttributeUsage(AttributeTargets.Method)]
    public class TagAttribute : Attribute { }

    [Tag]
    // csharpier-ignore
    public void ShallNotBeFormatted_ButRemovesSpaceLines()
    {
        var x = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30;
        var y = x + 100;
    }

    // csharpier-ignore
    [Tag]
    public void ShallNotBeFormatted_ButFormats()
    {
        var x =
            1
            + 2
            + 3
            + 4
            + 5
            + 6
            + 7
            + 8
            + 9
            + 10
            + 11
            + 12
            + 13
            + 14
            + 15
            + 16
            + 17
            + 18
            + 19
            + 20
            + 21
            + 22
            + 23
            + 24
            + 25
            + 26
            + 27
            + 28
            + 29
            + 30;

        var y = x + 100;
    }
}

Activity

  1. changed the title [-][Bug]: Ignoring methods with tags[/-] [+][Bug]: How to force ignoring methods with tags[/+] on Oct 1, 2026
  2. changed the title [-][Bug]: How to force ignoring methods with tags[/-] [+][Bug]: How to force ignoring methods with attributes[/+] on Oct 1, 2026
  3. belav commented on Oct 1, 2026

    @belav
    Owner

    The final example you give, the csharpier-ignore is for the attribute, not the method.

        // csharpier-ignore - this is only for the attribute
        [SomeAttribute(someLongValue____________________________________________, someLongValue____________________________________________)]
        public void ignore()
        {
            var someVariable = someLongValue____________________________________________ + someLongValue____________________________________________;
    
            return;
        }

    It does appear that csharpier is losing blank lines in an ignored method when that method has an attribute though. These two methods should format the same

    internal class CSharpierTest
    {
        // csharpier-ignore
        public void SomeMethodWithLines()
        {
            var someVariable = someLongValue____________________________________________ + someLongValue____________________________________________;
    
            return;
        }
    
        [SomeAttribute]
        // csharpier-ignore
        public void SomeMethodWithLines()
        {
            var someVariable = someLongValue____________________________________________ + someLongValue____________________________________________;
    
            return;
        }
  4. added this to the 1.4.0 milestone on Oct 1, 2026
  5. added a commit that references this issue on Oct 1, 2026
    76c4264
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions