Skip to content

Commit 163d7bb

Browse files
committed
ci: add dylint check using perfectionist
Wire up the `perfectionist` dylint library so its lints run alongside the existing fmt and clippy checks. The library is referenced via git in `dylint.toml`, pinned to the commit that matches the published `0.0.0-rc.0` release on crates.io; `cargo-dylint` does not currently support registry sources. `test.sh` gains a `DYLINT` toggle (default `false`) that runs `cargo dylint --all -- --all-features --all-targets` once, outside the per-feature `unit` loop, since the lints inspect source style and a single `--all-features` pass already covers conditional code. CI runs this through a dedicated `dylint.yaml` workflow that installs `cargo-dylint` and `dylint-link`, matching the project's convention of one workflow per concern.
1 parent 626e047 commit 163d7bb

8 files changed

Lines changed: 88 additions & 13 deletions

File tree

.github/copilot-instructions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Read and follow the CONTRIBUTING.md file in this repository for all code style c
1717
- Minimize `unwrap()` in non-test code. Use proper error handling instead.
1818
- Prefer `#[cfg_attr(..., ignore = "reason")]` over `#[cfg(...)]` when skipping tests. Use `#[cfg]` on tests only when the code cannot compile under the condition, such as when it references types or functions that do not exist on other platforms.
1919
- A unit-test module may sit inline as `mod tests { ... }` when it is short. Once it grows long enough to noticeably extend the parent, move it to an external file and declare the module with `#[cfg(test)] mod tests;` at the end of the parent. The external file lives at `src/foo/tests.rs` for a parent `src/foo.rs`, and at `src/foo/bar/tests.rs` for a parent `src/foo/bar.rs`. Use this layout even when the parent has no other submodules.
20-
- Install the toolchain before running tests: `rustup toolchain install "$(< rust-toolchain)" && rustup component add --toolchain "$(< rust-toolchain)" rustfmt clippy`.
20+
- Install the toolchain before running tests: `rustup toolchain install "$(< rust-toolchain)" && rustup component add --toolchain "$(< rust-toolchain)" rustfmt clippy`. To run the dylint checks (`DYLINT=true`), additionally install `cargo-dylint` and `dylint-link` with `cargo install cargo-dylint dylint-link`.
2121
- When you change CLI arguments, help text, or anything that affects command-line output, run `./generate-completions.sh` to regenerate the shell completion files, the help text files, `USAGE.md`, and the man page. **Do not attempt to regenerate these files manually.** Always use the script.
22-
- Validate changes with `FMT=true LINT=true BUILD=true TEST=true DOC=true ./test.sh`. When a test fails with a hint about `TEST_SKIP`, follow the hint and rerun with the suggested variable. When a sync test fails, read its error message and run the exact command it reports.
23-
- **Always run the full test suite** (`FMT=true LINT=true BUILD=true TEST=true DOC=true ./test.sh`) before every commit. This rule applies to all changes, including documentation changes, comment edits, config changes, and refactors. The test suite checks formatting, linting, building, tests, and docs across multiple feature combinations, and any kind of change can break any of these checks.
22+
- Validate changes with `FMT=true LINT=true BUILD=true TEST=true DOC=true DYLINT=true ./test.sh`. When a test fails with a hint about `TEST_SKIP`, follow the hint and rerun with the suggested variable. When a sync test fails, read its error message and run the exact command it reports.
23+
- **Always run the full test suite** (`FMT=true LINT=true BUILD=true TEST=true DOC=true DYLINT=true ./test.sh`) before every commit. This rule applies to all changes, including documentation changes, comment edits, config changes, and refactors. The test suite checks formatting, linting, building, tests, and docs across multiple feature combinations, and any kind of change can break any of these checks.
2424
- When the user provides a diff to apply, run `git apply` rather than interpreting each hunk manually. When a diff is provided for context or discussion, respond accordingly.

.github/workflows/dylint.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Dylint
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
dylint_check:
9+
name: Dylint
10+
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v6
15+
16+
- name: Cache
17+
uses: actions/cache@v5
18+
timeout-minutes: 2
19+
continue-on-error: true
20+
with:
21+
path: |
22+
~/.cargo
23+
~/.dylint_drivers
24+
target
25+
key: ${{ github.job }}-${{ runner.os }}-${{ hashFiles('rust-toolchain') }}-${{ hashFiles('dylint.toml') }}-${{ hashFiles('**/Cargo.lock') }}
26+
restore-keys: |
27+
${{ github.job }}-${{ runner.os }}-${{ hashFiles('rust-toolchain') }}-${{ hashFiles('dylint.toml') }}-${{ hashFiles('**/Cargo.lock') }}
28+
${{ github.job }}-${{ runner.os }}-${{ hashFiles('rust-toolchain') }}-${{ hashFiles('dylint.toml') }}-
29+
${{ github.job }}-${{ runner.os }}-${{ hashFiles('rust-toolchain') }}-
30+
31+
- name: Install Rust
32+
shell: bash
33+
run: |
34+
installer=$(mktemp -d)/install-rustup
35+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > $installer
36+
bash $installer --default-toolchain $(cat rust-toolchain) -y
37+
38+
- name: Install dylint tooling
39+
shell: bash
40+
run: cargo install cargo-dylint dylint-link
41+
42+
- name: Run dylint
43+
shell: bash
44+
env:
45+
FMT: 'false'
46+
LINT: 'false'
47+
DOC: 'false'
48+
BUILD: 'false'
49+
TEST: 'false'
50+
DYLINT: 'true'
51+
run: ./test.sh
52+
53+
- name: Clean workspace artifacts before cache
54+
if: always()
55+
continue-on-error: true
56+
shell: bash
57+
run: cargo clean --workspace

AGENTS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Read and follow the CONTRIBUTING.md file in this repository for all code style c
1717
- Minimize `unwrap()` in non-test code. Use proper error handling instead.
1818
- Prefer `#[cfg_attr(..., ignore = "reason")]` over `#[cfg(...)]` when skipping tests. Use `#[cfg]` on tests only when the code cannot compile under the condition, such as when it references types or functions that do not exist on other platforms.
1919
- A unit-test module may sit inline as `mod tests { ... }` when it is short. Once it grows long enough to noticeably extend the parent, move it to an external file and declare the module with `#[cfg(test)] mod tests;` at the end of the parent. The external file lives at `src/foo/tests.rs` for a parent `src/foo.rs`, and at `src/foo/bar/tests.rs` for a parent `src/foo/bar.rs`. Use this layout even when the parent has no other submodules.
20-
- Install the toolchain before running tests: `rustup toolchain install "$(< rust-toolchain)" && rustup component add --toolchain "$(< rust-toolchain)" rustfmt clippy`.
20+
- Install the toolchain before running tests: `rustup toolchain install "$(< rust-toolchain)" && rustup component add --toolchain "$(< rust-toolchain)" rustfmt clippy`. To run the dylint checks (`DYLINT=true`), additionally install `cargo-dylint` and `dylint-link` with `cargo install cargo-dylint dylint-link`.
2121
- When you change CLI arguments, help text, or anything that affects command-line output, run `./generate-completions.sh` to regenerate the shell completion files, the help text files, `USAGE.md`, and the man page. **Do not attempt to regenerate these files manually.** Always use the script.
22-
- Validate changes with `FMT=true LINT=true BUILD=true TEST=true DOC=true ./test.sh`. When a test fails with a hint about `TEST_SKIP`, follow the hint and rerun with the suggested variable. When a sync test fails, read its error message and run the exact command it reports.
23-
- **Always run the full test suite** (`FMT=true LINT=true BUILD=true TEST=true DOC=true ./test.sh`) before every commit. This rule applies to all changes, including documentation changes, comment edits, config changes, and refactors. The test suite checks formatting, linting, building, tests, and docs across multiple feature combinations, and any kind of change can break any of these checks.
22+
- Validate changes with `FMT=true LINT=true BUILD=true TEST=true DOC=true DYLINT=true ./test.sh`. When a test fails with a hint about `TEST_SKIP`, follow the hint and rerun with the suggested variable. When a sync test fails, read its error message and run the exact command it reports.
23+
- **Always run the full test suite** (`FMT=true LINT=true BUILD=true TEST=true DOC=true DYLINT=true ./test.sh`) before every commit. This rule applies to all changes, including documentation changes, comment edits, config changes, and refactors. The test suite checks formatting, linting, building, tests, and docs across multiple feature combinations, and any kind of change can break any of these checks.
2424
- When the user provides a diff to apply, run `git apply` rather than interpreting each hunk manually. When a diff is provided for context or discussion, respond accordingly.

CLAUDE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Read and follow the CONTRIBUTING.md file in this repository for all code style c
1717
- Minimize `unwrap()` in non-test code. Use proper error handling instead.
1818
- Prefer `#[cfg_attr(..., ignore = "reason")]` over `#[cfg(...)]` when skipping tests. Use `#[cfg]` on tests only when the code cannot compile under the condition, such as when it references types or functions that do not exist on other platforms.
1919
- A unit-test module may sit inline as `mod tests { ... }` when it is short. Once it grows long enough to noticeably extend the parent, move it to an external file and declare the module with `#[cfg(test)] mod tests;` at the end of the parent. The external file lives at `src/foo/tests.rs` for a parent `src/foo.rs`, and at `src/foo/bar/tests.rs` for a parent `src/foo/bar.rs`. Use this layout even when the parent has no other submodules.
20-
- Install the toolchain before running tests: `rustup toolchain install "$(< rust-toolchain)" && rustup component add --toolchain "$(< rust-toolchain)" rustfmt clippy`.
20+
- Install the toolchain before running tests: `rustup toolchain install "$(< rust-toolchain)" && rustup component add --toolchain "$(< rust-toolchain)" rustfmt clippy`. To run the dylint checks (`DYLINT=true`), additionally install `cargo-dylint` and `dylint-link` with `cargo install cargo-dylint dylint-link`.
2121
- When you change CLI arguments, help text, or anything that affects command-line output, run `./generate-completions.sh` to regenerate the shell completion files, the help text files, `USAGE.md`, and the man page. **Do not attempt to regenerate these files manually.** Always use the script.
22-
- Validate changes with `FMT=true LINT=true BUILD=true TEST=true DOC=true ./test.sh`. When a test fails with a hint about `TEST_SKIP`, follow the hint and rerun with the suggested variable. When a sync test fails, read its error message and run the exact command it reports.
23-
- **Always run the full test suite** (`FMT=true LINT=true BUILD=true TEST=true DOC=true ./test.sh`) before every commit. This rule applies to all changes, including documentation changes, comment edits, config changes, and refactors. The test suite checks formatting, linting, building, tests, and docs across multiple feature combinations, and any kind of change can break any of these checks.
22+
- Validate changes with `FMT=true LINT=true BUILD=true TEST=true DOC=true DYLINT=true ./test.sh`. When a test fails with a hint about `TEST_SKIP`, follow the hint and rerun with the suggested variable. When a sync test fails, read its error message and run the exact command it reports.
23+
- **Always run the full test suite** (`FMT=true LINT=true BUILD=true TEST=true DOC=true DYLINT=true ./test.sh`) before every commit. This rule applies to all changes, including documentation changes, comment edits, config changes, and refactors. The test suite checks formatting, linting, building, tests, and docs across multiple feature combinations, and any kind of change can break any of these checks.
2424
- When the user provides a diff to apply, run `git apply` rather than interpreting each hunk manually. When a diff is provided for context or discussion, respond accordingly.
2525
- The `gh` (GitHub CLI) is not installed. Do not attempt to use it.

CONTRIBUTING.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,14 @@ rustup toolchain install "$(< rust-toolchain)"
379379
rustup component add --toolchain "$(< rust-toolchain)" rustfmt clippy
380380
```
381381

382+
To run the dylint checks locally, also install `cargo-dylint` and `dylint-link`:
383+
384+
```sh
385+
cargo install cargo-dylint dylint-link
386+
```
387+
388+
These are only required when running with `DYLINT=true`. The dylint libraries declared in `dylint.toml` are built against their own pinned nightly toolchain, which `cargo-dylint` fetches automatically on first run.
389+
382390
## Optional External Dependencies
383391

384392
Some integration tests require external tools that are not managed by `Cargo.toml`. These tests panic when the tools are absent. CI installs them to get full coverage.
@@ -397,13 +405,16 @@ Before submitting, ensure:
397405
- `cargo clippy` passes on all feature combinations.
398406
- `cargo test` passes.
399407
- The project builds with no default features, with default features, and with all features.
408+
- `cargo dylint --all` passes (requires `cargo-dylint` and `dylint-link`).
400409

401410
The CI script `test.sh` runs all of these across every supported feature combination. You can run it locally with:
402411

403412
```sh
404-
FMT=true LINT=true BUILD=true TEST=true DOC=true ./test.sh
413+
FMT=true LINT=true BUILD=true TEST=true DOC=true DYLINT=true ./test.sh
405414
```
406415

416+
`DYLINT` defaults to `false` because it requires extra tooling and a separate nightly toolchain. Enable it once `cargo-dylint` and `dylint-link` are installed.
417+
407418
> [!IMPORTANT]
408419
> Always run the full test suite before every commit. This rule applies to all changes, including documentation edits, comment changes, and config updates. Any change can break formatting, linting, building, tests, or doc generation across the different feature combinations.
409420

dylint.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[workspace.metadata.dylint]
2+
libraries = [
3+
{ git = "https://github.com/KSXGitHub/perfectionist", rev = "561ed190f4b99bacfbf6b2ca6c6a86174d0d1fc5" },
4+
]

template/ai-instructions/shared.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Read and follow the CONTRIBUTING.md file in this repository for all code style c
1717
- Minimize `unwrap()` in non-test code. Use proper error handling instead.
1818
- Prefer `#[cfg_attr(..., ignore = "reason")]` over `#[cfg(...)]` when skipping tests. Use `#[cfg]` on tests only when the code cannot compile under the condition, such as when it references types or functions that do not exist on other platforms.
1919
- A unit-test module may sit inline as `mod tests { ... }` when it is short. Once it grows long enough to noticeably extend the parent, move it to an external file and declare the module with `#[cfg(test)] mod tests;` at the end of the parent. The external file lives at `src/foo/tests.rs` for a parent `src/foo.rs`, and at `src/foo/bar/tests.rs` for a parent `src/foo/bar.rs`. Use this layout even when the parent has no other submodules.
20-
- Install the toolchain before running tests: `rustup toolchain install "$(< rust-toolchain)" && rustup component add --toolchain "$(< rust-toolchain)" rustfmt clippy`.
20+
- Install the toolchain before running tests: `rustup toolchain install "$(< rust-toolchain)" && rustup component add --toolchain "$(< rust-toolchain)" rustfmt clippy`. To run the dylint checks (`DYLINT=true`), additionally install `cargo-dylint` and `dylint-link` with `cargo install cargo-dylint dylint-link`.
2121
- When you change CLI arguments, help text, or anything that affects command-line output, run `./generate-completions.sh` to regenerate the shell completion files, the help text files, `USAGE.md`, and the man page. **Do not attempt to regenerate these files manually.** Always use the script.
22-
- Validate changes with `FMT=true LINT=true BUILD=true TEST=true DOC=true ./test.sh`. When a test fails with a hint about `TEST_SKIP`, follow the hint and rerun with the suggested variable. When a sync test fails, read its error message and run the exact command it reports.
23-
- **Always run the full test suite** (`FMT=true LINT=true BUILD=true TEST=true DOC=true ./test.sh`) before every commit. This rule applies to all changes, including documentation changes, comment edits, config changes, and refactors. The test suite checks formatting, linting, building, tests, and docs across multiple feature combinations, and any kind of change can break any of these checks.
22+
- Validate changes with `FMT=true LINT=true BUILD=true TEST=true DOC=true DYLINT=true ./test.sh`. When a test fails with a hint about `TEST_SKIP`, follow the hint and rerun with the suggested variable. When a sync test fails, read its error message and run the exact command it reports.
23+
- **Always run the full test suite** (`FMT=true LINT=true BUILD=true TEST=true DOC=true DYLINT=true ./test.sh`) before every commit. This rule applies to all changes, including documentation changes, comment edits, config changes, and refactors. The test suite checks formatting, linting, building, tests, and docs across multiple feature combinations, and any kind of change can break any of these checks.
2424
- When the user provides a diff to apply, run `git apply` rather than interpreting each hunk manually. When a diff is provided for context or discussion, respond accordingly.

test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ unit() (
7373
)
7474

7575
run_if "${FMT:-true}" cargo fmt -- --check
76+
# Dylint inspects the source under all feature gates in a single pass, so it is
77+
# run once with `--all-features` rather than across every feature combination.
78+
run_if "${DYLINT:-false}" cargo dylint --all -- --all-features --all-targets
7679
unit "$@"
7780
unit --no-default-features "$@"
7881
unit --all-features "$@"

0 commit comments

Comments
 (0)