belav / csharpier

CSharpier is an opinionated code formatter for c#.
https://csharpier.com
MIT License
1.26k stars 84 forks source link

Don't reformat tabular data. #583

Open belav opened 2 years ago

belav commented 2 years ago

There are cases where we want to keep the original formatting on arrays

        private static readonly char[] _Base64Code = {
            '.', '/', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
            'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
            'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
            'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
            'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5',
            '6', '7', '8', '9'
        };

Keeping this as is will be much more readable than putting every char on its own line.

belav commented 2 years ago

One concern, how do we decide that it is tabular? If each line has the same number of arguments? What happens if someone adds a new argument to the first line? Do they need to rearrange the whole line?

Other examples https://github.com/dlech/SshAgentLib/blob/07c4d17f6648d13378dee274ebc8efa3c9b78144/SshAgentLib/Crypto/BCrypt.cs#L355

google java format discussion https://github.com/google/google-java-format/issues/137#issuecomment-436319566

jods4 commented 2 years ago

This kind of situations is given as examples for // prettier-ignore.

It's hard to decide when a collection should be printed with a fixed number of items per line. It's probably best to just let user indicate // csharpier-ignore if they're writing matrices, a sudoku solver or similar.

Aside: do you have a date planned for the next release? I'd like to try csharpier and provide feedback based on large, complex projects but I'm waiting for the new configurable tabs to land in released version.

belav commented 2 years ago

Aside: do you have a date planned for the next release?

I can make sure it gets out this weekend. I've been releasing less often because I haven't had as much time to work on csharpier. But I think releasing more regularly even if there is less in each release makes more sense.

SK-Genius commented 5 months ago

WorkAroundExists :-)

        private static readonly char[] _Base64Code = {
            new []{ '.', '/', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J' },
            new []{ 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V' },
            new []{ 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' },
            new []{ 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't' },
            new []{ 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5' },
            new []{ '6', '7', '8', '9' }
        }.SelectMany(_ => _).ToArray();