Repository navigation
chore(lint): deny self-named module files - #22
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.rsmodule style: a module with its own folder puts its main code infoo/mod.rs. Clippy, Rust's checker for common mistakes and style problems, rejects a self-named module file, such asfoo.rsbeside itsfoo/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. Addingself_named_module_files = "deny"there makes a self-named module file an error. Each crate'sCargo.tomlhas[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 fortokiotogether with the fingerprint algorithmsha2(tokio,sha2). It also passed with each fingerprint algorithm (blake2,ripemd,sha1,sha2,sha3,sm3,streebog,whirlpool) and with the pairssha1,sha2,sha3,whirlpool,blake2,sm3, andripemd,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.shpassed all nine sample cases. It uses stand-ins for Cargo and test programs to check.github/scripts/kernel-tests.shwithout 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.rsstyle.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.