Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: clippy
on:
merge_group:
pull_request:

permissions:
contents: read

jobs:
check_clippy_configs:
runs-on: ubuntu-latest
name: check clippy configs
steps:
- name: checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: install rustup
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup-init.sh
sh rustup-init.sh -y --default-toolchain none
rustup target add x86_64-unknown-linux-gnu
- name: Check clippy configs all match
run: cargo run --manifest-path ci/Cargo.toml -- clippy-config-check


run_clippy:
runs-on: ubuntu-latest
name: clippy ${{ matrix.package }}
strategy:
fail-fast: false
matrix:
package:
- . # rustfmt
- check_diff
- ci
- config_proc_macro
steps:
- name: checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: install rustup
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup-init.sh
sh rustup-init.sh -y --default-toolchain none
- name: clippy
run: cargo clippy --manifest-path ${{ matrix.package }}/Cargo.toml

14 changes: 14 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,17 @@ insta = { version = "1.48.0", features = ["filters"] }
[package.metadata.rust-analyzer]
# This package uses #[feature(rustc_private)]
rustc_private = true

[lints.clippy]
# allow all rules with a low priority ..
all = { level = "allow", priority = -1 }
# so we can pick out an exact subset of rules to deny
correctness = "deny"
char_lit_as_u8 = "deny"
four_forward_slashes = "deny"
non_minimal_cfg = "deny"
print_literal = "deny"
same_item_push = "deny"
single_char_add_str = "deny"
to_string_in_format_args = "deny"
unconditional_recursion = "deny"
20 changes: 20 additions & 0 deletions Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ assistance when participating in `rust-lang/rustfmt`.

[LLM usage policy]: https://forge.rust-lang.org/policies/llm-usage.html

## Linting

This project supports linting via
[`clippy`](https://doc.rust-lang.org/stable/clippy/index.html). You can either
run it directly, or use an integration through your editor.

```
# lint rustfmt-nightly (the package at the root of this repo)
cargo clippy
```

To Lint a package outside of the root one you will need to do one of:

```
# pass the manifest path
cargo clippy --manifest-path ./config_proc_macro/Config.toml
# or run the command from within the package
cd ./config_proc_macro
cargo clippy
```

## Test and file issues

Expand Down
150 changes: 150 additions & 0 deletions ci/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions ci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,21 @@ edition = "2024"
publish = false

[workspace]

[dependencies]
itertools = "0.15.0"
toml = "1.1.5"

[lints.clippy]
# allow all rules with a low priority ..
all = { level = "allow", priority = -1 }
# so we can pick out an exact subset of rules to deny
correctness = "deny"
char_lit_as_u8 = "deny"
four_forward_slashes = "deny"
non_minimal_cfg = "deny"
print_literal = "deny"
same_item_push = "deny"
single_char_add_str = "deny"
to_string_in_format_args = "deny"
unconditional_recursion = "deny"
40 changes: 40 additions & 0 deletions ci/src/clippy_config_check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use std::fs;

use itertools::Itertools;

const CARGO_TOMLS: &[&'static str] = &[
"Cargo.toml",
"ci/Cargo.toml",
"config_proc_macro/Cargo.toml",
];

pub(crate) fn runner() -> Result<(), String> {
for (first, second) in CARGO_TOMLS.iter().tuple_windows() {
let first_table = parse_to_toml(&first)?;
let second_table = parse_to_toml(&second)?;
assert_eq!(
get_lints(first, &first_table)?,
get_lints(second, &second_table)?,
"Clippy configs do not match between {} and {}",
first,
second,
);
}
Ok(())
}

fn parse_to_toml(path: &str) -> Result<toml::Table, String> {
let toml_str = fs::read_to_string(path).map_err(|e| format!("reading {}: {}", path, e))?;
toml_str
.parse::<toml::Table>()
.map_err(|e| format!("parsing {} as TOML: {}", path, e))
}

fn get_lints<'a>(path: &str, toml: &'a toml::Table) -> Result<&'a toml::Value, String> {
toml.get("lints")
.ok_or(format!("{} is missing key {}", path, "lints"))
.and_then(|t| {
t.get("clippy")
.ok_or(format!("{} is missing key {}", path, "lints.clippy"))
})
}
8 changes: 6 additions & 2 deletions ci/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod build_and_test;
mod clippy_config_check;
mod common;
mod integration;

Expand All @@ -7,11 +8,14 @@ fn main() {
if let Err(error) = match args.next().as_deref() {
Some("integration") => integration::runner(&mut args),
Some("build-and-test") => build_and_test::runner(),
Some("clippy-config-check") => clippy_config_check::runner(),
Some(arg) => Err(format!(
"Expected `integration` or `build-and-test` as first argument, found {arg:?}"
"Expected `integration`, `build-and-test`, or `clippy-config-check` \
as first argument, found {arg:?}"
)),
None => Err(
"Expected `integration` or `build-and-test` as first argument, found nothing"
"Expected `integration`, `build-and-test`, or `clippy-config-check` \
as first argument, found nothing"
.to_string(),
),
} {
Expand Down
14 changes: 14 additions & 0 deletions config_proc_macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,17 @@ serde = { version = "1.0.160", features = ["derive"] }
[features]
default = []
debug-with-rustfmt = []

[lints.clippy]
# allow all rules with a low priority ..
all = { level = "allow", priority = -1 }
# so we can pick out an exact subset of rules to deny
correctness = "deny"
char_lit_as_u8 = "deny"
four_forward_slashes = "deny"
non_minimal_cfg = "deny"
print_literal = "deny"
same_item_push = "deny"
single_char_add_str = "deny"
to_string_in_format_args = "deny"
unconditional_recursion = "deny"