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
This commit is contained in:
parent
c277cdef8c
commit
03f1c1e81b
@ -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/)|
|
||||
|
@ -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': {
|
||||
|
@ -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))
|
||||
|
@ -29,5 +29,11 @@ g:ale_css_stylelint_use_global *g:ale_css_stylelint_use_global*
|
||||
See |ale-integrations-local-executables|
|
||||
|
||||
|
||||
===============================================================================
|
||||
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:
|
||||
|
18
doc/ale-json.txt
Normal file
18
doc/ale-json.txt
Normal file
@ -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:
|
@ -21,5 +21,11 @@ g:ale_scss_stylelint_use_global *g:ale_scss_stylelint_use_global*
|
||||
See |ale-integrations-local-executables|
|
||||
|
||||
|
||||
===============================================================================
|
||||
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:
|
||||
|
@ -93,5 +93,11 @@ g:ale_typescript_tsserver_use_global *g:ale_typescript_tsserver_use_global*
|
||||
tsserver in node_modules.
|
||||
|
||||
|
||||
===============================================================================
|
||||
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:
|
||||
|
14
doc/ale.txt
14
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`
|
||||
|
@ -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(''))
|
||||
|
0
test/prettier-test-files/testfile.css
Normal file
0
test/prettier-test-files/testfile.css
Normal file
0
test/prettier-test-files/testfile.json
Normal file
0
test/prettier-test-files/testfile.json
Normal file
0
test/prettier-test-files/testfile.scss
Normal file
0
test/prettier-test-files/testfile.scss
Normal file
0
test/prettier-test-files/testfile.ts
Normal file
0
test/prettier-test-files/testfile.ts
Normal file
Loading…
Reference in New Issue
Block a user