Packages

EditorConfig Core implementation for Elixir: parser, glob matcher, resolver, and CLI.

Current section

Files

Jump to
Raw

README.md

# EditorConfig
[![CI](https://github.com/ivan-podgurskiy/editorconfig/actions/workflows/ci.yml/badge.svg)](https://github.com/ivan-podgurskiy/editorconfig/actions/workflows/ci.yml)
[![Hex.pm](https://img.shields.io/hexpm/v/editorconfig_core.svg)](https://hex.pm/packages/editorconfig_core)
[![HexDocs](https://img.shields.io/badge/hex-docs-blue.svg)](https://hexdocs.pm/editorconfig_core)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
EditorConfig is a pure Elixir EditorConfig parser and resolver targeting
specification 0.17.2. It reads `.editorconfig` files, matches EditorConfig
globs, walks parent directories, and returns the effective properties for any
file. The package also provides typed property helpers and an `editorconfig`
escript CLI.
## Why EditorConfig?
Tools that format, analyze, or generate source code often need the same
settings that a developer's editor uses. Implementing that behavior requires
more than parsing an INI file: `.editorconfig` discovery, glob matching,
section precedence, `root = true`, `unset`, and version-specific defaults all
affect the final result.
EditorConfig provides that behavior through an Elixir API, without requiring
an external EditorConfig executable. It offers:
- resolution of effective EditorConfig properties for a file;
- standalone `.editorconfig` parsing and glob matching;
- source tracing to show which files and sections contributed properties;
- an injectable filesystem, including an in-memory implementation for tests;
- typed helpers for common EditorConfig values;
- an escript-compatible EditorConfig CLI;
- conformance testing against the official `editorconfig-core-test` suite.
## When to use EditorConfig
Use EditorConfig when an Elixir application needs to interpret
`.editorconfig` files itself, especially when building:
- code formatters, linters, or static analysis tools;
- code generators and Mix tasks;
- language servers and editor integrations;
- CI checks that inspect effective formatting settings;
- developer tooling that must explain where a property came from;
- scripts or services that need EditorConfig behavior without shelling out.
You probably do not need this package when your editor already supports
EditorConfig and your Elixir application never reads the resolved properties.
## Installation
Add EditorConfig to your dependencies in `mix.exs`:
```elixir
def deps do
[
{:editorconfig_core, "~> 0.1"}
]
end
```
During local development, use a `path:` dependency.
## Quick start
```elixir
EditorConfig.spec_version()
# => "0.17.2"
{:ok, props} = EditorConfig.properties("/project/lib/file.ex")
props["indent_style"]
# => "space"
```
Use an in-memory filesystem for editor integrations or tests:
```elixir
fs =
EditorConfig.FileSystem.Memory.new(%{
"/project/.editorconfig" => "root = true\n[*]\nindent_style = space\n"
})
EditorConfig.properties("/project/lib/file.ex", fs: fs)
```
Build and run the CLI:
```bash
mix escript.build
./editorconfig lib/file.ex
./editorconfig --files lib/file.ex
```
Documentation is generated with `mix docs`.
## What It Does
`EditorConfig` walks up from a target file, reads each applicable
`.editorconfig`, respects `root = true`, applies EditorConfig glob sections in
order, and returns the final property map for that file. It is meant for
formatters, linters, generators, language servers, editor plugins, and CI tools
that need EditorConfig behavior from Elixir without shelling out to an external
binary.
## Compliance
EditorConfig is gated by the official `editorconfig-core-test` suite pinned in
`vendor/editorconfig-core-test`.
## License
MIT. See [LICENSE](LICENSE).