Apply `exclude_files` to `files` absolute paths
When calling erlfmt with absolute paths for the files to format, the excludes don't apply, even if the resolved paths of the excludes would match the files to format.
Resolve the paths of the excludes based on the current working directory and add them to the excludes.
This issue was observed when using the
VS Code Erlang Formatter extension. The extension invokes rebar3 fmt with the full path of the file to format.
@awalterschulze @michalmuskala ready for further review 🙂
I've addressed Windows support by switching to using filename:absname/2 for abspath resolution.
The change also makes sure files/exclude_files consistently resolve relative paths in case of double dots/parent directory segments. Note that previously, erlfmt didn't resolve these - e.g. a/../b and b were distinct. I had already resolved these for the absolute excludes in the first commit. Now it applies to all paths for both files/exclude_files.
I intentionally avoided any symlink resolution. The existing behaviour of erlfmt treats symlinks as distinct files. e.g.
$ echo " -module(a)." > a.erl
$ ln -s a.erl b.erl
$ rebar3 fmt --verbose --exclude-files "a.erl" b.erl
Formatting b.erl
-module(a).
a.erl is skipped, because the b.erl symlink is not followed.
I think this makes sense and is consistent with most treatment of symlinks in my experience. One example is the script name argument when running a bash script:
$ echo 'echo $0' > test.sh
$ chmod +x test.sh
$ ln -s test.sh test2.sh
$ ./test.sh
./test.sh
$ ./test2.sh
./test2.sh
Unless the script explicitly follows its script name symlink, it thinks it is a unique script.
Thank you! ❤️