summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2017-08-10 21:06:55 +0100
committerGitHub <noreply@github.com>2017-08-10 21:06:55 +0100
commitdcf7cbe3661444b272346f9a3f1a7fd26b97dae3 (patch)
treef9426e7f53fb3394411ca3618f8fcc2a883b5986 /autoload
parent34aa3437e0fc062215020b423bdf57da449e9400 (diff)
parent4709e676275000f01975aa433f702e825d6a2353 (diff)
downloadale-dcf7cbe3661444b272346f9a3f1a7fd26b97dae3.zip
Merge pull request #842 from gfontenot/gf-swiftformat
Add support for SwiftFormat as a fixer
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/swiftformat.vim25
2 files changed, 30 insertions, 0 deletions
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