Skip to content

Commit 5d9f822

Browse files
authored
Merge pull request #238 from eclipse-score/dcalavrezo_clippy_lint
test: switch to rules_lint
2 parents e0a136e + 1b21dbb commit 5d9f822

File tree

27 files changed

+292
-562
lines changed

27 files changed

+292
-562
lines changed

.bazelrc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ build --@score_baselibs//score/mw/log/flags:KRemote_Logging=False
3131
common --extra_toolchains=@gcc_toolchain//:host_gcc_12
3232

3333
# Clippy linting (enabled by default)
34-
build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
35-
build --output_groups=+clippy_checks
36-
build --@rules_rust//rust/settings:clippy.toml=@score_rust_policies//clippy/strict:clippy.toml
34+
build --aspects=@score_rust_policies//clippy:linters.bzl%clippy_strict
35+
build --output_groups=+rules_lint_human
36+
build:lint --@aspect_rules_lint//lint:fail_on_violation=true
3737

3838
test --test_output=errors
3939

.github/workflows/check.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ jobs:
3636
toolchain: 1.90.0
3737
components: clippy, rustfmt
3838

39-
- name: Cargo Clippy
40-
run: |
41-
cargo clippy --all-targets --all-features
42-
43-
- name: Cargo Fmt
44-
run: |
45-
cargo fmt --check
46-
4739
- name: Cargo Build
4840
run: |
4941
cargo build

.github/workflows/clippy.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ jobs:
2525
bazel-clippy:
2626
uses: eclipse-score/cicd-workflows/.github/workflows/static-analysis.yml@main
2727
with:
28-
bazel-target: "build //:clippy"
28+
bazel-targets: "//src/rust/..."
29+
bazel-config: "lint"

BUILD

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
1313

14-
load("@rules_rust//rust:defs.bzl", "rust_clippy")
1514
load("@score_docs_as_code//:docs.bzl", "docs")
1615
load("@score_tooling//:defs.bzl", "cli_helper", "copyright_checker", "dash_license_checker", "rust_coverage_report", "setup_starpls", "use_format_targets")
1716
load("//:project_config.bzl", "PROJECT_CONFIG")
@@ -103,17 +102,6 @@ alias(
103102
# Add target for formatting checks
104103
use_format_targets()
105104

106-
rust_clippy(
107-
name = "clippy",
108-
testonly = True,
109-
tags = ["manual"],
110-
visibility = ["//visibility:public"],
111-
deps = [
112-
"//src/rust/rust_kvs",
113-
"//src/rust/rust_kvs_tool:kvs_tool",
114-
],
115-
)
116-
117105
alias(
118106
name = "kvs_cpp",
119107
actual = "//src/cpp/src:kvs_cpp",

MODULE.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use_repo(pip, "pip_score_venv_test")
4141
bazel_dep(name = "rules_rust", version = "0.61.0")
4242

4343
# Shared Rust policies (Clippy config, etc.), overridden locally during development.
44-
bazel_dep(name = "score_rust_policies", version = "0.0.2", dev_dependency = True)
44+
bazel_dep(name = "score_rust_policies", version = "0.0.4", dev_dependency = True)
4545

4646
# bazel cc rules
4747
bazel_dep(name = "rules_cc", version = "0.1.2")
@@ -90,7 +90,7 @@ bazel_dep(name = "score_python_basics", version = "0.3.4")
9090
bazel_dep(name = "score_tooling", version = "1.1.0")
9191

9292
# ToDo: implicit dependencies for score_tooling, but needed directly here??
93-
bazel_dep(name = "aspect_rules_lint", version = "1.10.2")
93+
bazel_dep(name = "aspect_rules_lint", version = "2.0.0")
9494
bazel_dep(name = "buildifier_prebuilt", version = "8.2.0.2")
9595

9696
## temporary overrides / tools

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ bazel test <TARGET_NAME>
118118

119119
## Clippy
120120

121-
- Clippy runs by default via `.bazelrc` on all Rust targets (Rust tests are tagged `no-clippy`).
122-
- Use `bazel build //:clippy` if you want an explicit lint-only target, or `bazel build //src/rust/...` while building.
121+
- Clippy runs by default via `.bazelrc` when building Rust targets (rules_lint aspect).
122+
- Use `bazel build //src/rust/...` (or any Rust target pattern) while developing.
123+
- Use `bazel build --config=lint //src/rust/...` to enable lint config, including `--@aspect_rules_lint//lint:fail_on_violation=true`.
123124
- The Clippy config comes from `@score_rust_policies//clippy/strict:clippy.toml`.
124125

125126
## Cargo-based operations

rustfmt.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# `rustfmt` should not be used with local configuration.
2+
# Use Bazel target for formatting.
3+
# E.g., `bazel run //:format.fix_Rust_with_rustfmt`
4+
DO_NOT_USE_LOCAL_RUSTFMT_TOML = false

src/rust/rust_kvs/examples/basic.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ fn main() -> Result<(), ErrorCode> {
3030
{
3131
// Build KVS instance for given instance ID and temporary directory.
3232
let builder = KvsBuilder::new(instance_id).backend(Box::new(
33-
JsonBackendBuilder::new()
34-
.working_dir(dir_path.clone())
35-
.build(),
33+
JsonBackendBuilder::new().working_dir(dir_path.clone()).build(),
3634
));
3735
let kvs = builder.build()?;
3836

@@ -43,11 +41,7 @@ fn main() -> Result<(), ErrorCode> {
4341
kvs.set_value("null", ())?;
4442
kvs.set_value(
4543
"array",
46-
vec![
47-
KvsValue::from(456.0),
48-
false.into(),
49-
"Second".to_string().into(),
50-
],
44+
vec![KvsValue::from(456.0), false.into(), "Second".to_string().into()],
5145
)?;
5246
kvs.set_value(
5347
"object",
@@ -58,11 +52,7 @@ fn main() -> Result<(), ErrorCode> {
5852
("sub-null".into(), ().into()),
5953
(
6054
"sub-array".into(),
61-
KvsValue::from(vec![
62-
KvsValue::from(1246.0),
63-
false.into(),
64-
"Fourth".to_string().into(),
65-
]),
55+
KvsValue::from(vec![KvsValue::from(1246.0), false.into(), "Fourth".to_string().into()]),
6656
),
6757
]),
6858
)?;
@@ -75,9 +65,8 @@ fn main() -> Result<(), ErrorCode> {
7565

7666
{
7767
// Build KVS instance for given instance ID and temporary directory.
78-
let builder = KvsBuilder::new(instance_id).backend(Box::new(
79-
JsonBackendBuilder::new().working_dir(dir_path).build(),
80-
));
68+
let builder =
69+
KvsBuilder::new(instance_id).backend(Box::new(JsonBackendBuilder::new().working_dir(dir_path).build()));
8170
let kvs = builder.build()?;
8271

8372
// `get_value` usage - print all existing keys with their values.

src/rust/rust_kvs/examples/custom_types.rs

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ impl KvsDeserialize for Point {
4444
fn from_kvs(kvs_value: &KvsValue) -> Result<Self, Self::Error> {
4545
if let KvsValue::Object(map) = kvs_value {
4646
Ok(Point {
47-
x: f64::from_kvs(map.get("x").ok_or(ErrorCode::DeserializationFailed(
48-
"Field not found".to_string(),
49-
))?)?,
50-
y: f64::from_kvs(map.get("y").ok_or(ErrorCode::DeserializationFailed(
51-
"Field not found".to_string(),
52-
))?)?,
47+
x: f64::from_kvs(
48+
map.get("x")
49+
.ok_or(ErrorCode::DeserializationFailed("Field not found".to_string()))?,
50+
)?,
51+
y: f64::from_kvs(
52+
map.get("y")
53+
.ok_or(ErrorCode::DeserializationFailed("Field not found".to_string()))?,
54+
)?,
5355
})
5456
} else {
5557
Err(ErrorCode::DeserializationFailed(
@@ -145,42 +147,54 @@ impl KvsDeserialize for Example {
145147
fn from_kvs(kvs_value: &KvsValue) -> Result<Self, Self::Error> {
146148
if let KvsValue::Object(map) = kvs_value {
147149
Ok(Example {
148-
i32: i32::from_kvs(map.get("i32").ok_or(ErrorCode::DeserializationFailed(
149-
"Field not found".to_string(),
150-
))?)?,
151-
u32: u32::from_kvs(map.get("u32").ok_or(ErrorCode::DeserializationFailed(
152-
"Field not found".to_string(),
153-
))?)?,
154-
i64: i64::from_kvs(map.get("i64").ok_or(ErrorCode::DeserializationFailed(
155-
"Field not found".to_string(),
156-
))?)?,
157-
u64: u64::from_kvs(map.get("u64").ok_or(ErrorCode::DeserializationFailed(
158-
"Field not found".to_string(),
159-
))?)?,
160-
f64: f64::from_kvs(map.get("f64").ok_or(ErrorCode::DeserializationFailed(
161-
"Field not found".to_string(),
162-
))?)?,
163-
bool: bool::from_kvs(map.get("bool").ok_or(ErrorCode::DeserializationFailed(
164-
"Field not found".to_string(),
165-
))?)?,
166-
string: String::from_kvs(map.get("string").ok_or(
167-
ErrorCode::DeserializationFailed("Field not found".to_string()),
168-
)?)?,
169-
vec: Vec::from_kvs(map.get("vec").ok_or(ErrorCode::DeserializationFailed(
170-
"Field not found".to_string(),
171-
))?)?,
172-
object: KvsMap::from_kvs(map.get("object").ok_or(
173-
ErrorCode::DeserializationFailed("Field not found".to_string()),
174-
)?)?,
175-
u8: u8::from_kvs(map.get("u8").ok_or(ErrorCode::DeserializationFailed(
176-
"Field not found".to_string(),
177-
))?)?,
178-
nested: Point::from_kvs(map.get("nested").ok_or(
179-
ErrorCode::DeserializationFailed("Field not found".to_string()),
180-
)?)?,
181-
ip: IpAddrWrapper::from_kvs(map.get("ip").ok_or(
182-
ErrorCode::DeserializationFailed("Field not found".to_string()),
183-
)?)?
150+
i32: i32::from_kvs(
151+
map.get("i32")
152+
.ok_or(ErrorCode::DeserializationFailed("Field not found".to_string()))?,
153+
)?,
154+
u32: u32::from_kvs(
155+
map.get("u32")
156+
.ok_or(ErrorCode::DeserializationFailed("Field not found".to_string()))?,
157+
)?,
158+
i64: i64::from_kvs(
159+
map.get("i64")
160+
.ok_or(ErrorCode::DeserializationFailed("Field not found".to_string()))?,
161+
)?,
162+
u64: u64::from_kvs(
163+
map.get("u64")
164+
.ok_or(ErrorCode::DeserializationFailed("Field not found".to_string()))?,
165+
)?,
166+
f64: f64::from_kvs(
167+
map.get("f64")
168+
.ok_or(ErrorCode::DeserializationFailed("Field not found".to_string()))?,
169+
)?,
170+
bool: bool::from_kvs(
171+
map.get("bool")
172+
.ok_or(ErrorCode::DeserializationFailed("Field not found".to_string()))?,
173+
)?,
174+
string: String::from_kvs(
175+
map.get("string")
176+
.ok_or(ErrorCode::DeserializationFailed("Field not found".to_string()))?,
177+
)?,
178+
vec: Vec::from_kvs(
179+
map.get("vec")
180+
.ok_or(ErrorCode::DeserializationFailed("Field not found".to_string()))?,
181+
)?,
182+
object: KvsMap::from_kvs(
183+
map.get("object")
184+
.ok_or(ErrorCode::DeserializationFailed("Field not found".to_string()))?,
185+
)?,
186+
u8: u8::from_kvs(
187+
map.get("u8")
188+
.ok_or(ErrorCode::DeserializationFailed("Field not found".to_string()))?,
189+
)?,
190+
nested: Point::from_kvs(
191+
map.get("nested")
192+
.ok_or(ErrorCode::DeserializationFailed("Field not found".to_string()))?,
193+
)?,
194+
ip: IpAddrWrapper::from_kvs(
195+
map.get("ip")
196+
.ok_or(ErrorCode::DeserializationFailed("Field not found".to_string()))?,
197+
)?
184198
.0,
185199
})
186200
} else {
@@ -205,18 +219,11 @@ fn main() -> Result<(), ErrorCode> {
205219
f64: 444.4,
206220
bool: true,
207221
string: "example".to_string(),
208-
vec: vec![
209-
KvsValue::from("one"),
210-
KvsValue::from("two"),
211-
KvsValue::from("three"),
212-
],
222+
vec: vec![KvsValue::from("one"), KvsValue::from("two"), KvsValue::from("three")],
213223
object: KvsMap::from([
214224
("first".to_string(), KvsValue::from(-123i32)),
215225
("second".to_string(), KvsValue::from(321u32)),
216-
(
217-
"third".to_string(),
218-
KvsValue::String("map_example".to_string()),
219-
),
226+
("third".to_string(), KvsValue::String("map_example".to_string())),
220227
]),
221228
u8: 200,
222229
nested: Point { x: 432.1, y: 654.3 },
@@ -231,9 +238,7 @@ fn main() -> Result<(), ErrorCode> {
231238
let kvs = KvsBuilder::new(InstanceId(0))
232239
.kvs_load(KvsLoad::Ignored)
233240
.defaults(KvsDefaults::Ignored)
234-
.backend(Box::new(
235-
JsonBackendBuilder::new().working_dir(dir_path).build(),
236-
))
241+
.backend(Box::new(JsonBackendBuilder::new().working_dir(dir_path).build()))
237242
.build()?;
238243

239244
// Serialize and set object.

src/rust/rust_kvs/examples/defaults.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ fn main() -> Result<(), ErrorCode> {
6161
// Build KVS instance for given instance ID and temporary directory.
6262
// `defaults` is set to `KvsDefaults::Required` - defaults are required.
6363
let builder = KvsBuilder::new(instance_id)
64-
.backend(Box::new(
65-
JsonBackendBuilder::new().working_dir(dir_path).build(),
66-
))
64+
.backend(Box::new(JsonBackendBuilder::new().working_dir(dir_path).build()))
6765
.defaults(KvsDefaults::Required);
6866
let kvs = builder.build()?;
6967

0 commit comments

Comments
 (0)