Skip to content

GeneratedRegex fixer forces pattern onto a single line #79891

@danmoseley

Description

@danmoseley

Consider

   private static Regex r = new Regex(@"a
             b
             c", RegexOptions.IgnorePatternWhitespace);

run the fixer, now I have

    [GeneratedRegex("a\r\n             b\r\n             c", RegexOptions.IgnorePatternWhitespace)]
    private static partial Regex MyRegex();

The semantics are the same, but the readability is gone. I would expect

    [GeneratedRegex(@"a
         b
         c", RegexOptions.IgnorePatternWhitespace)]
    private static partial Regex MyRegex();

I see #69616 which implies that whitespace is preserved but not comments. I don't see whitespace preserved, or at least not in the original form.

Metadata

Metadata

Assignees

Labels

area-System.Text.RegularExpressionsenhancementProduct code improvement that does NOT require public API changes/additionsin-prThere is an active PR which will close this issue when it is mergedneeds-further-triageIssue has been initially triaged, but needs deeper consideration or reconsiderationsource-generatorIndicates an issue with a source generator feature

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions