Skip to content

Refactor Elvis configuration for stricter code quality with per-module rule customization #335

@williamthome

Description

@williamthome

Problem

Currently, our Elvis configuration disables several rules globally across all modules (e.g., max_module_length, max_function_length, etc.). This approach reduces code quality enforcement and misses opportunities to catch issues in modules that could easily comply with these rules.

Proposed Solution

Refactor the Elvis configuration to:

  1. Enable all rules by default with strict, reasonable limits
  2. Use per-module rule customization only where necessary via -elvis() attributes
  3. Split large modules to resolve structural issues like max_module_length and god_modules
  4. Document exceptions with clear reasoning for each per-module override

Benefits

  • Higher code quality across the codebase
  • Targeted exceptions only where genuinely needed
  • Better maintainability by catching issues early
  • Clearer intent when rules are disabled for specific modules

Implementation Plan

  1. Audit current disabled rules in elvis.config
  2. Identify modules that can be split (e.g., separate parsing logic, validation, optimization phases)
  3. Re-enable rules globally with appropriate thresholds
  4. Refactor large modules into smaller, focused modules where possible
  5. Add per-module overrides using -elvis() attributes only where splitting isn't feasible
  6. Document rationale for each exception in module comments

Module Splitting Strategy

For rules like max_module_length and god_modules:

  • Extract related functionality into separate modules (e.g., arizona_parse_transform_validation.erl, arizona_parse_transform_optimization.erl)
  • Use behavior patterns to organize module responsibilities
  • Maintain clear interfaces between split modules

Example

Instead of:

% elvis.config
{rules, [
    {elvis_style, max_module_length, disable}
]}

Use:

% elvis.config - strict by default
{rules, [
    {elvis_style, max_module_length, #{max_length => 500}}
]}

In specific modules that need exceptions:

% arizona_parse_transform.erl
-elvis([{elvis_style, max_module_length, #{max_length => 1000}}]).
% Large parse transform module due to comprehensive AST processing

Priority

Medium - Improves code quality without blocking current development

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions