diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | autoload/ale/fix/registry.vim | 5 | ||||
-rw-r--r-- | autoload/ale/fixers/swiftformat.vim | 25 | ||||
-rw-r--r-- | doc/ale.txt | 2 | ||||
-rw-r--r-- | test/command_callback/swift_paths/dummy.swift | 0 | ||||
-rw-r--r-- | test/fixers/test_swiftformat_fixer_callback.vader | 38 |
6 files changed, 70 insertions, 2 deletions
@@ -117,7 +117,7 @@ name. That seems to be the fairest way to arrange this table. | SML | [smlnj](http://www.smlnj.org/) | | Stylus | [stylelint](https://github.com/stylelint/stylelint) | | SQL | [sqlint](https://github.com/purcell/sqlint) | -| Swift | [swiftlint](https://github.com/realm/SwiftLint) | +| Swift | [swiftlint](https://github.com/realm/SwiftLint), [swiftformat](https://github.com/nicklockwood/SwiftFormat) | | Tcl | [nagelfar](http://nagelfar.sourceforge.net)| | Texinfo | [proselint](http://proselint.com/)| | Text^ | [proselint](http://proselint.com/), [vale](https://github.com/ValeLint/vale) | diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index ce30c36e..d9c69f53 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -72,6 +72,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['css', 'sass', 'scss', 'stylus'], \ 'description': 'Fix stylesheet files using stylelint --fix.', \ }, +\ 'swiftformat': { +\ 'function': 'ale#fixers#swiftformat#Fix', +\ 'suggested_filetypes': ['swift'], +\ 'description': 'Apply SwiftFormat to a file.', +\ }, \} " Reset the function registry to the default entries. diff --git a/autoload/ale/fixers/swiftformat.vim b/autoload/ale/fixers/swiftformat.vim new file mode 100644 index 00000000..dcc204b1 --- /dev/null +++ b/autoload/ale/fixers/swiftformat.vim @@ -0,0 +1,25 @@ +" Author: gfontenot (Gordon Fontenot) <gordon@fonten.io> +" Description: Integration of SwiftFormat with ALE. + +call ale#Set('swift_swiftformat_executable', 'swiftformat') +call ale#Set('swift_swiftformat_use_global', 0) +call ale#Set('swift_swiftformat_options', '') + +function! ale#fixers#swiftformat#GetExecutable(buffer) abort + return ale#node#FindExecutable(a:buffer, 'swift_swiftformat', [ + \ 'Pods/SwiftFormat/CommandLineTool/swiftformat', + \ 'ios/Pods/SwiftFormat/CommandLineTool/swiftformat', + \ 'swiftformat', + \]) +endfunction + +function! ale#fixers#swiftformat#Fix(buffer) abort + let l:options = ale#Var(a:buffer, 'swift_swiftformat_options') + + return { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape(ale#fixers#swiftformat#GetExecutable(a:buffer)) + \ . ' %t' + \ . ' ' . l:options, + \} +endfunction diff --git a/doc/ale.txt b/doc/ale.txt index b0323f85..f5a51359 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -224,7 +224,7 @@ The following languages and tools are supported. * SML: 'smlnj' * Stylus: 'stylelint' * SQL: 'sqlint' -* Swift: 'swiftlint' +* Swift: 'swiftlint', 'swiftformat' * Texinfo: 'proselint' * Text: 'proselint', 'vale' * TypeScript: 'eslint', 'tslint', 'tsserver', 'typecheck' diff --git a/test/command_callback/swift_paths/dummy.swift b/test/command_callback/swift_paths/dummy.swift new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/swift_paths/dummy.swift diff --git a/test/fixers/test_swiftformat_fixer_callback.vader b/test/fixers/test_swiftformat_fixer_callback.vader new file mode 100644 index 00000000..e3674ded --- /dev/null +++ b/test/fixers/test_swiftformat_fixer_callback.vader @@ -0,0 +1,38 @@ +Before: + Save g:ale_swift_swiftformat_executable + + " Use an invalid global executable, so we don't match it. + let g:ale_swift_swiftformat_executable = 'xxxinvalid' + + call ale#test#SetDirectory('/testplugin/test/fixers') + silent cd .. + silent cd command_callback + let g:dir = getcwd() + +After: + Restore + + call ale#test#RestoreDirectory() + +Execute(The swiftformat callback should return the correct default values): + call ale#test#SetFilename('swift_paths/dummy.swift') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape(g:ale_swift_swiftformat_executable) + \ . ' %t ', + \ }, + \ ale#fixers#swiftformat#Fix(bufnr('')) + +Execute(The swiftformat callback should include any additional options): + call ale#test#SetFilename('swift_paths/dummy.swift') + let g:ale_swift_swiftformat_options = '--some-option' + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape(g:ale_swift_swiftformat_executable) + \ . ' %t --some-option', + \ }, + \ ale#fixers#swiftformat#Fix(bufnr('')) |