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

Rule to indent multiline strings #243

Closed
hartbit opened this issue Apr 13, 2018 · 7 comments
Closed

Rule to indent multiline strings #243

hartbit opened this issue Apr 13, 2018 · 7 comments
Labels
enhancement fixed in develop bug/feature resolved in the develop branch

Comments

@hartbit
Copy link

hartbit commented Apr 13, 2018

It would be nice to have a rule to indent multiline strings from:

let sql = """
SELECT *
FROM authors
WHERE authors.name LIKE '%David%'
"""

into

let sql = """
    SELECT *
    FROM authors
    WHERE authors.name LIKE '%David%'
    """

It seems to be the style most often used in the community too.

@nicklockwood
Copy link
Owner

@hartbit sorry for not responding earlier. Seems like a reasonable feature - would you be interested in creating a PR?

@hartbit
Copy link
Author

hartbit commented Jul 27, 2018

I have very little left for Open Source contributions :-( I'll have a look but I can't promise anything.

@neilt
Copy link

neilt commented Mar 14, 2019

Also note that indentation inside the multiline string should be preserved.

For example:

let sql = """
    SELECT *
    FROM  authors,
          books
    WHERE authors.name LIKE '%David%'
         AND pubdate < $1
    """

@nicklockwood
Copy link
Owner

@neilt yes, that logic is already in place.

The SwiftFormat tokenizer actually bakes the relative indent into the string tokens themselves, so as long as the string lines are all given the same indent, the relative indent will be correctly preserved.

@facumenzella
Copy link
Contributor

Hello there 👋
I was wondering how did you think about this rule? I've managed to write something for multilineStringAssignmets like the examples above, but I have some doubts about it:

  1. Do you think something like indentMultilineStringAssignments makes sense as a separate rule?

  2. Where should the .startOfScope(""") be? This should probably be another rule, right?

+++ let sql = """
--- let sql = 
---    """
    SELECT *
    FROM  authors,
          books
    WHERE authors.name LIKE '%David%'
         AND pubdate < $1
    """

@nicklockwood
Copy link
Owner

@facumenzella my understanding of the feature request was that it should convert:

let sql = """
SELECT *
FROM  authors,
      books
WHERE authors.name LIKE '%David%'
     AND pubdate < $1
"""

to:

let sql = """
    SELECT *
    FROM  authors,
          books
    WHERE authors.name LIKE '%David%'
         AND pubdate < $1
    """

Which I think should not be a new rule, but a configuration option like --indentstrings true that is applied by the existing indent rule.

Unwrapping the """ onto previous line seems like a different requirement.

@nicklockwood
Copy link
Owner

@hartbit implemented in 0.49.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement fixed in develop bug/feature resolved in the develop branch
Projects
None yet
Development

No branches or pull requests

4 participants