Thanks to visit codestin.com
Credit goes to lib.rs

4 releases

Uses new Rust 2024

0.0.4 Apr 7, 2026
0.0.3 Dec 18, 2025
0.0.2 Dec 10, 2025
0.0.1 Dec 9, 2025

#112 in Text editors

Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App

11,472 downloads per month

MIT license

22KB
288 lines

editorconfig-parser

Crates.io Docs.rs

MIT licensed Build Status Code Coverage CodSpeed Badge Sponsors Discord chat

A fast, spec-compliant Rust implementation of an EditorConfig parser.

Features

  • Spec-compliant - fully implements the EditorConfig specification
  • Zero dependencies - pure Rust implementation with no external dependencies
  • Fast and safe - no unsafe code, optimized for performance
  • Comprehensive property support - handles all standard EditorConfig properties
  • Path resolution - resolves properties for specific file paths

Usage

Add this to your Cargo.toml:

[dependencies]
editorconfig-parser = "0.0.1"

Parsing an EditorConfig file

use editorconfig_parser::EditorConfig;

let config_text = r#"
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
max_line_length = off

[Makefile]
indent_style = tab
"#;

let config = EditorConfig::parse(config_text);

// Check if this is a root config
assert!(config.root());

// Access sections
for section in config.sections() {
    println!("Section: {}", section.name);
    if let Some(indent_style) = section.properties.indent_style {
        println!("  indent_style: {:?}", indent_style);
    }
}

Resolving properties for a file path

use editorconfig_parser::EditorConfig;
use std::path::Path;

let config = EditorConfig::parse(config_text);
let properties = config.resolve(Path::new("src/main.rs"));

Supported Properties

The parser supports all standard EditorConfig properties:

Property Type Values
indent_style IdentStyle tab, space
indent_size usize Positive integer
tab_width usize Positive integer
end_of_line EndOfLine lf, cr, crlf
charset Charset latin1, utf-8, utf-8-bom, utf-16be, utf-16le
trim_trailing_whitespace bool true, false
insert_final_newline bool true, false
max_line_length MaxLineLength Positive integer or off
quote_type QuoteType single, double, auto

Note: max_line_length and quote_type are not part of the official EditorConfig spec but are commonly used by tools like Prettier.

How It Works

The parser follows the EditorConfig specification:

  1. Reads the file line by line
  2. Removes leading and trailing whitespace
  3. Ignores blank lines and comments (# or ;)
  4. Parses root = true in the preamble (before any sections)
  5. Parses section headers [pattern] as glob patterns
  6. Parses key-value pairs key = value within sections
  7. All values are case-insensitive

Development

Building

cargo build --release

Running Tests

cargo test

License

MIT

References

Sponsored By

My sponsors

Dependencies

~2.8–4.5MB
~77K SLoC