Skip to content

Code Fix Provider for SA1402 adds extra space #3876

Open
@MattFromRVA

Description

@MattFromRVA

While working on PR #3873 for #3109 I noticed the following errors when applying the original code fix for SA1402 for two edge cases.

If there are no using statements then a space is added between the namespace and the class in the new file:

namespace TestNamespace
{
    public class TestClass
    {
        public int MyProperty { get; set; }
    }

    public class TestClass2
    {
        public string MyProperty { get; set; }
    }
}

New File:

namespace TestNamespace
{

    public class TestClass2
    {
        public string MyProperty { get; set; }
    }
}

Similarly if there is a preprocessor directive with using statements then a space is added between the last using statement and the ending directive:

namespace TestNamespace
{
#if true
    using System;
#endif

    public class TestClass
    {
        public DateTime MyDate { get; set; }
    }

    public class TestClass2
    {
        public DateTime MyDate2 { get; set; }
    }
}

New File:

namespace TestNamespace
{
#if true
    using System;

#endif

    public class TestClass2
    {
        public DateTime MyDate2 { get; set; }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions