Skip to content

chore(lint): deny self-named module files - #22

Merged
npmccallum merged 1 commit into
mainfrom
bot/devmap/deny-self-named-module-files
Oct 31, 2026
Merged

npmccallum merged 1 commit into
mainfrom
bot/devmap/deny-self-named-module-files

Conversation

@npmccallum

Copy link
Copy Markdown
Contributor

Summary

In Rust, a crate is one library or program, and a module is a named part of its code. This follows the pichi-vm organization rule that all crates use the mod.rs module style: a module with its own folder puts its main code in foo/mod.rs. Clippy, Rust's checker for common mistakes and style problems, rejects a self-named module file, such as foo.rs beside its foo/ folder.

Fixes #21

Approach

A lint is a rule for checking code. The workspace is the group of crates in this repository that are built together. It holds its shared lint list, the list of code checks Clippy runs and how strict each one is, in the top-level Cargo.toml. This is the configuration file for Cargo, Rust's build and test program. Adding self_named_module_files = "deny" there makes a self-named module file an error. Each crate's Cargo.toml has [lints] workspace = true, which means that crate uses the shared lint settings.

A scan of all 85 tracked Rust files found no self-named module files.

Verification

  • All local tests were run and passed for every commit in this series independently

  • Formatting passed. Features are switches for enabling optional parts of the code. Clippy passed with warnings treated as errors for all crates and their build and test targets (the pieces of code selected for compilation) in three settings: all optional features, the default features, and no optional features.

  • Tests and documentation examples passed across the workspace with all optional features and with none. Separate checks passed with default features for the core crate and the disk snapshot crate, which preserves a view of data at a chosen time, including the snapshot documentation examples. The disk verification crate, which checks data against stored fingerprints (short values computed from the data) to detect changes, also passed with all features.

  • The disk verification crate passed separate feature checks for tokio, a library for work that can wait without blocking, including documentation examples, and for tokio together with the fingerprint algorithm sha2 (tokio,sha2). It also passed with each fingerprint algorithm (blake2, ripemd, sha1, sha2, sha3, sm3, streebog, whirlpool) and with the pairs sha1,sha2, sha3,whirlpool, blake2,sm3, and ripemd,streebog.

  • Rust 1.87.0 is the minimum supported Rust version. It compiled all test targets with all features and passed documentation examples with all features and with none.

  • The documentation build passed with warnings treated as errors. The package build, which prepares crates for distribution and checks that they compile, passed for all crates with all features.

  • cargo deny, a check of rules for third-party code, passed its security notice, license, source, and permitted-library checks. cargo audit, a check for reported security problems in third-party code, passed.

  • hawkeye, the checker for license notices at the start of source files, passed. gitlint, the commit message checker, passed. The check of spaces, tabs, and line endings passed. actionlint, the checker for GitHub Actions workflow files that describe automated checks, passed, including checks of commands in those files.

  • Checks of which libraries each crate depends on passed. .github/scripts/tests/kernel-tests.sh passed all nine sample cases. It uses stand-ins for Cargo and test programs to check .github/scripts/kernel-tests.sh without running tests that need administrator rights. The script it tests compiles tests for all crates with all optional features, checks a list of test programs, and runs them one at a time, including tests marked to be skipped by default. Eight cases cover a compiler failure, a reported unsuccessful build, malformed output, empty output, output with no test programs, output without a final build result, a path containing a line break, and a missing test program. Each checks that no tests run, the saved list is removed, and temporary files are removed. The success case checks that the script writes the expected list with repeated entries removed, handles a path containing a space, and launches the test program once through the runner (the command that starts it), with the expected options.

  • A small test with a self-named module file confirmed that Clippy rejects it and asks for the mod.rs style.

The 28 tests that need administrator (root) rights to create device-mapper devices (device-mapper is the Linux system for creating virtual disk devices) and loop devices (a loop device lets a file act as a disk) were run as root inside a small local virtual machine (a computer running inside another computer) on this commit. All passed under each feature setting they belong to: 59 test and feature combinations, 59 passed, 0 failed.

In Rust, a module is a named part of a crate (a crate is one Rust
library or program). When a module has its own folder, its main code
can live in one of two places: in a file inside the folder called
`mod.rs` (for example `foo/mod.rs`), or in a file named after the
module that sits beside the folder (for example `foo.rs` next to
`foo/`). We call the second kind a self-named module file.

All crates in the pichi-vm organization use the `mod.rs` style. This
change asks Clippy, the standard Rust tool that checks code for common
mistakes and style problems, to treat a self-named module file as an
error. The shared lint list is the list of code checks Clippy runs
and how strict each one is. The top-level `Cargo.toml`, the file for
Rust build settings, holds this list for the workspace: the group of
crates in this repository that are built together. Each crate's
`Cargo.toml` has `[lints] workspace = true`, which means that crate
uses the shared lint settings.

This workspace has no self-named module files.

Fixes #21
@npmccallum
npmccallum merged commit 9c4898b into main Oct 31, 2026
22 checks passed
@npmccallum
npmccallum deleted the bot/devmap/deny-self-named-module-files branch October 31, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deny self-named module files in Clippy

1 participant