google / google/yapf

Allow forcing newline after when training comma heuristic happens

Open
#929 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
14k
Forks
904
PR merge metrics
No merged PRs in 30d

Description

This is about making lists with "one item per line" (triggered by the trailing comma heuristic) easy to sort (so the brackets need to be on separate lines) but I want other lists (no trailing comma) to have a compact "indentation signals nesting" style. I played around with various knobs but nothing helped...

I'm not sure whether I'm missing something why this would be a bad idea and I might be completely off. This could be related to #134, too.

The config currently is (short lines to help the example):

```
[style]
based_on_style = pep8
COLUMN_LIMIT = 30
```

And I get the following formatting:

```
def asdf():
a = {
"asdf": [
1, 2, 3, 4, 5, 6,
fdsafdsafdsafdsa,
fdasfdasfdasfdsa,
fdsafdsafdsa,
fdsafdsa,
afsdafdsa
]
}

b = [
1,
2,
3,
4,
5,
6,
fd,
fdsafdsafdsafdsa,
fdasfdasfdasfdsa,
fdsafdsafdsa,
fdsafdsa,
afsdafdsa,
]
```

What I would like to get is:

```
def asdf():
a = {
"asdf": [
1, 2, 3, 4, 5, 6,
fdsafdsafdsafdsa,
fdasfdasfdasfdsa,
fdsafdsafdsa,
fdsafdsa,
afsdafdsa]}

b = [
1,
2,
3,
4,
5,
6,
fd,
fdsafdsafdsafdsa,
fdasfdasfdasfdsa,
fdsafdsafdsa,
fdsafdsa,
afsdafdsa,
]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.