Skip to content

Applying autofixes uses wrong line endings / should honour .editorconfig #3360

@dgeelen-uipath

Description

@dgeelen-uipath

.editorconfig:

[*.cs]
end_of_line = lf

Example.cs:

namespace Bug
{
    public static class Example
    {
        public static int MissingNewLine(bool condition)
        {
            if (condition)
            {
                return 42;
            } // SA1513: Closing brace should be followed by a blank line
            return 0;
        }
    }
}

Applying the automatic fix for SA1513 (and probably a bunch of others, but this is the one where I tracked down the problem) inserts a CRLF (carriage return + line feed) combination, but the file uses LF only. In Visual Studio, you can observe the state of line endings for the current file in the bottom right corner of the file-editor pane. It should initially say LF, when the automatic fix is applied it will switch to MIXED instead:
image

The next time the file is opened (but not immediately when the problem is introduced!), Visual Studio will complain about mixed line endings, and suggest to 'normalize' the line endings (using the wrong default option, of-course):
image

The root-cause is probably because the fixer appears to use a hard-coded CRLF (SyntaxFactory.CarriageReturnLineFeed) rather than the currently configured line-end character.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions