Skip to main content

Crate convention_lint

Crate convention_lint 

Source
Expand description

§convention-lint

A file-naming convention linter for Rust projects, configurable via Cargo.toml metadata.

It enforces naming conventions (like snake_case or CamelCase) for any files in your project, not just Rust source files. It uses parallel directory traversal (same as ripgrep) and respects .gitignore.

§Configuration

Add [[package.metadata.convention-lint.checks]] or [[workspace.metadata.convention-lint.checks]] entries to your Cargo.toml.

§Example

[[workspace.metadata.convention-lint.checks]]
dirs      = ["src/idl", "proto"]
include   = ["*.idl", "*.proto"]
exclude   = ["**/legacy_*.proto"]
format    = "snake_case"
recursive = true

§Configuration Fields

FieldRequiredDefaultDescription
dirsYesDirectories to scan. Supports globs like src/*/tests. Cannot be empty.
includeNo["*"]Glob patterns for files to check (e.g. ["*.rs"]).
excludeNo[]Glob patterns for files to skip (takes priority over include).
formatYesConvention to enforce: snake_case, CamelCase, camelCase, SCREAMING_SNAKE_CASE, kebab-case.
recursiveNotrueIf false, the linter won’t enter subdirectories.

§Pattern Matching Rules

Patterns in include and exclude are matched against the full relative path //! from the project root.

PatternMatch TypeDescription
*.rsExtensionAny .rs file in any directory.
generated.rsExact FileOnly generated.rs in the project root.
**/generated.rsFloating FileAny file named generated.rs anywhere in the project.
**/tests/**DirectoryEntire directory and all its contents.

Note: To exclude an entire directory, always end the pattern with /**.

§Supported Conventions

IdentifierExample
snake_casemy_service
CamelCaseMyService (Alias: PascalCase)
camelCasemyService
SCREAMING_SNAKE_CASEMY_SERVICE
kebab-casemy-service

§Usage

Install the tool:

cargo install convention-lint

Run it in your project root:

cargo convention-lint

§Library Usage

use convention_lint::{config::load_config, lint::run};
use std::path::Path;

let manifest_path = Path::new("Cargo.toml");
let project_root = Path::new(".");

let cfg = load_config(manifest_path)?;
let violations = run(&cfg, project_root);

for v in &violations {
    eprintln!("{v}");
}

if !violations.is_empty() {
    std::process::exit(1);
}

Re-exports§

pub use crate::core::Convention;
pub use crate::error::Error;
pub use crate::lint::Violation;

Modules§

config
Configuration loading from Cargo.toml metadata.
core
Naming convention definitions and stem validation.
error
Error types for convention-lint.
lint
Core linting logic — filesystem walk and violation collection.