Skip to content

Commit b4aafd5

Browse files
awuseddbarnett
authored andcommitted
Add support for formatting sass, scss, and less files using js-beautify. (#114)
1 parent 54d1eac commit b4aafd5

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ helpfiles in the `doc/` directory. The helpfiles are also available via
1212

1313
* [Bazel](https://www.github.com/bazelbuild/bazel) BUILD files (buildifier)
1414
* C, C++ (clang-format)
15-
* CSS (js-beautify)
15+
* CSS, Sass, SCSS, Less (js-beautify)
1616
* Chrome GN files (gn)
1717
* Dart (dartfmt)
1818
* Go (gofmt)
@@ -82,7 +82,7 @@ augroup autoformat_settings
8282
autocmd FileType dart AutoFormatBuffer dartfmt
8383
autocmd FileType go AutoFormatBuffer gofmt
8484
autocmd FileType gn AutoFormatBuffer gn
85-
autocmd FileType html,css,json AutoFormatBuffer js-beautify
85+
autocmd FileType html,css,sass,scss,less,json AutoFormatBuffer js-beautify
8686
autocmd FileType java AutoFormatBuffer google-java-format
8787
autocmd FileType python AutoFormatBuffer yapf
8888
" Alternative: autocmd FileType python AutoFormatBuffer autopep8

autoload/codefmt/jsbeautify.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ function! codefmt#jsbeautify#GetFormatter() abort
4343
let l:cmd = [s:plugin.Flag('js_beautify_executable'), '-f', '-']
4444
if &filetype is# 'javascript' || &filetype is# 'json'
4545
let l:cmd = l:cmd + ['--type', 'js']
46+
elseif &filetype is# 'sass' || &filetype is# 'scss' || &filetype is# 'less'
47+
let l:cmd = l:cmd + ['--type', 'css']
4648
elseif &filetype != ""
4749
let l:cmd = l:cmd + ['--type', &filetype]
4850
endif

vroom/jsbeautify.vroom

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ here we specify js-beautify explicitly.
8484
! js-beautify -f - --type css 2>.*
8585
$ f();
8686

87+
:set filetype=sass
88+
:FormatCode js-beautify
89+
! js-beautify -f - --type css 2>.*
90+
$ f();
91+
92+
:set filetype=scss
93+
:FormatCode js-beautify
94+
! js-beautify -f - --type css 2>.*
95+
$ f();
96+
97+
:set filetype=less
98+
:FormatCode js-beautify
99+
! js-beautify -f - --type css 2>.*
100+
$ f();
101+
87102
:set filetype=
88103

89104

0 commit comments

Comments
 (0)