From 9aabbcfa54fd9c3370ebcd5bd074cdce23ca760c Mon Sep 17 00:00:00 2001 From: tony-o Date: Fri, 12 Jul 2024 15:52:33 -0700 Subject: [PATCH] Add scadformat to ALE --- autoload/ale/fix/registry.vim | 5 +++++ autoload/ale/fixers/scadformat.vim | 15 +++++++++++++++ doc/ale-openscad.txt | 18 ++++++++++++++++++ doc/ale-supported-languages-and-tools.txt | 1 + doc/ale.txt | 1 + supported-tools.md | 1 + test/fixers/test_scadformat_fixer.vader | 20 ++++++++++++++++++++ test/test-files/openscad/dummy.scad | 0 8 files changed, 61 insertions(+) create mode 100644 autoload/ale/fixers/scadformat.vim create mode 100644 test/fixers/test_scadformat_fixer.vader create mode 100644 test/test-files/openscad/dummy.scad diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 38a87153f5..bc66d75239 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -666,6 +666,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['ruby'], \ 'description': 'A formatter for Ruby source code', \ }, +\ 'scadformat': { +\ 'function': 'ale#fixers#scadformat#Fix', +\ 'suggested_filetypes': ['openscad'], +\ 'description': 'Formatter for scad files', +\ }, \} " Reset the function registry to the default entries. diff --git a/autoload/ale/fixers/scadformat.vim b/autoload/ale/fixers/scadformat.vim new file mode 100644 index 0000000000..f95f296399 --- /dev/null +++ b/autoload/ale/fixers/scadformat.vim @@ -0,0 +1,15 @@ +" Author: tony o'dell +" Description: Fix scad files with scadformat + +call ale#Set('openscad_scadformat_executable', 'scadformat') +call ale#Set('openscad_scadformat_options', '') + +function! ale#fixers#scadformat#Fix(buffer) abort + let l:executable = ale#Var(a:buffer, 'openscad_scadformat_executable') + let l:options = ale#Var(a:buffer, 'openscad_scadformat_options') + + return { + \ 'command': ale#Escape(l:executable) + \ . (empty(l:options) ? '' : ' ' . l:options), + \} +endfunction diff --git a/doc/ale-openscad.txt b/doc/ale-openscad.txt index ac416bc36e..12fb528301 100644 --- a/doc/ale-openscad.txt +++ b/doc/ale-openscad.txt @@ -21,5 +21,23 @@ g:ale_openscad_sca2d_options *g:ale_openscad_sca2d_options* This variable can be set to pass options to sca2d. +=============================================================================== +scadformat ale-openscad-scadformat + +g:ale_openscad_scadformat_executable *g:ale_openscad_scadformat_executable* + *b:ale_openscad_scadformat_executable* + Type: |String| + Default: `'scadformat'` + + See |ale-integrations-local-executables| + + +g:ale_openscad_scadformat_options *g:ale_openscad_scadformat_options* + *b:ale_openscad_scadformat_options* + Type: |String| + Default: `''` + + This variable can be set to pass options to scadformat. + =============================================================================== 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 37cc83352f..a50ac25035 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -435,6 +435,7 @@ Notes: * `yamllint` * OpenSCAD * `SCA2D` + * `scadformat` * Packer * `packer-fmt-fixer` * Pascal diff --git a/doc/ale.txt b/doc/ale.txt index e235e44c63..1d6d476936 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -3237,6 +3237,7 @@ documented in additional help files. yamllint..............................|ale-openapi-yamllint| openscad................................|ale-openscad-options| sca2d.................................|ale-openscad-sca2d| + scadformat............................|ale-openscad-scadformat| packer..................................|ale-packer-options| packer-fmt-fixer......................|ale-packer-fmt-fixer| pascal..................................|ale-pascal-options| diff --git a/supported-tools.md b/supported-tools.md index fee80d23b5..a8bba58c0b 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -444,6 +444,7 @@ formatting. * [yamllint](https://yamllint.readthedocs.io/) * OpenSCAD * [SCA2D](https://gitlab.com/bath_open_instrumentation_group/sca2d) :floppy_disk: + * [scadformat](https://github.com/hugheaves/scadformat) * Packer (HCL) * [packer-fmt-fixer](https://github.com/hashicorp/packer) * Pascal diff --git a/test/fixers/test_scadformat_fixer.vader b/test/fixers/test_scadformat_fixer.vader new file mode 100644 index 0000000000..65d751d7e3 --- /dev/null +++ b/test/fixers/test_scadformat_fixer.vader @@ -0,0 +1,20 @@ +Begin: + Save g:ale_openscad_scadformat_executable + Save g:ale_openscad_scadformat_options + + let g:ale_openscad_scadformat_executable = 'xxx' + let g:ale_openscad_scadformat_options = '' + +After: + Restore + + call ale#test#RestoreDirectory() + +Execute(scadformat - defaults OK): + call ale#test#SetFilename('../test-files/openscad/dummy.scad') + + AssertEqual + \ { + \ 'command': ale#Escape('xxx') + \ }, + \ ale#fixer#scadformat#Fix(bufnr('')) diff --git a/test/test-files/openscad/dummy.scad b/test/test-files/openscad/dummy.scad new file mode 100644 index 0000000000..e69de29bb2