buildtools icon indicating copy to clipboard operation
buildtools copied to clipboard

How to ignore specific lines in buildifier?

Open WesleyYue opened this issue 5 years ago • 5 comments

Hi, I'm looking for the equivalent of "clang-format: off; clang-format: on" for buildifier to ignore specific lines of code. Does that feature exist?

WesleyYue avatar Mar 14 '20 21:03 WesleyYue

What is your example, and why do you want this?

There are a few rules in: https://github.com/bazelbuild/buildtools/blob/195b83e94906df245fdc44da27b1be5489087025/build/rewrite.go including 'buildifier: leave-alone' will that handle your case?

pmbethe09 avatar Mar 18 '20 14:03 pmbethe09

@pmbethe09 I am actually looking for something similar as well.

My use case is I have classpath loading issue, and I do want to turn off buildifier for some code blocks. Thanks!

chenrui333 avatar May 14 '20 17:05 chenrui333

What exactly do you want to ignore?

If you use a linter and want to ignore a warning, use this: https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#how-to-disable-warnings If you don't want a certain list to be automatically sorted, use a comment do not sort. If you want to disable any transformations like reordering rule arguments or shortening the labels, comment the node with buildifier: leave-alone.

It's not possible to disable formatting completely because formatting itself is not supposed to change the semantics. If it does, please file a bug.

vladmos avatar May 14 '20 17:05 vladmos

what I am looking is to disable reordering for certain lines (something like below):

    # buildifier: leave-alone
    deps = [
        "//modules/base",
        "//modules/module-b",
        "//modules/module-a",
    ]

chenrui333 avatar May 14 '20 20:05 chenrui333

https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#how-to-disable-warnings is probably what you are looking for.

hofbi avatar Nov 09 '23 17:11 hofbi