buildtools icon indicating copy to clipboard operation
buildtools copied to clipboard

buildifier: docstrings for global variables should not be considered

Open UebelAndre opened this issue 3 years ago • 2 comments

Buildifier should allow docstrings on global variables. It currently does not and by applying something like the following diff to rules_rust

diff --git a/version.bzl b/version.bzl
index 7e40f459..fdee7b85 100644
--- a/version.bzl
+++ b/version.bzl
@@ -1,3 +1,4 @@
 """The version of rules_rust."""

 VERSION = "0.9.0"
+"""The current version of rules_rust"""

The following warning is shown:

rust/defs.bzl:68: no-effect: Expression result is not used. Docstrings should be the first statements of a file or a function (they may follow comment lines). (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#no-effect)

UebelAndre avatar Aug 27 '22 16:08 UebelAndre

I'd recommend that you use a comment:

# The current version of rules_rust
VERSION = "0.9.0"

Buildifier has special handling for comments, they are attached to a piece of code. So if a refactoring moves or deletes the variable, it will also move or delete the attached comment.

laurentlb avatar Aug 27 '22 20:08 laurentlb

I know that works but I’d consider this a feature request. I want to have docstrings for globals and right now buildifier is a big advocate against that due to the existing lint. I think the lint is wrong and it would be wonderful to support this and implement into IDE extensions

UebelAndre avatar Aug 27 '22 22:08 UebelAndre