reformat
A modular code transformation framework for applying code transformations to code in a set of source code files.
Organized as a Cargo workspace:
- reformat-core: Core transformation library
- reformat-cli: Command-line interface
- reformat-plugins: Plugin system (foundation)
Features
Default Command (Quick Processing)
- Run all common transformations in a single pass with
reformat <path> - Combines three operations efficiently:
- Rename files to lowercase
- Transform task emojis to text alternatives
- Remove trailing whitespace
- 3x faster than running individual commands separately
- Perfect for quick project cleanup:
reformat -r src/
Case Format Conversion
- Convert between 6 case formats: camelCase, PascalCase, snake_case, SCREAMING_SNAKE_CASE, kebab-case, and SCREAMING-KEBAB-CASE
- Process single files or entire directories (with recursive option)
- Dry-run mode to preview changes
- Filter files by glob patterns
- Filter which words to convert using regex patterns
- Add prefix/suffix to converted identifiers
- Support for multiple file extensions (.c, .h, .py, .md, .js, .ts, .java, .cpp, .hpp)
Whitespace Cleaning
- Remove trailing whitespace from files
- Preserve line endings and file structure
- Recursive directory processing
- Extension filtering with sensible defaults
- Dry-run mode to preview changes
- Automatically skips hidden files and build directories
Emoji Transformation
- Replace task completion emojis with text alternatives (✅ → [x], ☐ → [ ], etc.)
- Replace status indicator emojis (🟡 → [yellow], 🟢 → [green], 🔴 → [red])
- Remove non-task emojis from code and documentation
- Smart replacements for common task tracking symbols
- Configurable behavior (replace task emojis, remove others, or both)
- Support for markdown, documentation, and source files
File Grouping
- Organize files by common prefix into subdirectories
- Automatically detect file prefixes based on separator character
- Optional prefix stripping from filenames after moving
- Suffix-based splitting (
--from-suffix): Split at the LAST separator for multi-part prefixes - Preview mode to see what groups would be created
- Configurable minimum file count for group creation
- Recursive processing for nested directories
- Broken reference detection: Automatically scan codebase for references to moved files
- Interactive fix workflow: Review and apply fixes for broken references
- Change tracking with
changes.jsonandfixes.jsonoutput files
Logging & UI
- Multi-level verbosity control (
-v,-vv,-vvv) - Quiet mode for silent operation (
-q) - File logging for debugging (
--log-file) - Progress spinners with indicatif
- Automatic operation timing
- Color-coded console output
Installation
Install from the workspace:
Or build from source:
The binary will be at ./target/release/reformat
Library Usage
Add to your Cargo.toml:
[]
= "0.1.4"
Case Conversion
use ;
let converter = new?;
converter.process_directory?;
Whitespace Cleaning
use ;
let mut options = default;
options.dry_run = false;
options.recursive = true;
let cleaner = new;
let = cleaner.process?;
println!;
Combined Processing (Default Command)
use ;
let mut options = default;
options.recursive = true;
options.dry_run = false;
let processor = new;
let stats = processor.process?;
println!;
println!;
println!;
File Grouping
use ;
let mut options = default;
options.strip_prefix = true; // Remove prefix from filenames
options.from_suffix = false; // Set true to split at LAST separator
options.min_count = 2; // Require at least 2 files to create a group
options.dry_run = false;
let grouper = new;
let stats = grouper.process?;
println!;
println!;
println!;
Quick Start
Default Command (Recommended)
The fastest way to clean up your code:
# Process directory (non-recursive)
# Process recursively
# Preview changes without modifying files
What it does:
- Renames files to lowercase
- Transforms task emojis: ✅ → [x], ☐ → [ ]
- Removes trailing whitespace
Example:
# Clean up an entire project directory
# Preview changes first
# Process a single file
Output:
Renamed '/tmp/TestFile.txt' -> '/tmp/testfile.txt'
Transformed emojis in '/tmp/testfile.txt'
Cleaned 2 lines in '/tmp/testfile.txt'
Processed files:
- Renamed: 1 file(s)
- Emoji transformations: 1 file(s) (1 changes)
- Whitespace cleaned: 1 file(s) (2 lines)
Usage
Case Conversion
Basic conversion (using subcommand):
Recursive directory conversion:
Dry run (preview changes):
Add prefix to all converted identifiers:
Filter files by pattern:
Only convert specific identifiers:
Whitespace Cleaning
Clean all default file types in current directory:
Clean with dry-run to preview changes:
Clean only specific file types:
Clean a single file:
Emoji Transformation
Replace task emojis with text in markdown files:
Process with dry-run to preview changes:
Only replace task emojis, keep other emojis:
Process specific file types:
File Grouping
Organize files by common prefix into subdirectories:
# Preview what groups would be created
# Dry run to see what would happen
# Group files (keep original filenames)
# Group files and strip prefix from filenames
# Group by suffix (split at LAST separator) - for multi-part prefixes
# Process subdirectories recursively
# Use custom separator (e.g., hyphen)
# Require at least 3 files to create a group
Example transformation with --strip-prefix (splits at FIRST separator):
Before: After:
templates/ templates/
├── wbs_create.tmpl ├── wbs/
├── wbs_delete.tmpl │ ├── create.tmpl
├── wbs_list.tmpl │ ├── delete.tmpl
├── work_package_create.tmpl │ └── list.tmpl
├── work_package_delete.tmpl ├── work/
└── other.txt │ ├── package_create.tmpl
│ └── package_delete.tmpl
└── other.txt
Example transformation with --from-suffix (splits at LAST separator):
Before: After:
templates/ templates/
├── activity_relationships_list.tmpl ├── activity_relationships/
├── activity_relationships_create.tmpl │ ├── list.tmpl
├── activity_relationships_delete.tmpl │ ├── create.tmpl
├── user_profile_edit.tmpl │ └── delete.tmpl
├── user_profile_view.tmpl ├── user_profile/
└── other.txt │ ├── edit.tmpl
│ └── view.tmpl
└── other.txt
Broken Reference Detection
After grouping files, reformat can scan your codebase for broken references:
# Interactive mode (default) - prompts for scanning
# Output:
# Grouping complete:
# - Directories created: 2
# - Files moved: 5
#
# Changes recorded to: changes.json
#
# Would you like to scan for broken references? [y/N]: y
# Enter directories to scan: src
#
# Found 3 broken reference(s).
# Proposed fixes written to: fixes.json
#
# Review fixes.json and apply changes? [y/N]: y
# Fixed 3 reference(s) in 2 file(s).
# Non-interactive mode with automatic scanning
# Skip reference scanning entirely
Generated files:
changes.json- Record of all file operations (for auditing)fixes.json- Proposed reference fixes (review before applying)
Logging and Debugging
Control output verbosity:
# Info level output (-v)
# Debug level output (-vv)
# Silent mode (errors only)
# Log to file
Output example with -v:
2025-10-10T00:15:08.927Z [INFO] Converting from CamelCase to SnakeCase
2025-10-10T00:15:08.927Z [INFO] Target path: /tmp/test.py
2025-10-10T00:15:08.927Z [INFO] Recursive: false, Dry run: false
Converted '/tmp/test.py'
2025-10-10T00:15:08.931Z [INFO] Conversion completed successfully
2025-10-10T00:15:08.931Z [INFO] run_convert(), Elapsed=4.089125ms
Case Format Options
--from-camel/--to-camel- camelCase (firstName, lastName)--from-pascal/--to-pascal- PascalCase (FirstName, LastName)--from-snake/--to-snake- snake_case (first_name, last_name)--from-screaming-snake/--to-screaming-snake- SCREAMING_SNAKE_CASE (FIRST_NAME, LAST_NAME)--from-kebab/--to-kebab- kebab-case (first-name, last-name)--from-screaming-kebab/--to-screaming-kebab- SCREAMING-KEBAB-CASE (FIRST-NAME, LAST-NAME)
Examples
Case Conversion Examples
Convert Python file from camelCase to snake_case:
Convert C++ project from snake_case to PascalCase:
Preview converting JavaScript getters to snake_case:
Whitespace Cleaning Examples
Clean trailing whitespace from entire project:
Clean only Python files in src directory:
Preview what would be cleaned without making changes:
Emoji Transformation Examples
Transform task emojis in documentation:
Example transformation:
Before:
- -----
After:
- -----
Process only markdown files:
File Grouping Examples
Organize template files by prefix (split at first separator):
Organize files with multi-part prefixes (split at last separator):
# activity_relationships_list.tmpl -> activity_relationships/list.tmpl
Preview groups without making changes:
Example output:
Found 2 potential group(s):
wbs (3 files):
- wbs_create.tmpl
- wbs_delete.tmpl
- wbs_list.tmpl
work (2 files):
- work_package_create.tmpl
- work_package_delete.tmpl
Group files with hyphen separator:
Recursively organize nested directories:
Group files and automatically scan for broken references:
Example changes.json:
Example fixes.json:
Installation from crates.io
License
MIT License. See LICENSE for details.