Skip to content

Commit 6a5eecc

Browse files
chore(vdev): better formatting with nightly features (#23734)
* chore(vdev): better formatting with nightly features * pass all and add to contributing guide * currently we only want imports_granularity * contributing * PR template improvements * license building updates * Update .github/PULL_REQUEST_TEMPLATE.md Co-authored-by: Thomas <[email protected]> --------- Co-authored-by: Thomas <[email protected]>
1 parent 697b64d commit 6a5eecc

File tree

7 files changed

+32
-16
lines changed

7 files changed

+32
-16
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ This should help the reviewers give feedback faster and with higher quality. -->
3737
- Some CI checks run only after we manually approve them.
3838
- We recommend adding a `pre-push` hook, please see [this template](https://github.com/vectordotdev/vector/blob/master/CONTRIBUTING.md#Pre-push).
3939
- Alternatively, we recommend running the following locally before pushing to the remote branch:
40-
- `cargo fmt --all`
41-
- `cargo clippy --workspace --all-targets -- -D warnings`
42-
- `cargo nextest run --workspace` (alternatively, you can run `cargo test --all`)
40+
- `make fmt`
41+
- `make check-clippy` (if there are failures it's possible some of them can be fixed with `make clippy-fix`)
42+
- `make test`
4343
- After a review is requested, please avoid force pushes to help us review incrementally.
4444
- Feel free to push as many commits as you want. They will be squashed into one before merging.
4545
- For example, you can run `git merge origin master` and `git push`.
4646
- If this PR introduces changes Vector dependencies (modifies `Cargo.lock`), please
47-
run `cargo vdev build licenses` to regenerate the [license inventory](https://github.com/vectordotdev/vrl/blob/main/LICENSE-3rdparty.csv) and commit the changes (if any). More details [here](https://crates.io/crates/dd-rust-license-tool).
47+
run `make build-licenses` to regenerate the [license inventory](https://github.com/vectordotdev/vrl/blob/main/LICENSE-3rdparty.csv) and commit the changes (if any). More details [here](https://crates.io/crates/dd-rust-license-tool).
4848

4949

5050
<!--

.rustfmt.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ newline_style = "unix"
33
reorder_imports = true
44

55
# Nightly only features
6-
# unstable_features = true
7-
# imports_granularity = "Crate"
6+
unstable_features = true
7+
8+
# See https://github.com/rust-lang/rustfmt/issues/4991
9+
imports_granularity = "Crate"
10+
11+
# See https://github.com/rust-lang/rustfmt/issues/5083
812
# group_imports = "StdExternalCrate"
13+
14+
# See https://github.com/rust-lang/rustfmt/issues/3346
915
# indent_style = "Block"

CONTRIBUTING.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ You can use the following as a starting point:
130130
```shell
131131
#!/bin/sh
132132
set -e
133+
134+
echo "Format code"
135+
136+
make fmt
137+
133138
echo "Running pre-push checks..."
134139

135140
# We recommend always running all the following checks.
@@ -298,8 +303,8 @@ cd rust-doc && make docs
298303

299304
```sh
300305
cargo install dd-rust-license-tool --locked
301-
dd-rust-license-tool write
302-
git commit -am "dd-rust-license-tool write"
306+
make build-licenses
307+
git commit -am "updated LICENSE-3rdparty.csv"
303308
git push
304309
```
305310

@@ -312,7 +317,7 @@ When deprecating functionality in Vector, see [DEPRECATION.md](docs/DEPRECATION.
312317
When adding, modifying, or removing a dependency in Vector you may find that you need to update the
313318
inventory of third-party licenses maintained in `LICENSE-3rdparty.csv`. This file is generated using
314319
[dd-rust-license-tool](https://github.com/DataDog/rust-license-tool.git) and can be updated using
315-
`cargo vdev build licenses`.
320+
`make build-licenses`.
316321

317322
## Next steps
318323

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,10 +670,6 @@ compile-vrl-wasm: ## Compile VRL crates to WASM target
670670
clean: environment-clean ## Clean everything
671671
cargo clean
672672

673-
.PHONY: fmt
674-
fmt: ## Format code
675-
${MAYBE_ENVIRONMENT_EXEC} cargo fmt
676-
677673
.PHONY: generate-kubernetes-manifests
678674
generate-kubernetes-manifests: ## Generate Kubernetes manifests from latest Helm chart
679675
cargo vdev build manifests
@@ -709,3 +705,11 @@ ci-generate-publish-metadata: ## Generates the necessary metadata required for b
709705
.PHONY: clippy-fix
710706
clippy-fix:
711707
${MAYBE_ENVIRONMENT_EXEC} cargo vdev check rust --fix
708+
709+
.PHONY: fmt
710+
fmt:
711+
${MAYBE_ENVIRONMENT_EXEC} cargo vdev fmt
712+
713+
.PHONY: build-licenses
714+
build-licenses:
715+
${MAYBE_ENVIRONMENT_EXEC} cargo vdev build licenses

docs/DEVELOPING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Loosely, you'll need the following:
125125
- **To run `make test`:** Install [`cargo-nextest`](https://nexte.st/)
126126
- **To run integration tests:** Have `docker` available, or a real live version of that service. (Use `AUTOSPAWN=false`)
127127
- **To run `make check-component-features`:** Have `remarshal` installed.
128-
- **To run `make check-licenses` or `cargo vdev build licenses`:** Have `dd-rust-license-tool` [installed](https://github.com/DataDog/rust-license-tool).
128+
- **To run `make check-licenses` or `make build-licenses`:** Have `dd-rust-license-tool` [installed](https://github.com/DataDog/rust-license-tool).
129129
- **To run `make generate-component-docs`:** Have `cue` [installed](https://cuelang.org/docs/install/).
130130

131131
If you find yourself needing to run something inside the Docker environment described above, that's totally fine, they won't collide or hurt each other. In this case, you'd just run `make environment-generate`.

vdev/src/commands/check/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ pub struct Cli {}
1010
impl Cli {
1111
pub fn exec(self) -> Result<()> {
1212
app::exec::<&str>("scripts/check-style.sh", [], true)?;
13-
app::exec("cargo", ["fmt", "--", "--check"], true)
13+
app::exec("cargo", ["fmt", "--", "-q", "--check"], true)
1414
}
1515
}

vdev/src/commands/fmt.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub struct Cli {}
1010
impl Cli {
1111
pub fn exec(self) -> Result<()> {
1212
app::exec("scripts/check-style.sh", ["--fix"], true)?;
13-
app::exec("cargo", ["fmt"], true)
13+
// We are using nightly features in `.rustfmt.toml
14+
app::exec("cargo", ["+nightly", "fmt", "--all"], true)
1415
}
1516
}

0 commit comments

Comments
 (0)