sourceror
sourceror copied to clipboard
Sourceror seems to ignore .formatter.exs
First of all, thanks for your great work.
I have started an experimental project recode
to playing around with sourceror
. When I reformat one my project time_zone_info
with recode
I got some unexpected code changes.
The project contains the following .formatter.exs
:
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test,scripts}/**/*.{ex,exs}"],
import_deps: [:stream_data, :nimble_parsec, :plug, :benchee_dsl],
locals_without_parens: [prove: 1, prove: 2]
]
Sourcer still changes code lines like this:
- defparsecp :do_parse, parser
+ defparsecp(:do_parse, parser)
So, it seems sourceror
ignores .formatter.exs
or I have forgotten to set an option correct.
Sourceror does not read the project's formatter.exs
file. It doesn't accept the locals_without_parens
option either.
This would be a really useful feature for Sourceror, so I'll leave it open as a feature request :)
Two things need to be done:
- Support
locals_without_parens
inSourceror.to_string/2
(I just pushed a commit to main for this) - Have a way to read and extract these options from
formatter.exs
files
Maybe the support in Sourceror.to_string/2
is enough to do for sourceror
. You could leave the extracting of the .formatter.exs
to the user of your package. I would be nice if Elixir would have a function like Mix.Project.formatter/1
to get the formatter config. WDYT?
For recode
I have lend me some code from Mix
to extract locals_without_parens
.
Sounds reasonable :)
I was able to get my transformations done with the options provided to to_string
, but agreed it'd be much easier if elixir/mix had a tool for getting that information out of a formatter.exs (i manually recreated my list rather than ripping code from Mix)
Since 1.13 Elixir exposes Mix.Tasks.Format.formatter_for_file/1
, which can be used to parse a .formatter.exs
, grab the options, and pass them to Sourceror.to_string/2
=)