How to format only changed lines by mix format
? How to integrate it with git?
This is not an option. Mix format wants to format the entire file passed to it. I also don’t think it ever will be added as the whole point is to add consistency.
They do offer nice options for integrating with git.
You will need to write a CI script that manually invokes mix format with the files in your git dif.
The formatter will read a `.formatter.exs` in the current directory for
formatter configuration. Evaluating this file should return a keyword list.
Here is an example `.formatter.exs` that works as a starting point:
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
Besides the options listed in `Code.format_string!/2`, the `.formatter.exs`
supports the following options:
* `:inputs` (a list of paths and patterns) - specifies the default inputs
to be used by this task. For example, `["mix.exs", "{config,lib,test}/**/*.{ex,exs}"]`.
Patterns are expanded with `Path.wildcard/2`.
* `:subdirectories` (a list of paths and patterns) - specifies subdirectories
that have their own formatting rules. Each subdirectory should have a
`.formatter.exs` that configures how entries in that subdirectory should be
formatted as. Configuration between `.formatter.exs` are not shared nor
and
{value, binding}
end
@doc ~S"""
Formats the given code `string`.
The formatter receives a string representing Elixir code and
returns iodata representing the formatted code according to
pre-defined rules.
## Options
* `:file` - the file which contains the string, used for error
reporting
* `:line` - the line the string starts, used for error reporting
* `:line_length` - the line length to aim for when formatting
the document. Defaults to 98.
* `:locals_without_parens` - a keyword list of name and arity
The only real options right now are line_length and locals_without_parens
1 Like