Warning categories supported by buildifier's linter:
attr-applicable_licensesattr-cfgattr-licenseattr-licensesattr-non-emptyattr-output-defaultattr-package-metadataattr-single-filebuild-args-kwargsbzl-visibilitycanonical-repositoryconfusing-nameconstant-globctx-actionsctx-argsdeprecated-functiondepset-itemsdepset-iterationdepset-uniondict-concatenationdict-method-named-argduplicated-nameexternal-pathfiletypefunction-docstringfunction-docstring-argsfunction-docstring-headerfunction-docstring-returngit-repositoryhttp-archiveinteger-divisionkeyword-positional-paramslist-appendloadload-on-topmodule-docstringname-conventionsnative-androidnative-buildnative-cc-binarynative-cc-commonnative-cc-debug-package-infonative-cc-fdo-prefetch-hintsnative-cc-fdo-profilenative-cc-importnative-cc-infonative-cc-librarynative-cc-memprof-profilenative-cc-objc-importnative-cc-objc-librarynative-cc-propeller-optimizenative-cc-protonative-cc-shared-librarynative-cc-shared-library-hint-infonative-cc-shared-library-infonative-cc-testnative-cc-toolchainnative-cc-toolchain-suitenative-java-binarynative-java-commonnative-java-importnative-java-infonative-java-librarynative-java-lite-protonative-java-package-confignative-java-pluginnative-java-plugin-infonative-java-protonative-java-runtimenative-java-testnative-java-toolchainnative-packagenative-protonative-proto-commonnative-proto-infonative-proto-lang-toolchainnative-proto-lang-toolchain-infonative-pynative-sh-binarynative-sh-librarynative-sh-testno-effectout-of-order-loadoutput-groupoverly-nested-depsetpackage-namepackage-on-toppositional-argsprintprovider-paramsredefined-variablerepository-namereturn-valuerule-impl-returnsame-origin-loadskylark-commentskylark-docstringstring-iterationuninitializedunnamed-macrounreachableunsorted-dict-itemsunused-variableAll warnings can be disabled / suppressed / ignored by adding a special comment # buildifier: disable=<category_name> to the expression that causes the warning. Historically comments with buildozer instead of buildifier are also supported, they are equivalent.
# buildifier: disable=no-effect """ A multiline comment as a string literal. Docstrings don't trigger the warning if they are first statements of a file or a function. """ if debug: print("Debug information:", foo) # buildifier: disable=print
applicable_licenses as an attribute name.attr-applicable_licenses# buildifier: disable=attr-applicable_licensesUsing applicable_licenses as an attribute name may cause unexpected behavior. Its use may be prohibited in future Bazel releases.
cfg = "data" for attr definitions has no effectattr-cfg--incompatible_disallow_data_transition# buildifier: disable=attr-cfgThe Configuration cfg = "data" is deprecated and has no effect. Consider removing it. The Configuration cfg = "host" is deprecated. Consider replacing it with cfg = "exec".
attr.license() is deprecated and shouldn't be usedattr-license--incompatible_no_attr_license# buildifier: disable=attr-licenseThe attr.license() method is almost never used and being deprecated.
licenses as an attribute name.attr-licenses# buildifier: disable=attr-licensesUsing licenses as an attribute name may cause unexpected behavior.
non_empty attribute for attr definitions is deprecatedattr-non-empty--incompatible_disable_deprecated_attr_params# buildifier: disable=attr-non-emptyThe non_empty attribute for attr definitions is deprecated, please use allow_empty with an opposite value instead.
default parameter for attr.output()is deprecatedattr-output-default--incompatible_no_output_attr_default# buildifier: disable=attr-output-defaultThe default parameter of attr.output() is bug-prone, as two targets of the same rule would be unable to exist in the same package under default behavior. Use Starlark macros to specify defaults for these attributes instead.
package_metadata as an attribute name.attr-package-metadata# buildifier: disable=attr-package-metadataUsing package_metadata as an attribute name may cause unexpected behavior. Its use may be prohibited in future Bazel releases.
single_file is deprecatedattr-single-file--incompatible_disable_deprecated_attr_params# buildifier: disable=attr-single-fileThe single_file attribute is deprecated, please use allow_single_file instead.
*args and **kwargs are not allowed in BUILD filesbuild-args-kwargs--incompatible_no_kwargs_in_build_files# buildifier: disable=build-args-kwargsHaving *args or **kwargs makes BUILD files hard to read and manipulate. The list of arguments should be explicit.
bzl-visibility# buildifier: disable=bzl-visibilityIf a directory foo contains a subdirectory internal or private, only files located under foo can access it.
For example, dir/rules_mockascript/private/foo.bzl can be loaded from dir/rules_mockascript/private/bar.bzl or dir/rules_mockascript/sub/public.bzl, but not from dir/other_rule/file.bzl.
@@ which indicates a canonical repository name reference that should be avoidedcanonical-repository# buildifier: disable=canonical-repositoryUsing canonical repository names (with @@ prefix) makes BUILD files fragile to repository mapping changes and external dependency updates. Canonical names are internal implementation details that can change between Bazel versions or when external dependencies are updated.
Instead of using canonical names like:
load("@@rules_go//go:def.bzl", "go_library") deps = ["@@protobuf~5.27.0//src:message"]
Use apparent names with single @:
load("@rules_go//go:def.bzl", "go_library") deps = ["@protobuf//src:message"]
This makes your BUILD files more maintainable and resilient to changes.
l, I, or O as namesconfusing-name# buildifier: disable=confusing-nameThe names l, I, or O can be easily confused with I, l, or 0 correspondingly.
constant-glob# buildifier: disable=constant-globGlob function is used to get a list of files from the depot. The patterns (the first argument) typically include a wildcard (* character). A pattern without a wildcard is often useless and sometimes harmful.
To fix the warning, move the string out of the glob:
- glob(["*.cc", "test.cpp"]) + glob(["*.cc"]) + ["test.cpp"]
There’s one important difference: before the change, Bazel would silently ignore test.cpp if file is missing; after the change, Bazel will throw an error if file is missing.
If test.cpp doesn’t exist, the fix becomes:
- glob(["*.cc", "test.cpp"]) + glob(["*.cc"])
which improves maintenance and readability.
If no pattern has a wildcard, just remove the glob. It will also improve build performance (glob can be relatively slow):
- glob(["test.cpp"]) + ["test.cpp"]
ctx.{action_name} is deprecatedctx-actions--incompatible_new_actions_api# buildifier: disable=ctx-actionsThe following actions are deprecated, please use the new API:
ctx.new_file → ctx.actions.declare_filectx.experimental_new_directory → ctx.actions.declare_directoryctx.file_action → ctx.actions.writectx.action(command = "...") → ctx.actions.run_shellctx.action(executable = "...") → ctx.actions.runctx.empty_action → ctx.actions.do_nothingctx.template_action → ctx.actions.expand_templatectx.actions.args().add() for multiple arguments is deprecatedctx-args--incompatible_disallow_old_style_args_add# buildifier: disable=ctx-argsIt's deprecated to use the add method of ctx.actions.args() to add a list (or a depset) of variables. Please use either add_all or add_joined, depending on the desired behavior.
deprecated-function# buildifier: disable=deprecated-functionThe function defined in another .bzl file has a docstring stating that it's deprecated, i.e. it contains a Deprecated: section. The convention for function docstrings is described by the function-docstring warning.
depset-items--incompatible_disable_depset_items# buildifier: disable=depset-itemsThe items parameter for depset is deprecated. In its old form it's either a list of direct elements to be added (use the direct or unnamed first parameter instead) or a depset that becomes a transitive element of the new depset (use the transitive parameter instead).
depset-iteration--incompatible_depset_is_not_iterable# buildifier: disable=depset-iterationDepsets are complex structures, iterations over them and lookups require flattening them to a list which may be a heavy operation. To make it more obvious it's now required to call the .to_list() method on them in order to be able to iterate their items:
deps = depset() [x.path for x in deps] # deprecated [x.path for x in deps.to_list()] # recommended
depset-union--incompatible_depset_union# buildifier: disable=depset-unionThe following ways to merge two depsets are deprecated:
depset1 + depset2 depset1 | depset2 depset1.union(depset2)
Please use the depset constructor instead:
depset(transitive = [depset1, depset2])
When fixing this issue, make sure you understand depsets and try to reduce the number of calls to depset. See this explanation for more detail.
dict-concatenation--incompatible_disallow_dict_plus# buildifier: disable=dict-concatenationThe + operator to concatenate dicts is deprecated. The operator used to create a new dict and copy the data to it. There are several ways to avoid it, for example, instead of d = d1 + d2 + d3 you can use one of the following:
load("@bazel_skylib//lib:dicts.bzl", "dicts") d = dicts.add(d1, d2, d3)
d = dict(d1.items() + d2.items() + d3.items())
d = dict(d1) # If you don't want `d1` to be mutated d.update(d2) d.update(d3)
defaultdict-method-named-arg# buildifier: disable=dict-method-named-argDict methods get, pop and setdefault do not accept a named argument called default. Due to a bug, Bazel currently accepts that named argument. It is better to use a positional argument instead:
- mydict.get(5, default = 0) + mydict.get(5, 0)
foo was already found on lineduplicated-name# buildifier: disable=duplicated-nameEach label in Bazel has a unique name, and Bazel doesn’t allow two rules to have the same name. With macros, this may be accepted by Bazel (if each macro generates different rules):
my_first_macro(name = "foo") my_other_macro(name = "foo")
Although the build may work, this code can be very confusing. It can confuse users reading a BUILD file (if they look for the rule “foo”, they may read see only one of the macros). It will also confuse tools that edit BUILD files.
To fix the issue just change the name attribute of one rule/macro.
/external/ which may indicate a dependency on external repositories that could be fragileexternal-path# buildifier: disable=external-pathUsing /external/ paths may indicate a hard-coded dependency on external repository locations, which can be fragile and break when external dependencies are updated or reorganized.
Paths containing /external/ (without a leading //) may indicate:
Examples that trigger this warning:
srcs = ["/external/some_repo/file.h"] data = ["path/external/repo/data.txt"]
Instead, use proper Bazel labels:
srcs = ["@some_repo//file.h"] data = ["@repo//path:data.txt"]
Note: This warning does not apply to main repository paths like //external/... which are legitimate Bazel labels.
FileType function is deprecatedfiletype--incompatible_disallow_filetype# buildifier: disable=filetypeThe function FileType is deprecated. Instead of using it as an argument to the rule function just use a list of strings.
function-docstringfunction-docstring-headerfunction-docstring-argsfunction-docstring-return# buildifier: disable=function-docstring, # buildifier: disable=function-docstring-header, # buildifier: disable=function-docstring-args, # buildifier: disable=function-docstring-returnPublic functions should have docstrings describing functions and their signatures. A docstring is a string literal (not a comment) which should be the first statement of a function (it may follow comment lines). Function docstrings are expected to be formatted in the following way:
"""One-line summary: must be followed and may be preceded by a blank line. Optional additional description like this. If it's a function docstring and the function has more than one argument, the docstring has to document these parameters as follows: Args: parameter1: description of the first parameter. Each parameter line should be indented by one, preferably two, spaces (as here). parameter2: description of the second parameter that spans two lines. Each additional line should have a hanging indentation of at least one, preferably two, additional spaces (as here). another_parameter (unused, mutable): a parameter may be followed by additional attributes in parentheses Returns: Description of the return value. Should be indented by at least one, preferably two spaces (as here) Can span multiple lines. Deprecated: Optional, description of why the function is deprecated and what should be used instead. """
Docstrings are required for all public functions with at least 5 statements. If a docstring exists it should start with a one-line summary line followed by an empty line. If a docstring is required or it describes some arguments, it should describe all of them. If a docstring is required and the function returns a value, it should be described.
git_repository is not global anymoregit-repository--incompatible_remove_native_git_repository# buildifier: disable=git-repositoryNative git_repository and new_git_repository functions are removed. Please use the Starlark version instead:
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
http_archive is not global anymorehttp-archive--incompatible_remove_native_http_archive# buildifier: disable=http-archiveNative http_archive function is removed. Please use the Starlark version instead:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
/ operator for integer division is deprecatedinteger-division--incompatible_disallow_slash_operator# buildifier: disable=integer-divisionThe / operator is deprecated in favor of //, please use the latter for integer division:
a = b // c d //= e
keyword-positional-params# buildifier: disable=keyword-positional-paramsSome parameters for builtin functions in Starlark are keyword for legacy reasons; their names are not meaningful (e.g. x). Making them positional-only will improve the readability.
.append() to adding a single element listlist-append# buildifier: disable=list-appendTransforming x += [expr] to x.append(expr) avoids a list allocation. NOTE: .append() does not work if the target is a select, hence this warning can safely be ignored or suppressed.
load# buildifier: disable=loadload is used to import definitions in a BUILD file. If the definition is not used in the file, the load can be safely removed. If a symbol is loaded two times, you will get a warning on the second occurrence.
Delete the line. When load is used to import multiple symbols, you can remove the unused symbols from the list. To fix your BUILD files automatically, try this command:
$ buildozer 'fix unusedLoads' path/to/BUILD
If you want to keep the load, you can disable the warning by adding a comment # @unused.
load-on-top--incompatible_bzl_disallow_load_after_statement# buildifier: disable=load-on-topObsolete; the warning has been implemented in the formatter and the fix is now automatically applied to all files except WORKSPACE files (unless suppressed).
Load statements should be first statements (with the exception of WORKSPACE files), they can follow only comments and docstrings.
module-docstring# buildifier: disable=module-docstring.bzl files should have docstrings on top of them. A docstring is a string literal (not a comment) which should be the first statement of the file (it may follow comment lines). For example:
""" This module contains build rules for my project. """ ...
name-conventions# buildifier: disable=name-conventionsBy convention, all variables should be lower_snake_case, constant should be UPPER_SNAKE_CASE, and providers should be UpperCamelCase ending with Info.
native-android--incompatible_disable_native_android_rules# buildifier: disable=native-androidThe Android build rules should be loaded from Starlark.
Update: the plans for disabling native rules have been postponed, at the moment it's not required to load Starlark rules.
native module shouldn't be used in BUILD filesnative-build# buildifier: disable=native-buildThere's no need in using native. in BUILD files, its members are available as global symbols there.
native-cc-binarynative-cc-commonnative-cc-debug-package-infonative-cc-fdo-prefetch-hintsnative-cc-fdo-profilenative-cc-importnative-cc-infonative-cc-librarynative-cc-memprof-profilenative-cc-objc-importnative-cc-objc-librarynative-cc-propeller-optimizenative-cc-shared-librarynative-cc-shared-library-hint-infonative-cc-shared-library-infonative-cc-testnative-cc-toolchainnative-cc-toolchain-suite--incompatible_autoload_externally# buildifier: disable=native-cc-binary, # buildifier: disable=native-cc-common, # buildifier: disable=native-cc-debug-package-info, # buildifier: disable=native-cc-fdo-prefetch-hints, # buildifier: disable=native-cc-fdo-profile, # buildifier: disable=native-cc-import, # buildifier: disable=native-cc-info, # buildifier: disable=native-cc-library, # buildifier: disable=native-cc-memprof-profile, # buildifier: disable=native-cc-objc-import, # buildifier: disable=native-cc-objc-library, # buildifier: disable=native-cc-propeller-optimize, # buildifier: disable=native-cc-shared-library, # buildifier: disable=native-cc-shared-library-hint-info, # buildifier: disable=native-cc-shared-library-info, # buildifier: disable=native-cc-test, # buildifier: disable=native-cc-toolchain, # buildifier: disable=native-cc-toolchain-suiteThe C++ build rules should be loaded from @rules_cc.
native-cc-proto--incompatible_autoload_externally# buildifier: disable=native-cc-protoThe cc_proto_library rule should be loaded from Starlark.
native-java-binary--incompatible_autoload_externally# buildifier: disable=native-java-binaryThe Java build rules should be loaded from Starlark.
native-java-common--incompatible_autoload_externally# buildifier: disable=native-java-commonThe Java build rules should be loaded from Starlark.
native-java-import--incompatible_autoload_externally# buildifier: disable=native-java-importThe Java build rules should be loaded from Starlark.
native-java-info--incompatible_autoload_externally# buildifier: disable=native-java-infoThe Java build rules should be loaded from Starlark.
native-java-library--incompatible_autoload_externally# buildifier: disable=native-java-libraryThe Java build rules should be loaded from Starlark.
native-java-lite-proto--incompatible_autoload_externally# buildifier: disable=native-java-lite-protoThe java_lite_proto_library rule should be loaded from Starlark.
native-java-package-config--incompatible_autoload_externally# buildifier: disable=native-java-package-configThe Java build rules should be loaded from Starlark.
native-java-plugin--incompatible_autoload_externally# buildifier: disable=native-java-pluginThe Java build rules should be loaded from Starlark.
native-java-plugin-info--incompatible_autoload_externally# buildifier: disable=native-java-plugin-infoThe Java build rules should be loaded from Starlark.
native-java-proto--incompatible_autoload_externally# buildifier: disable=native-java-protoThe java_proto_library rule should be loaded from Starlark.
native-java-runtime--incompatible_autoload_externally# buildifier: disable=native-java-runtimeThe Java build rules should be loaded from Starlark.
native-java-test--incompatible_autoload_externally# buildifier: disable=native-java-testThe Java build rules should be loaded from Starlark.
native-java-toolchain--incompatible_autoload_externally# buildifier: disable=native-java-toolchainThe Java build rules should be loaded from Starlark.
native.package() shouldn't be used in .bzl filesnative-package# buildifier: disable=native-packageIt's discouraged and will be disallowed to use native.package() in .bzl files. It can silently modify the semantics of a BUILD file and makes it hard to maintain.
native-proto--incompatible_autoload_externally# buildifier: disable=native-protoThe proto_library rule should be loaded from Starlark.
native-proto-common--incompatible_autoload_externally# buildifier: disable=native-proto-commonThe proto_common module should be loaded from Starlark.
native-proto-info--incompatible_autoload_externally# buildifier: disable=native-proto-infoThe ProtoInfo provider should be loaded from Starlark.
native-proto-lang-toolchain--incompatible_autoload_externally# buildifier: disable=native-proto-lang-toolchainThe proto_lang_toolchain rule should be loaded from Starlark.
native-proto-lang-toolchain-info--incompatible_autoload_externally# buildifier: disable=native-proto-lang-toolchain-infoThe ProtoLangToolchainInfo provider should be loaded from Starlark.
native-py--incompatible_load_python_rules_from_bzl# buildifier: disable=native-pyThe Python build rules should be loaded from Starlark.
Update: the plans for disabling native rules have been postponed, at the moment it's not required to load Starlark rules.
native-sh-binary# buildifier: disable=native-sh-binaryThe sh_binary build rules should be loaded from Starlark.
native-sh-library# buildifier: disable=native-sh-libraryThe sh_library build rules should be loaded from Starlark.
native-sh-test# buildifier: disable=native-sh-testThe sh_test build rules should be loaded from Starlark.
no-effect# buildifier: disable=no-effectThe statement has no effect. Consider removing it or storing its result in a variable.
out-of-order-load# buildifier: disable=out-of-order-loadObsolete; the warning has been implemented in the formatter and the fix is now automatically applied to all files (unless suppressed).
Load statements should be ordered by their first argument - extension file label. This makes it easier to developers to locate loads of interest and reduces chances for conflicts when performing large-scale automated refactoring.
When applying automated fixes, it's highly recommended to also use load-on-top fixes, since otherwise the relative order of a symbol load and its usage can change resulting in runtime error.
ctx.attr.dep.output_group is deprecatedoutput-group--incompatible_no_target_output_group# buildifier: disable=output-groupThe output_group field of a target is deprecated in favor of the OutputGroupInfo provider.
overly-nested-depset# buildifier: disable=overly-nested-depsetIf a depset is iteratively chained in a for loop, e.g. the following pattern is used:
for ...: x = depset(..., transitive = [..., x, ...])
this can result in an overly nested depset with a long chain of transitive elements. Such patterns can lead to performance problems, consider refactoring the code to create a flat list of transitive elements and call the depset constructor just once:
transitive = [] for ...: transitive += ... x = depset(..., transitive = transitive)
Or in simple cases you can use list comprehensions instead:
x = depset(..., transitive = [y.deps for y in ...])
For more information, read Bazel documentation about depsets and reducing the number of calls to depset.
PACKAGE_NAME is deprecatedpackage-name--incompatible_package_name_is_a_function# buildifier: disable=package-nameThe global variable PACKAGE_NAME is deprecated, please use native.package_name() instead.
package-on-top# buildifier: disable=package-on-topHere is a typical structure of a BUILD file:
load() statementspackage()Instantiating a rule and setting the package defaults later can be very confusing, and has been a source of bugs (tools and humans sometimes believe package applies to everything in a BUILD file). This might become an error in the future.
The linter allows the following to be before package():
load()package_group()licenses()positional-args# buildifier: disable=positional-argsAll macro and rule calls should use keyword args over positional arguments. Positional arguments can cause subtle errors if the order is switched or if an argument is removed. Keyword args also greatly improve readability. Additionally, positional arguments prevent migration from Legacy Macros to Symbolic Macros.
- my_macro("foo", "bar") + my_macro(name = "foo", env = "bar")
The linter allows the following functions to be called with positional arguments:
load()vardef()export_files()licenses()print()print() is a debug function and shouldn't be submittedprint# buildifier: disable=printUsing the print() function for warnings is discouraged: they are often spammy and non actionable, the people who see the warning are usually not the people who can fix the code to make the warning disappear, and the actual maintainers of the code may never see the warning.
provider should specify a list of fields and a documentationprovider-params# buildifier: disable=provider-paramsCalls to provider should specify a documentation string and a list of fields:
ServerAddressInfo = provider( "The address of an HTTP server. Fields are host (string) and port (int).", fields = ["host", "port"] )
Fields should also be documented when needed:
ServerAddressInfo = provider( "The address of an HTTP server.", fields = { "host": "string, e.g. 'example.com'", "port": "int, a TCP port number", } )
Note that specifying a list of fields is a breaking change. It is an error if a call to the provider uses undeclared fields. If you cannot declare the list of fields, you may explicitly set it to None (and explain why in a comment).
AllInfo = provider("This provider accepts any field.", fields = None) NoneInfo = provider("This provider cannot have fields.", fields = [])
See the documentation for providers.
redefined-variable# buildifier: disable=redefined-variableIn .bzl files, redefining a global variable is already forbidden. This helps both humans and tools reason about the code. For consistency, we want to bring this restriction also to BUILD files.
Rename one of the variables.
Note that the content of lists and dictionaries can still be modified. We will forbid reassignment, but not every side-effect.
REPOSITORY_NAME is deprecatedrepository-name--incompatible_package_name_is_a_function# buildifier: disable=repository-nameThe global variable REPOSITORY_NAME is deprecated, please use native.repository_name() instead.
return-value# buildifier: disable=return-valueSome but not all execution paths of a function return a value. Either there's an explicit empty return statement, or an implicit return in the end of a function. If it is intentional, make it explicit using return None. If you know certain parts of the code cannot be reached, add the statement fail("unreachable") to them.
rule-impl-return# buildifier: disable=rule-impl-returnReturning structs from rule implementation functions is deprecated, consider using providers or lists of providers instead.
same-origin-load# buildifier: disable=same-origin-loadObsolete; the warning has been implemented in the formatter and the fix is now automatically applied to all files except WORKSPACE files (unless suppressed).
load is used to import definitions in a BUILD file. If the same label is used for loading symbols more the ones, all such loads can be merged into a single one.
Merge all loads into a single one. For example,
load(":f.bzl", "s1") load(":f.bzl", "s2")
can be written more compactly as
load(":f.bzl", "s1", "s2")
skylark-commentskylark-docstring# buildifier: disable=skylark-comment, # buildifier: disable=skylark-docstringThe configuration language for Bazel is called “Starlark” now, the name “Skylark” is outdated and shouldn't be used.
string-iteration--incompatible_string_is_not_iterable# buildifier: disable=string-iterationIteration over strings often leads to confusion with iteration over a sequence of strings, therefore strings won't be recognized as sequences of 1-element strings (like in Python). Use string indexing and len instead:
my_string = "hello world" for i in range(len(my_string)): char = my_string[i] # do something with char
uninitialized# buildifier: disable=uninitializedThe local value can be not initialized at the time of execution. It may happen if it's initialized in one of the if-else clauses but not in all of them, or in a for-loop which can potentially be empty.
unnamed-macro# buildifier: disable=unnamed-macroBy convention all macro functions should have a keyword argument called name (even if they don't use it). This is important for tooling and automation.
A macro is a function that calls a rule (either directly or indirectly by calling other macros).
If this function is a helper function that's not supposed to be used outside of its file, please make it private (rename it so that the name starts with _), this will prevent loading the function from BUILD files and suppress the warning.
unreachable# buildifier: disable=unreachableThe statement is unreachable because it follows a return, break, continue, or fail() statement.
unsorted-dict-items# buildifier: disable=unsorted-dict-itemsDictionary items should be sorted lexicographically by their keys. This makes it easier to find the item of interest and reduces chances of conflicts when performing large-scale automated refactoring.
The order is affected by NamePriority dictionary passed using -tables or -add_tables flags.
If you want to preserve the original dictionary items order, you can disable the warning by adding a comment # @unsorted-dict-items to the dictionary expression or any of its enclosing expressions (binary, if etc). For example,
# @unsorted-dict-items d = { "b": "bvalue", "a": "avalue", }
will not be reported as an issue because the assignment operation that uses the dictionary with unsorted items has a comment disabling this warning.
unused-variable# buildifier: disable=unused-variableThis happens when a variable or function is set but not used in the file, e.g.
x = [1, 2]
The line can often be safely removed.
If you want to keep the variable, you can disable the warning by adding a comment # @unused.
x = [1, 2] # @unused # @unused def f( x, y, # @unused ): pass
If an unused variable is used for partially unpacking tuples, just prefix its name with an underscore to suppress the warning:
x, _y = foo() for _, (a, _b) in iterable: print(a + x)
The same applies for function arguments that are not used by design:
def foo(a, _b, *_args): return bar(a)
If a tuple is unpacked not in a for-loop and all variables are unused, it'll still trigger a warning, even if all variables are underscored:
_a, _b = pair _unused = 3