Skip to content

Feature: Detect stuttering type names (module-aware naming) #3

@jssblck

Description

@jssblck

Use Case

Rust style guides recommend avoiding redundant context in type names when they're already namespaced by modules:

// ❌ Avoid: stutters "storage"
mod storage {
    pub struct CasStorage { ... }
    pub struct DiskStorage { ... }
}

// ✅ Prefer: module provides context
mod storage {
    pub struct Cas { ... }
    pub struct Disk { ... }
}

// Usage is clear either way:
use storage::Disk;  // or storage::DiskStorage

Challenge

Creating a reliable Nudge rule requires:

  1. Module context awareness: Know what module a type is defined in
  2. Semantic analysis: Detect if the type name repeats the module name
  3. Linguistic understanding: Recognize variations ("Database" in db, "Manager" suffixes)
  4. False positive avoidance: Some repetition is intentional or necessary

Examples from Real Codebase

From our style guide:

  • storage::CasStorage → ✅ storage::Cas
  • storage::DiskStorage → ✅ storage::Disk
  • db::Database → ✅ db::Postgres
  • cache::KeyCache → ✅ cache::Memory
  • auth::JwtManager → ✅ auth::Jwt

Potential Solutions

To make this enforceable, Nudge would need:

  • AST parsing: Understand module structure and type definitions
  • Name similarity detection: Compare type names to module names
  • Common suffix detection: Recognize patterns like "Manager", "Service", "Handler"
  • Configurable patterns: Allow projects to define their own stuttering patterns

Related Guidelines

From our style guide:

When a type is already namespaced by its module, don't repeat context in the type name.

Request

This requires understanding the relationship between a type's module path and its name. Is there any way to make this pattern detectable, even in a limited form?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions