From 64ddf457e1e95aed1501b6db37181c0e3bfee5e7 Mon Sep 17 00:00:00 2001 From: Henrique Barcelos <16565602+hbarcelos@users.noreply.github.com> Date: Tue, 5 Sep 2023 19:34:39 +0200 Subject: [PATCH] Feature: add `forge fmt` as a fixer for Solidity files (#4598) * feat: add `forge fmt` as a fixer for Solidity --- autoload/ale/fix/registry.vim | 5 +++++ autoload/ale/fixers/forge.vim | 11 +++++++++++ doc/ale-solidity.txt | 9 +++++++++ doc/ale-supported-languages-and-tools.txt | 1 + doc/ale.txt | 1 + supported-tools.md | 1 + test/fixers/test_forge_fixer_callback.vader | 15 +++++++++++++++ 7 files changed, 43 insertions(+) create mode 100644 autoload/ale/fixers/forge.vim create mode 100644 test/fixers/test_forge_fixer_callback.vader diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index d2de0fc2..3c4ccbde 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -286,6 +286,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['fish'], \ 'description': 'Format fish scripts using fish_indent.', \ }, +\ 'forge': { +\ 'function': 'ale#fixers#forge#Fix', +\ 'suggested_filetypes': ['solidity'], +\ 'description': 'Fix Solidity files with forge fmt.', +\ }, \ 'gofmt': { \ 'function': 'ale#fixers#gofmt#Fix', \ 'suggested_filetypes': ['go'], diff --git a/autoload/ale/fixers/forge.vim b/autoload/ale/fixers/forge.vim new file mode 100644 index 00000000..2efbb7da --- /dev/null +++ b/autoload/ale/fixers/forge.vim @@ -0,0 +1,11 @@ +call ale#Set('solidity_forge_executable', 'forge') + +function! ale#fixers#forge#Fix(buffer) abort + let l:executable = ale#Var(a:buffer, 'solidity_forge_executable') + + return { + \ 'command': ale#Escape(l:executable) + \ . ' fmt %t', + \ 'read_temporary_file': 1, + \} +endfunction diff --git a/doc/ale-solidity.txt b/doc/ale-solidity.txt index c4d2f02f..6cf97344 100644 --- a/doc/ale-solidity.txt +++ b/doc/ale-solidity.txt @@ -36,6 +36,15 @@ solium *ale-solidity-solium* See the corresponding solium usage for detailed instructions (https://github.com/duaraghav8/Solium#usage). +=============================================================================== +forge *ale-solidity-forge* + + `forge fmt` is not a linter, only a formatter. It should be used only as a + fixer. + + `forge fmt` should work out-of-the-box. You can further configure it using + `foundry.toml`. See the corresponding documentation for detailed + instructions (https://book.getfoundry.sh/reference/config/formatter). =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index 40c78f76..07ad0a62 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -586,6 +586,7 @@ Notes: * SML * `smlnj` * Solidity + * `forge` * `solc` * `solhint` * `solium` diff --git a/doc/ale.txt b/doc/ale.txt index e73abc99..9cec0fbe 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -3326,6 +3326,7 @@ documented in additional help files. solc..................................|ale-solidity-solc| solhint...............................|ale-solidity-solhint| solium................................|ale-solidity-solium| + forge.................................|ale-solidity-forge| spec....................................|ale-spec-options| rpmlint...............................|ale-spec-rpmlint| sql.....................................|ale-sql-options| diff --git a/supported-tools.md b/supported-tools.md index 72b45671..66914464 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -595,6 +595,7 @@ formatting. * SML * [smlnj](http://www.smlnj.org/) * Solidity + * [forge](https://github.com/foundry-rs/forge) * [solc](https://solidity.readthedocs.io/) * [solhint](https://github.com/protofire/solhint) * [solium](https://github.com/duaraghav8/Solium) diff --git a/test/fixers/test_forge_fixer_callback.vader b/test/fixers/test_forge_fixer_callback.vader new file mode 100644 index 00000000..fbb087a1 --- /dev/null +++ b/test/fixers/test_forge_fixer_callback.vader @@ -0,0 +1,15 @@ +Before: + Save g:ale_solidity_forge_executable + +After: + Restore + +Execute(The forge fmt callback should return the correct default values): + AssertEqual + \ { + \ 'command': ale#Escape('forge') + \ . ' fmt %t', + \ 'read_temporary_file': 1, + \ }, + \ ale#fixers#forge#Fix(bufnr('')) +