mirror of https://github.com/bazelbuild/rules_rust
Added more "ignore" tags to rustfmt and clippy rules. (#1400)
* Added more "ignore" tags to rustfmt rules. * Updated "ignore" tags for clippy rules. * Regenerate documentation * Update rust/private/clippy.bzl Co-authored-by: Daniel Wagner-Hall <dawagner@gmail.com> Co-authored-by: Daniel Wagner-Hall <dawagner@gmail.com>
This commit is contained in:
parent
53ad14eead
commit
30e68b49be
|
@ -1938,8 +1938,8 @@ used at runtime.
|
|||
[cs]: https://rust-lang.github.io/rustfmt/
|
||||
|
||||
This aspect is executed on any target which provides the `CrateInfo` provider. However
|
||||
users may tag a target with `norustfmt` to have it skipped. Additionally, generated
|
||||
source files are also ignored by this aspect.
|
||||
users may tag a target with `no-rustfmt` or `no-format` to have it skipped. Additionally,
|
||||
generated source files are also ignored by this aspect.
|
||||
|
||||
|
||||
**ASPECT ATTRIBUTES**
|
||||
|
|
|
@ -27,7 +27,7 @@ build --output_groups=+clippy_checks
|
|||
|
||||
This will enable clippy on all [Rust targets](./defs.md).
|
||||
|
||||
Note that targets tagged with `noclippy` will not perform clippy checks
|
||||
Note that targets tagged with `no-clippy` will not perform clippy checks
|
||||
|
||||
To use a local clippy.toml, add the following flag to your `.bazelrc`. Note that due to
|
||||
the upstream implementation of clippy, this file must be named either `.clippy.toml` or
|
||||
|
|
|
@ -21,7 +21,7 @@ build --output_groups=+clippy_checks
|
|||
|
||||
This will enable clippy on all [Rust targets](./defs.md).
|
||||
|
||||
Note that targets tagged with `noclippy` will not perform clippy checks
|
||||
Note that targets tagged with `no-clippy` will not perform clippy checks
|
||||
|
||||
To use a local clippy.toml, add the following flag to your `.bazelrc`. Note that due to
|
||||
the upstream implementation of clippy, this file must be named either `.clippy.toml` or
|
||||
|
|
|
@ -86,8 +86,8 @@ used at runtime.
|
|||
[cs]: https://rust-lang.github.io/rustfmt/
|
||||
|
||||
This aspect is executed on any target which provides the `CrateInfo` provider. However
|
||||
users may tag a target with `norustfmt` to have it skipped. Additionally, generated
|
||||
source files are also ignored by this aspect.
|
||||
users may tag a target with `no-rustfmt` or `no-format` to have it skipped. Additionally,
|
||||
generated source files are also ignored by this aspect.
|
||||
|
||||
|
||||
**ASPECT ATTRIBUTES**
|
||||
|
|
|
@ -60,9 +60,16 @@ def _get_clippy_ready_crate_info(target, aspect_ctx):
|
|||
if target.label.workspace_root.startswith("external"):
|
||||
return None
|
||||
|
||||
# Targets annotated with `noclippy` will not be formatted
|
||||
if aspect_ctx and "noclippy" in aspect_ctx.rule.attr.tags:
|
||||
return None
|
||||
# Targets with specific tags will not be formatted
|
||||
if aspect_ctx:
|
||||
ignore_tags = [
|
||||
"noclippy",
|
||||
"no-clippy",
|
||||
]
|
||||
|
||||
for tag in ignore_tags:
|
||||
if tag in aspect_ctx.rule.attr.tags:
|
||||
return None
|
||||
|
||||
# Obviously ignore any targets that don't contain `CrateInfo`
|
||||
if rust_common.crate_info not in target:
|
||||
|
|
|
@ -20,9 +20,17 @@ def _find_rustfmtable_srcs(target, aspect_ctx = None):
|
|||
if target.label.workspace_root.startswith("external"):
|
||||
return []
|
||||
|
||||
# Targets annotated with `norustfmt` will not be formatted
|
||||
if aspect_ctx and "norustfmt" in aspect_ctx.rule.attr.tags:
|
||||
return []
|
||||
if aspect_ctx:
|
||||
# Targets with specifc tags will not be formatted
|
||||
ignore_tags = [
|
||||
"no-format",
|
||||
"no-rustfmt",
|
||||
"norustfmt",
|
||||
]
|
||||
|
||||
for tag in ignore_tags:
|
||||
if tag in aspect_ctx.rule.attr.tags:
|
||||
return []
|
||||
|
||||
crate_info = target[rust_common.crate_info]
|
||||
|
||||
|
@ -110,8 +118,8 @@ used at runtime.
|
|||
[cs]: https://rust-lang.github.io/rustfmt/
|
||||
|
||||
This aspect is executed on any target which provides the `CrateInfo` provider. However
|
||||
users may tag a target with `norustfmt` to have it skipped. Additionally, generated
|
||||
source files are also ignored by this aspect.
|
||||
users may tag a target with `no-rustfmt` or `no-format` to have it skipped. Additionally,
|
||||
generated source files are also ignored by this aspect.
|
||||
""",
|
||||
attrs = {
|
||||
"_config": attr.label(
|
||||
|
|
|
@ -78,7 +78,7 @@ fn edition_query(bazel_bin: &Path, edition: &str, scope: &str, current_dir: &Pat
|
|||
// Except for targets tagged with `norustfmt`.
|
||||
// And except for targets with a populated `crate` attribute since `crate` defines edition for this target
|
||||
format!(
|
||||
r#"let scope = set({scope}) in filter("^//.*\.rs$", kind("source file", deps(attr(edition, "{edition}", $scope) except attr(tags, "(^\[|, )norustfmt(, |\]$)", $scope) + attr(crate, ".*", $scope), 1)))"#,
|
||||
r#"let scope = set({scope}) in filter("^//.*\.rs$", kind("source file", deps(attr(edition, "{edition}", $scope) except attr(tags, "(^\[|, )(no-format|no-rustfmt|norustfmt)(, |\]$)", $scope) + attr(crate, ".*", $scope), 1)))"#,
|
||||
edition = edition,
|
||||
scope = scope,
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue