csharpier icon indicating copy to clipboard operation
csharpier copied to clipboard

Verbatim String formatting

Open belav opened this issue 4 years ago • 3 comments

Some changes were made recently that affected some instances of verbatim strings. See the StringLiteral/VerbatimStrings.cst file for some of the examples. There are probably a number of other edge cases.

Some examples of how I believe we want to format things

// right now we include a line/indent in the variable declaration, which makes this not work
var value = @"one
two";

// right now the formatting for arguments (attribute list does them separately) includes an indent if there are any. We should possibly exclude indent if there is a single argument and it is a string literal.
CallMethod(@"one
two");

belav avatar May 14 '21 05:05 belav

https://github.com/belav/csharpier/tree/verbatim-strings has some possible changes to deal with arguments. It breaks a lot of existing tests. Possibly the logic in that branch should only occur if there is a single argument and that single argument is a verbatim string literal.

belav avatar May 14 '21 05:05 belav

Another edge case, should the method call after this string break before the . ? Should the method call itself break?

            var args = @"
./src
--fix-whitespace
--fix-style
warn
--fix-analyzers
info
--verbosity
diag
--check
--include
*.cs
--exclude
*.vb
--report
report.json
--include-generated".Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);

belav avatar May 18 '21 01:05 belav

Another edge case

[assembly: System.Copyright(
    @"(C)""
2009"
)]
class ClassName { }
// should probably be
[assembly: System.Copyright(@"(C)""
2009")]
class ClassName

belav avatar Jun 14 '21 19:06 belav