yapf icon indicating copy to clipboard operation
yapf copied to clipboard

Comment alignment when `spaces_before_comment` is a list

Open 01tot10 opened this issue 3 years ago • 2 comments

Hey all!

I've just started using yapf with hopes for making easier the burden of code-cleanup.

I very much like the aesthetics of aligned comments when it comes to blocks of code, but having a list of values in spaces_before_comment kinda creates problems when I have blocks with comments on the side, as well as commented out lines.

I can imagine comments and commented out lines within a block are hard to distinguish programmatically, but is there something in yapf that would allow for not having the problem, where:

from torch.utils.data import DataLoader # this is an important comment
import numpy as np
# import torch
import matplotlib.pyplot as plt
# import sounddevice as sd
# import os
# import torchaudio

gets corrected to:

from torch.utils.data import DataLoader # this is an important comment
import numpy as np
                                        # import torch
import matplotlib.pyplot as plt
                                        # import sounddevice as sd
                                        # import os
                                        # import torchaudio

Thank you in advance!

01tot10 avatar Jan 26 '22 08:01 01tot10

Hi, check out my pull request at https://github.com/google/yapf/pull/1022, a knob added to choose not to align newline comments with inline comments.

lizawang avatar Sep 13 '22 15:09 lizawang

Hi @lizawang. I'll take a look at it soon. Thank you!

bwendling avatar Sep 14 '22 11:09 bwendling