| Crates.io | neatify |
| lib.rs | neatify |
| version | 0.1.4 |
| created_at | 2025-07-08 22:17:17.263374+00 |
| updated_at | 2025-07-08 23:35:38.671462+00 |
| description | A code formatter library for multiple languages with a clean API interface |
| homepage | |
| repository | https://github.com/pacmjs/neatify |
| max_upload_size | |
| id | 1743661 |
| size | 295,180 |
A powerful, extensible code formatter library for multiple languages with a clean API interface.
Add this to your Cargo.toml:
[dependencies]
neatify = "0.1.0"
use neatify::{format, format_dir};
use std::path::Path;
// Format a single file
fn format_single_file() -> anyhow::Result<()> {
let file_path = Path::new("path/to/file.js");
let write = true; // Set to false for dry-run
match format(file_path, write)? {
true => println!("File needed formatting and was updated"),
false => println!("File was already formatted"),
}
Ok(())
}
// Format all supported files in a directory
fn format_directory() -> anyhow::Result<()> {
let dir_path = Path::new("path/to/directory");
let write = true; // Set to false for dry-run
let stats = format_dir(dir_path, write)?;
println!("Formatting statistics:");
println!(" Total files processed: {}", stats.total_files);
println!(" Files formatted: {}", stats.formatted_files);
println!(" Files needing formatting: {}", stats.files_needing_formatting);
Ok(())
}
Neatify provides detailed error types for robust error handling:
use neatify::{format, NeatifyError};
use std::path::Path;
fn handle_formatting_errors() {
let result = format(Path::new("non_existent.js"), true);
match result {
Ok(formatted) => println!("Formatting successful: {}", formatted),
Err(NeatifyError::IoError(e)) => println!("IO Error: {}", e),
Err(NeatifyError::UnsupportedFile) => println!("File type not supported"),
Err(NeatifyError::FormattingError(e)) => println!("Formatting failed: {}", e),
Err(e) => println!("Other error: {}", e),
}
}
Neatify is designed to be easily extensible. To add support for a new language:
Tokenizer trait for your languageFormatter trait for your languageget_formatter_for_file functionSee the CONTRIBUTING.md guide for more detailed instructions.
# Clone the repository
git clone https://github.com/pacmjs/neatify.git
cd neatify
# Build the project
cargo build
# Run tests
cargo test
Contributions are welcome! Please feel free to submit a Pull Request.
Please read our Contributing Guidelines before submitting a pull request.
This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.
Currently, Neatify supports the following languages:
The following languages are planned for future releases: