Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Fix string concatenation spacing in line formatter#144

Merged
jakebailey merged 1 commit intomicrosoft:masterfrom
jakebailey:fix-string-concat
Sep 27, 2018
Merged

Fix string concatenation spacing in line formatter#144
jakebailey merged 1 commit intomicrosoft:masterfrom
jakebailey:fix-string-concat

Conversation

@jakebailey
Copy link
Copy Markdown
Member

I thought of this case while reading the fstring spec. The line formatter defaults to not spacing around string literals, but it's likely better to insert a space between two string literals next to each other.

For reference:

  • autopep8 leaves spacing as-is, so 'a''b' and 'a' 'b' would not be changed (even with more than one space between). I could emulate this behavior in the line formatter, since TokenExt includes PreceedingWhitespace.
  • yapf ensures there is a space between two strings.
  • black behaves the same as yapf (barring its replacement of ' with ").


case TokenKind.Name:
case TokenKind.Constant:
if (token.IsString && next != null && next.IsString) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does next == null means that it is the last token?
Also, do you need to check if they are on the same line?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, that next would be null if the current token were the last token on the line. That next is pulled from the list of tokens of the line, not the linked-list that's happening in TokenExt which could peer forward. I wouldn't want to look at the next line, since even if the next token (ignoring whitespace) happens to be a string literal, the fact that it's on another line implies that there's already spacing and adding a space here would only be adding trailing whitespace (which would then be trimmed away).

@jakebailey jakebailey merged commit 4bdbb5e into microsoft:master Sep 27, 2018
@jakebailey jakebailey deleted the fix-string-concat branch February 14, 2019 20:12
jakebailey added a commit to jakebailey/python-language-server that referenced this pull request Nov 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants