bazel-contrib / bazel-contrib/buildtools
Buildifier reformats assignment ignoring "# buildifier: leave-alone"
- Dominant language
- Go
- Stars
- 1.2k
- Forks
- 471
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 13
Description
Hi, I have a `.bzl` file that I need to keep compatible with both Starlark and Bash
The original contents of the file:
```
# buildifier: leave-alone
MY_VAR="value"
```
However after running `buildifier -v -lint fix -mode fix` against this file (we do that as pre-commit hook) it still reformats the assignment by adding _spaces_ aroud `=`:
```
# buildifier: leave-alone
MY_VAR = "value"
```
` = ` is invalid in Bash :(
As mentioned here https://github.com/bazelbuild/buildtools/issues/806#issuecomment-600644003 https://github.com/bazelbuild/buildtools/blob/195b83e94906df245fdc44da27b1be5489087025/build/rewrite.go#L128-L129, I used `buildifier: leave-alone` comment, but it still reformats it.
Looks like a bug, wdyt?
---
Notes:
- I've tried to find a category that reformatting falls in, but couldn't figure out after reading https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#buildifier-warnings
- I've tried to make `buildifier` print JSON to figure out the category, but that doesn't seem to work either:
```console
buildifier --format=json --type=check myfile.bzl
buildifier: unrecognized input type check; valid types are build, bzl, workspace, default, auto
```
I'll submit a PR for this, should be `--mode=check` it seems (submitted PR https://github.com/bazelbuild/buildtools/pull/891)
Running on macOS
```
buildifier version: 3.4.0
buildifier scm revision: b1667ff58f714d13c2bba6823d6c52214705508f
```
Contributor guide
Research direction
Start in build/rewrite.go around the referenced lines 128-129 and reproduce the behavior with the shown .bzl input and buildifier command. Verify that the `# buildifier: leave-alone` directive prevents assignment reformatting, then run the relevant formatter checks to confirm the corrected behavior.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100