diff options
author | Peter Renström <renstrom.peter@gmail.com> | 2017-09-06 16:21:26 +0200 |
---|---|---|
committer | w0rp <w0rp@users.noreply.github.com> | 2017-09-06 15:21:26 +0100 |
commit | 03f1c1e81bdf1fd41b535f6a0260d47ba1bf60dc (patch) | |
tree | 372ace207ef4b89d9b61b5d0d364dc3e01fd9dfb | |
parent | c277cdef8cb24512583093d7a9b7d68a14e6d82b (diff) | |
download | ale-03f1c1e81bdf1fd41b535f6a0260d47ba1bf60dc.zip |
Add 'prettier' fixer support to TypeScript, CSS, SCSS and JSON (#910)
* Add prettier fixer support for typescript
* Add prettier fixer support for css and scss
* Add prettier fixer support for json
* Use getbufvar() to get &filetype
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | autoload/ale/fix/registry.vim | 2 | ||||
-rw-r--r-- | autoload/ale/fixers/prettier.vim | 16 | ||||
-rw-r--r-- | doc/ale-css.txt | 6 | ||||
-rw-r--r-- | doc/ale-json.txt | 18 | ||||
-rw-r--r-- | doc/ale-scss.txt | 6 | ||||
-rw-r--r-- | doc/ale-typescript.txt | 6 | ||||
-rw-r--r-- | doc/ale.txt | 14 | ||||
-rw-r--r-- | test/fixers/test_prettier_fixer_callback.vader | 60 | ||||
-rw-r--r-- | test/prettier-test-files/testfile.css | 0 | ||||
-rw-r--r-- | test/prettier-test-files/testfile.json | 0 | ||||
-rw-r--r-- | test/prettier-test-files/testfile.scss | 0 | ||||
-rw-r--r-- | test/prettier-test-files/testfile.ts | 0 |
13 files changed, 126 insertions, 10 deletions
@@ -80,7 +80,7 @@ formatting. | CMake | [cmakelint](https://github.com/richq/cmake-lint) | | CoffeeScript | [coffee](http://coffeescript.org/), [coffeelint](https://www.npmjs.com/package/coffeelint) | | Crystal | [crystal](https://crystal-lang.org/) !! | -| CSS | [csslint](http://csslint.net/), [stylelint](https://github.com/stylelint/stylelint) | +| CSS | [csslint](http://csslint.net/), [stylelint](https://github.com/stylelint/stylelint), [prettier](https://github.com/prettier/prettier) | | Cython (pyrex filetype) | [cython](http://cython.org/) | | D | [dmd](https://dlang.org/dmd-linux.html) | | Dart | [dartanalyzer](https://github.com/dart-lang/sdk/tree/master/pkg/analyzer_cli) | @@ -100,7 +100,7 @@ formatting. | Idris | [idris](http://www.idris-lang.org/) | | Java | [checkstyle](http://checkstyle.sourceforge.net), [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html) | | JavaScript | [eslint](http://eslint.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [flow](https://flowtype.org/), [prettier](https://github.com/prettier/prettier), prettier-eslint >= 4.2.0, prettier-standard, [standard](http://standardjs.com/), [xo](https://github.com/sindresorhus/xo) -| JSON | [jsonlint](http://zaa.ch/jsonlint/) | +| JSON | [jsonlint](http://zaa.ch/jsonlint/), [prettier](https://github.com/prettier/prettier) | | Kotlin | [kotlinc](https://kotlinlang.org) !!, [ktlint](https://ktlint.github.io) !! see `:help ale-integration-kotlin` for configuration instructions | LaTeX | [chktex](http://www.nongnu.org/chktex/), [lacheck](https://www.ctan.org/pkg/lacheck), [proselint](http://proselint.com/) | | Lua | [luacheck](https://github.com/mpeterv/luacheck) | @@ -125,7 +125,7 @@ formatting. | Ruby | [brakeman](http://brakemanscanner.org/) !!, [rails_best_practices](https://github.com/flyerhzm/rails_best_practices) !!, [reek](https://github.com/troessner/reek), [rubocop](https://github.com/bbatsov/rubocop), [ruby](https://www.ruby-lang.org) | | Rust | cargo !! (see `:help ale-integration-rust` for configuration instructions), [rls](https://github.com/rust-lang-nursery/rls), [rustc](https://www.rust-lang.org/) | | SASS | [sass-lint](https://www.npmjs.com/package/sass-lint), [stylelint](https://github.com/stylelint/stylelint) | -| SCSS | [sass-lint](https://www.npmjs.com/package/sass-lint), [scss-lint](https://github.com/brigade/scss-lint), [stylelint](https://github.com/stylelint/stylelint) | +| SCSS | [sass-lint](https://www.npmjs.com/package/sass-lint), [scss-lint](https://github.com/brigade/scss-lint), [stylelint](https://github.com/stylelint/stylelint), [prettier](https://github.com/prettier/prettier) | | Scala | [scalac](http://scala-lang.org), [scalastyle](http://www.scalastyle.org) | | Slim | [slim-lint](https://github.com/sds/slim-lint) | SML | [smlnj](http://www.smlnj.org/) | @@ -136,7 +136,7 @@ formatting. | Texinfo | [proselint](http://proselint.com/)| | Text^ | [proselint](http://proselint.com/), [vale](https://github.com/ValeLint/vale) | | Thrift | [thrift](http://thrift.apache.org/) | -| TypeScript | [eslint](http://eslint.org/), [tslint](https://github.com/palantir/tslint), tsserver, typecheck | +| TypeScript | [eslint](http://eslint.org/), [tslint](https://github.com/palantir/tslint), tsserver, typecheck, [prettier](https://github.com/prettier/prettier) | | Verilog | [iverilog](https://github.com/steveicarus/iverilog), [verilator](http://www.veripool.org/projects/verilator/wiki/Intro) | | Vim | [vint](https://github.com/Kuniwak/vint) | | Vim help^ | [proselint](http://proselint.com/)| diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index b77ac031..5b1030d9 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -34,7 +34,7 @@ let s:default_registry = { \ }, \ 'prettier': { \ 'function': 'ale#fixers#prettier#Fix', -\ 'suggested_filetypes': ['javascript'], +\ 'suggested_filetypes': ['javascript', 'typescript', 'json', 'css', 'scss'], \ 'description': 'Apply prettier to a file.', \ }, \ 'prettier_eslint': { diff --git a/autoload/ale/fixers/prettier.vim b/autoload/ale/fixers/prettier.vim index 581536e6..ca1bf608 100644 --- a/autoload/ale/fixers/prettier.vim +++ b/autoload/ale/fixers/prettier.vim @@ -38,6 +38,22 @@ function! ale#fixers#prettier#Fix(buffer) abort let l:config = s:FindConfig(a:buffer) let l:use_config = ale#Var(a:buffer, 'javascript_prettier_use_local_config') \ && !empty(l:config) + let l:filetype = getbufvar(a:buffer, '&filetype') + + " Append the --parser flag depending on the current filetype (unless it's + " already set in g:javascript_prettier_options). + if match(l:options, '--parser') == -1 + if l:filetype is# 'typescript' + let l:parser = 'typescript' + elseif l:filetype =~# 'css\|scss' + let l:parser = 'postcss' + elseif l:filetype is# 'json' + let l:parser = 'json' + else + let l:parser = 'babylon' + endif + let l:options = (!empty(l:options) ? l:options . ' ' : '') . '--parser ' . l:parser + endif return { \ 'command': ale#Escape(ale#fixers#prettier#GetExecutable(a:buffer)) diff --git a/doc/ale-css.txt b/doc/ale-css.txt index b1ab8eb8..979be881 100644 --- a/doc/ale-css.txt +++ b/doc/ale-css.txt @@ -30,4 +30,10 @@ g:ale_css_stylelint_use_global *g:ale_css_stylelint_use_global* =============================================================================== +prettier *ale-css-prettier* + +See |ale-javascript-prettier| for information about the available options. + + +=============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale-json.txt b/doc/ale-json.txt new file mode 100644 index 00000000..1d052d55 --- /dev/null +++ b/doc/ale-json.txt @@ -0,0 +1,18 @@ +=============================================================================== +ALE JSON Integration *ale-json-options* + + +=============================================================================== +jsonlint *ale-json-jsonlint* + +There are no options available. + + +=============================================================================== +prettier *ale-json-prettier* + +See |ale-javascript-prettier| for information about the available options. + + +=============================================================================== + vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale-scss.txt b/doc/ale-scss.txt index c7b79195..e0b0a11d 100644 --- a/doc/ale-scss.txt +++ b/doc/ale-scss.txt @@ -22,4 +22,10 @@ g:ale_scss_stylelint_use_global *g:ale_scss_stylelint_use_global* =============================================================================== +prettier *ale-scss-prettier* + +See |ale-javascript-prettier| for information about the available options. + + +=============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale-typescript.txt b/doc/ale-typescript.txt index 949b80de..887766fe 100644 --- a/doc/ale-typescript.txt +++ b/doc/ale-typescript.txt @@ -94,4 +94,10 @@ g:ale_typescript_tsserver_use_global *g:ale_typescript_tsserver_use_global* =============================================================================== +prettier *ale-typescript-prettier* + +See |ale-javascript-prettier| for information about the available options. + + +=============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index 899e8c80..3c02af37 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -33,6 +33,7 @@ CONTENTS *ale-contents* gcc.................................|ale-cpp-gcc| clang-format........................|ale-cpp-clangformat| css...................................|ale-css-options| + prettier............................|ale-css-prettier| stylelint...........................|ale-css-stylelint| cmake.................................|ale-cmake-options| cmakelint...........................|ale-cmake-cmakelint| @@ -71,6 +72,9 @@ CONTENTS *ale-contents* prettier-standard...................|ale-javascript-prettier-standard| standard............................|ale-javascript-standard| xo..................................|ale-javascript-xo| + json..................................|ale-json-options| + jsonlint............................|ale-json-jsonlint| + prettier............................|ale-json-prettier| kotlin................................|ale-kotlin-options| kotlinc.............................|ale-kotlin-kotlinc| lua...................................|ale-lua-options| @@ -117,6 +121,7 @@ CONTENTS *ale-contents* scala.................................|ale-scala-options| scalastyle..........................|ale-scala-scalastyle| scss..................................|ale-scss-options| + prettier............................|ale-scss-prettier| stylelint...........................|ale-scss-stylelint| sh....................................|ale-sh-options| shell...............................|ale-sh-shell| @@ -136,6 +141,7 @@ CONTENTS *ale-contents* thrift..............................|ale-thrift-thrift| typescript............................|ale-typescript-options| eslint..............................|ale-typescript-eslint| + prettier............................|ale-typescript-prettier| tslint..............................|ale-typescript-tslint| tsserver............................|ale-typescript-tsserver| verilog/systemverilog.................|ale-verilog-options| @@ -200,7 +206,7 @@ Notes: * CMake: `cmakelint` * CoffeeScript: `coffee`, `coffeelint` * Crystal: `crystal`!! -* CSS: `csslint`, `stylelint` +* CSS: `csslint`, `stylelint`, `prettier` * Cython (pyrex filetype): `cython` * D: `dmd` * Dart: `dartanalyzer` @@ -220,7 +226,7 @@ Notes: * Idris: `idris` * Java: `checkstyle`, `javac` * JavaScript: `eslint`, `jscs`, `jshint`, `flow`, `prettier`, `prettier-eslint` >= 4.2.0, `prettier-standard`, `standard`, `xo` -* JSON: `jsonlint` +* JSON: `jsonlint`, `prettier` * Kotlin: `kotlinc`, `ktlint` * LaTeX (tex): `chktex`, `lacheck`, `proselint` * Lua: `luacheck` @@ -245,7 +251,7 @@ Notes: * Ruby: `brakeman`, `rails_best_practices`!!, `reek`, `rubocop`, `ruby` * Rust: `cargo`!!, `rls`, `rustc` (see |ale-integration-rust|) * SASS: `sass-lint`, `stylelint` -* SCSS: `sass-lint`, `scss-lint`, `stylelint` +* SCSS: `sass-lint`, `scss-lint`, `stylelint`, `prettier` * Scala: `scalac`, `scalastyle` * Slim: `slim-lint` * SML: `smlnj` @@ -256,7 +262,7 @@ Notes: * Texinfo: `proselint` * Text^: `proselint`, `vale` * Thrift: `thrift` -* TypeScript: `eslint`, `tslint`, `tsserver`, `typecheck` +* TypeScript: `eslint`, `tslint`, `tsserver`, `typecheck`, `prettier` * Verilog: `iverilog`, `verilator` * Vim: `vint` * Vim help^: `proselint` diff --git a/test/fixers/test_prettier_fixer_callback.vader b/test/fixers/test_prettier_fixer_callback.vader index 1eb24dae..a684ad02 100644 --- a/test/fixers/test_prettier_fixer_callback.vader +++ b/test/fixers/test_prettier_fixer_callback.vader @@ -24,6 +24,7 @@ Execute(The prettier callback should return the correct default values): \ 'read_temporary_file': 1, \ 'command': ale#Escape(g:ale_javascript_prettier_executable) \ . ' %t' + \ . ' --parser babylon' \ . ' --write', \ }, \ ale#fixers#prettier#Fix(bufnr('')) @@ -37,6 +38,7 @@ Execute(The prettier callback should include configuration files when the option \ 'read_temporary_file': 1, \ 'command': ale#Escape(g:ale_javascript_prettier_executable) \ . ' %t' + \ . ' --parser babylon' \ . ' --config ' . ale#Escape(simplify(g:dir . '/../prettier-test-files/with_config/.prettierrc')) \ . ' --write', \ }, @@ -51,8 +53,64 @@ Execute(The prettier callback should include custom prettier options): \ 'read_temporary_file': 1, \ 'command': ale#Escape(g:ale_javascript_prettier_executable) \ . ' %t' - \ . ' --no-semi' + \ . ' --no-semi --parser babylon' \ . ' --config ' . ale#Escape(simplify(g:dir . '/../prettier-test-files/with_config/.prettierrc')) \ . ' --write', \ }, \ ale#fixers#prettier#Fix(bufnr('')) + +Execute(Append '--parser typescript' for filetype=typescript): + set filetype=typescript + call ale#test#SetFilename('../prettier-test-files/testfile.ts') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape(g:ale_javascript_prettier_executable) + \ . ' %t' + \ . ' --parser typescript' + \ . ' --write', + \ }, + \ ale#fixers#prettier#Fix(bufnr('')) + +Execute(Append '--parser json' for filetype=json): + set filetype=json + call ale#test#SetFilename('../prettier-test-files/testfile.json') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape(g:ale_javascript_prettier_executable) + \ . ' %t' + \ . ' --parser json' + \ . ' --write', + \ }, + \ ale#fixers#prettier#Fix(bufnr('')) + +Execute(Append '--parser postcss' for filetype=scss): + set filetype=scss + call ale#test#SetFilename('../prettier-test-files/testfile.scss') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape(g:ale_javascript_prettier_executable) + \ . ' %t' + \ . ' --parser postcss' + \ . ' --write', + \ }, + \ ale#fixers#prettier#Fix(bufnr('')) + +Execute(Append '--parser postcss' for filetype=css): + set filetype=css + call ale#test#SetFilename('../prettier-test-files/testfile.css') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape(g:ale_javascript_prettier_executable) + \ . ' %t' + \ . ' --parser postcss' + \ . ' --write', + \ }, + \ ale#fixers#prettier#Fix(bufnr('')) diff --git a/test/prettier-test-files/testfile.css b/test/prettier-test-files/testfile.css new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/prettier-test-files/testfile.css diff --git a/test/prettier-test-files/testfile.json b/test/prettier-test-files/testfile.json new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/prettier-test-files/testfile.json diff --git a/test/prettier-test-files/testfile.scss b/test/prettier-test-files/testfile.scss new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/prettier-test-files/testfile.scss diff --git a/test/prettier-test-files/testfile.ts b/test/prettier-test-files/testfile.ts new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/prettier-test-files/testfile.ts |