Code quality guidelines for Jarvy CLI - Rust formatting, Clippy linting, error handling patterns, documentation standards, and Conventional Commits.
This skill defines code quality standards for the Jarvy CLI project.
Run these before every commit:
cargo fmt --all # Format code
cargo clippy --all-features -- -D warnings # Lint (must pass)
cargo check --verbose # Type check
cargo test --verbose -- --show-output # Run tests
// Functions and variables: snake_case
fn install_package(package_name: &str) -> Result<(), InstallError>
// Types and traits: PascalCase
struct ToolConfig { }
enum InstallError { }
// Constants: SCREAMING_SNAKE_CASE
const MAX_RETRY_ATTEMPTS: u32 = 3;
// Modules: snake_case
mod package_manager;
#[cfg(target_os = "macos")]
fn install_macos() -> Result<(), InstallError> { }
#[cfg(target_os = "linux")]
fn install_linux() -> Result<(), InstallError> { }
#[cfg(target_os = "windows")]
fn install_windows() -> Result<(), InstallError> { }
Use OnceLock for lazy initialization:
use std::sync::OnceLock;
use std::sync::RwLock;
static REGISTRY: OnceLock<RwLock<HashMap<String, HandlerFn>>> = OnceLock::new();
fn get_registry() -> &'static RwLock<HashMap<String, HandlerFn>> {
REGISTRY.get_or_init(|| RwLock::new(HashMap::new()))
}
Code must pass cargo clippy --all-features -- -D warnings.
// Use if-let for single pattern
if let Ok(v) = result {
process(v);
}
// Use ? operator
let value = operation()?;
// Use is_empty()
if items.is_empty() { }
// Avoid needless borrows
function(&string) // not &string.clone()
#[derive(thiserror::Error, Debug)]
pub enum InstallError {
#[error("unsupported platform")]
Unsupported,
#[error("prerequisite missing: {0}")]
Prereq(&'static str),
#[error("command failed: {cmd} (code: {code:?})\n{stderr}")]
CommandFailed { cmd: String, code: Option<i32>, stderr: String },
#[error(transparent)]
Io(#[from] std::io::Error),
}
pub fn ensure(min_hint: &str) -> Result<(), InstallError> {
let config = load_config()?;
if !is_installed(&config)? {
install()?;
}
Ok(())
}
pub const SUCCESS: i32 = 0;
pub const CONFIG_ERROR: i32 = 2;
pub const PREREQ_MISSING: i32 = 3;
pub const PERMISSION_REQUIRED: i32 = 5;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_parse_version() {
let result = parse_version("2.40");
assert!(result.is_ok());
}
}
JARVY_TEST_MODE=1 - Disable interactive promptsJARVY_FAST_TEST - Skip external commands//! Tool registry for managing package installer handlers.
//!
//! This module provides a global registry that maps tool names
//! to their installation handler functions.
/// Ensures a tool is installed at the specified minimum version.
///
/// # Arguments
///
/// * `min_hint` - Minimum version string (e.g., "2.40")
///
/// # Returns
///
/// Returns `Ok(())` if installed or successfully installed.
pub fn ensure(min_hint: &str) -> Result<(), InstallError> { }
Use Conventional Commits:
<type>(<scope>): <description>
[optional body]
feat: - New featurefix: - Bug fixdocs: - Documentationchore: - Maintenancerefactor: - Code restructuringtest: - Testsfeat(tools): add Node.js version manager support
fix(config): handle missing jarvy.toml gracefully