Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding formatting for spread element #1179

Merged
merged 4 commits into from
Feb 18, 2024
Merged

Adding formatting for spread element #1179

merged 4 commits into from
Feb 18, 2024

Conversation

belav
Copy link
Owner

@belav belav commented Feb 17, 2024

closes #1167

@belav
Copy link
Owner Author

belav commented Feb 17, 2024

@jods4 I went with a space after the operator because that is what is in all the official docs

int[] someArray = [.. list];

There were only two instances of spread in here - belav/csharpier-repos#104 - or at least only two that changed formatting. I'm going to update the code there and then do some proper querying to see how the spread operator has been used so far. I'm open to either space or no space. JS/TS is no space as far as I know.

edit - just 10 instances in all the csharpier-repos, and they all use [.. list]
edit - new PR, not sure why it only has 1 instance now https://github.com/belav/csharpier-repos/pull/106/files I think I randomly delete 50% of the files to cut down on the time it takes to run these checks.

@belav belav marked this pull request as ready for review February 17, 2024 20:45
@jods4
Copy link

jods4 commented Feb 18, 2024

@belav I wrote my example without a space after .. because I'm used to JS/TS, but I don't have a strong preference. Space is fine, too.

Most important is that you've fixed the blind spot in formatting the spreaded value! 👍

@belav belav merged commit 0983917 into main Feb 18, 2024
3 checks passed
@belav belav deleted the format-spread branch February 18, 2024 15:54
@prettyv
Copy link

prettyv commented Feb 18, 2024

As already mentioned due to how the spread element/operator is used without an additional space in at least JS/TS the option without space would feel more "natural" to me, especially when switching between languages often. The official documentation is also a bit inconsistent here where in its explanatory text it doesn't use spaces either ("The spread element ..vowels", "The spread element ..consonants"), which makes more intuitive sense to me akin to prefix increment and decrement operators.

Would be happy if this could be reconsidered.

@jerone
Copy link

jerone commented Oct 16, 2024

Excuses to respond to an older PR.

I came to this repo to report (or ask to remove) the space between the spread operator and the operand.

This just looks weird:

internal class Test
{
    private static readonly int[] Array = [1, 2, 3];

    private static void Main()
    {
        int[] _ =
        [
            .. Test.Array,
            .. Test.Array,
            .. Test.Array,
            .. Test.Array,
            .. Test.Array,
            .. Test.Array,
        ];
    }
}

Me too, am familiar with JS syntax, but then again, the spread operator in JS uses three dots anyways.

But, after reading dotnet/roslyn#72863 & dotnet/roslyn#71219 it appears that the space is intentional.

Ranges and spreads are entirely different and intentionally have different spacing to reflect that.

it's not a unary expression, so it gets a space

TIL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spread (in collection expression) are not formatted
4 participants