Skip to content

Add 'nudge check' command for CI/linter usage#21

Merged
jssblck merged 5 commits into
mainfrom
jssblck/feat/ci
Jan 23, 2026
Merged

Add 'nudge check' command for CI/linter usage#21
jssblck merged 5 commits into
mainfrom
jssblck/feat/ci

Conversation

@jssblck
Copy link
Copy Markdown
Contributor

@jssblck jssblck commented Jan 23, 2026

Summary

Adds a new nudge check command that validates project files against configured rules, designed for CI pipelines and local linting.

  • Exits 0 on success, 1 when issues found
  • Supports optional path arguments for targeted checking
  • Respects .gitignore and ignores hidden files/directories
  • Reports rule violations with file paths, line numbers, and messages

Usage

# Check entire project
nudge check

# Check specific paths
nudge check src/
nudge check "**/*.rs"

# Use in CI (fails build on violations)
nudge check || exit 1

Dogfooding: Before & After

We ran nudge check on this repository to validate it works. Here's what we found and fixed:

Before (42 violations found)

$ cargo run -p nudge -- check
✗ Found 42 issues in 17 files

./packages/nudge/src/rules/schema.rs:1260 [no-unwrap]
  Use `.expect("descriptive error message")` instead of `.unwrap()`, then retry.

./packages/nudge/src/rules/schema.rs:1276 [no-unwrap]
  Use `.expect("descriptive error message")` instead of `.unwrap()`, then retry.

./packages/nudge/tests/it/bash.rs:77 [no-unwrap]
  Use `.expect("descriptive error message")` instead of `.unwrap()`, then retry.

./packages/nudge/tests/it/bash.rs:153 [no-unwrap]
  Use `.expect("descriptive error message")` instead of `.unwrap()`, then retry.

... (36 more violations across schema.rs, rules.rs, snippet.rs, and test files)

Checked 60 files against 6 rules

After (0 violations)

$ cargo run -p nudge -- check
✓ Checked 60 files against 6 rules
  - .nudge.yaml: 6 rules

Changes

  1. New nudge check command (src/cmd/check.rs)

    • Walks project files respecting .gitignore
    • Evaluates rules against file contents
    • Reports violations with source locations
    • Supports glob patterns for targeted checking
  2. Updated rules to use tree-sitter (.nudge.yaml)

    • prefer-pretty-assertions: Avoids false positive on pretty_assert_eq!
    • no-lhs-type-annotations: Avoids false positive on pattern matching
    • no-inline-imports: Ignores use in mod tests blocks
    • no-unwrap: Matches method calls only, not doc comments/strings
  3. Fixed all violations in source and test files

    • Replaced .unwrap() with .expect() (36 occurrences)
    • Used turbofish syntax instead of LHS type annotations

Testing

  • All 96 tests pass
  • nudge check reports zero violations on this repository

Validates project files against configured rules, enabling use in CI
pipelines or as a standalone linter.

Usage:
  nudge check              # Check all files
  nudge check src/         # Check specific directory
  nudge check "**/*.rs"    # Check files matching pattern

Exits 0 on success, 1 when issues found. Output is compact and
human-readable, showing file:line locations and rule violations.
Apply fixes for real violations found by running nudge check on the codebase:

- Replace std::fs::*, std::process::*, std::fmt::*, etc. with imports
- Use turbofish syntax instead of LHS type annotations where possible
- Move inline imports to file top (std::sync::Mutex in schema.rs)
- Add pretty_assertions import to test modules and convert assert_eq!

Remaining violations are false positives due to rule pattern issues:
- prefer-pretty-assertions: pattern matches substring in pretty_assert_eq!
- no-lhs-type-annotations: matches pattern matching (let Value::Object)
  and required type annotations on generic functions (serde)
- no-inline-imports: matches idiomatic use super::* in test modules
- no-unwrap: matches .unwrap() in doc comments and string literals
- Convert 4 rules from regex to tree-sitter to eliminate false positives:
  - prefer-pretty-assertions: matches macro_invocation instead of substring
  - no-lhs-type-annotations: matches let_declaration with type annotation
  - no-inline-imports: matches use inside block, not test modules
  - no-unwrap: matches actual method calls, avoiding doc comments/strings

- Replace all .unwrap() calls with .expect() for better error messages
  - 11 fixes in schema.rs test code
  - 1 fix in rules.rs test code
  - 2 fixes in snippet.rs test code
  - 9 fixes in bash.rs integration tests
  - 13 fixes in other integration test files
  - 4 fixes in build.rs and cmd modules

All 96 tests pass and nudge check reports zero violations.
@jssblck jssblck merged commit 4d5f3a6 into main Jan 23, 2026
4 checks passed
@jssblck jssblck deleted the jssblck/feat/ci branch January 23, 2026 02:22
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.

1 participant