Packages
editorconfig_core
0.1.0
EditorConfig Core implementation for Elixir: parser, glob matcher, resolver, and CLI.
Current section
Files
Jump to
Current section
Files
lib/editor_config.ex
defmodule EditorConfig do
@spec_version "0.17.2"
@moduledoc """
Resolves EditorConfig properties for files.
This package targets EditorConfig specification #{@spec_version}.
"""
@doc """
Returns the EditorConfig specification version targeted by this package.
## Examples
iex> EditorConfig.spec_version()
"0.17.2"
"""
@spec spec_version() :: String.t()
def spec_version, do: @spec_version
@doc """
Returns the package version.
## Examples
iex> EditorConfig.version()
"0.1.0"
"""
@spec version() :: String.t()
def version do
Application.spec(:editorconfig_core, :vsn)
|> to_string()
end
@doc """
Resolves EditorConfig properties for `path`.
## Examples
iex> fs = EditorConfig.FileSystem.Memory.new(%{
...> "/project/.editorconfig" => "root = true\\n[*]\\nindent_style = space\\n"
...> })
iex> EditorConfig.properties("/project/file.ex", fs: fs)
{:ok, %{"indent_style" => "space"}}
"""
@spec properties(Path.t(), keyword()) :: {:ok, map()} | {:error, term()}
def properties(path, opts \\ []), do: EditorConfig.Resolver.properties(path, opts)
@doc """
Resolves properties and includes contributing config file/section sources.
## Examples
iex> fs = EditorConfig.FileSystem.Memory.new(%{
...> "/project/.editorconfig" => "root = true\\n[*]\\nindent_style = space\\n"
...> })
iex> EditorConfig.properties_with_sources("/project/file.ex", fs: fs)
{:ok, %{"indent_style" => "space"}, [{"/project/.editorconfig", "*"}]}
"""
@spec properties_with_sources(Path.t(), keyword()) :: {:ok, map(), list()} | {:error, term()}
def properties_with_sources(path, opts \\ []) do
EditorConfig.Resolver.properties_with_sources(path, opts)
end
@doc """
Parses one `.editorconfig` file.
## Examples
iex> {:ok, file} = EditorConfig.parse("[*]\\nindent_style = space\\n")
iex> hd(file.sections).properties
%{"indent_style" => "space"}
"""
@spec parse(binary(), keyword()) :: {:ok, EditorConfig.File.t()} | {:error, term()}
def parse(binary, opts \\ []), do: EditorConfig.Parser.parse(binary, opts)
end