Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scadformat fixer for OpenSCAD #4808

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions autoload/ale/fix/registry.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions autoload/ale/fixers/scadformat.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
" Author: tony o'dell <[email protected]>
" 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
18 changes: 18 additions & 0 deletions doc/ale-openscad.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
1 change: 1 addition & 0 deletions doc/ale-supported-languages-and-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ Notes:
* `yamllint`
* OpenSCAD
* `SCA2D`
* `scadformat`
* Packer
* `packer-fmt-fixer`
* Pascal
Expand Down
1 change: 1 addition & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
1 change: 1 addition & 0 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions test/fixers/test_scadformat_fixer.vader
Original file line number Diff line number Diff line change
@@ -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(''))
Empty file.