Skip to content

Conversation

@DaelonSuzuka
Copy link
Collaborator

@DaelonSuzuka DaelonSuzuka commented Aug 2, 2025

Fixes #890

@theXYZT
Copy link

theXYZT commented Aug 3, 2025

I may be reading this wrong, but it doesn't seem like this fixes: [self] -> [ self ].

@DaelonSuzuka
Copy link
Collaborator Author

No it doesn't. (when would that even happen?)

@theXYZT
Copy link

theXYZT commented Aug 3, 2025

No it doesn't. (when would that even happen?)

When you use 'self' as a key for a Dictionary.

@DaelonSuzuka
Copy link
Collaborator Author

Yes that's obvious but I'm struggling to imagine when I would ever want that.

@Calinou Calinou added the bug label Aug 8, 2025
@DaelonSuzuka
Copy link
Collaborator Author

@theXYZT can you think of any other cases?

image

@theXYZT
Copy link

theXYZT commented Aug 8, 2025

In your image, is { self: self } supposed to be the formatted text?

@theXYZT
Copy link

theXYZT commented Aug 8, 2025

Thinking about it, is there a reason why this can't be the simplification for part of this fix:

if (next === "]") {
    return "";
}

if (prev === "[") {
    return "";
}

Are there any cases where you want an opening square bracket / closing square bracket to be followed / preceded by a space?

But perhaps this is for a different pull request to experiment with.

@DaelonSuzuka
Copy link
Collaborator Author

In your image, is { self: self } supposed to be the formatted text?

Hm, I just doubled checked and other dict literals are not expanded here. I've been writing mostly ts lately and a similar object literal does have the extra padding.

Just checked python/ruff, and padding is not added to dict literals there.

I have intentionally avoided adding more rules for this syntax because my formatter does not modify indentation at all. A proper formatter would re-indent list/dict literals, collapse small ones onto one line, expand large ones onto multiple lines, etc. Mine is not smart enough to handle that so I've just left them alone.

Let me mess with it a bit more...

@DaelonSuzuka
Copy link
Collaborator Author

image

There we go, much better. I removed the special cases entirely and changed it to treat self/super like regular identifiers. Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lines being changed here should probably be removed entirely rather than commented out (since you can find them back using version control).

@theXYZT
Copy link

theXYZT commented Sep 19, 2025

Is there anything blocking this from being pushed? I'd love to have a nightly build with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

self keyword adds space after it when formatting

3 participants