diff options
author | Cyrille David <dcyriller@gmail.com> | 2019-06-11 00:11:14 +0200 |
---|---|---|
committer | Cyrille David <cyrille@qonto.eu> | 2019-06-13 10:36:51 +0200 |
commit | 86205967ea0a31bacc600eb162d6668cdf0fd726 (patch) | |
tree | 3357f169d09726acf82ce37dbe59e095e36adc46 /autoload | |
parent | 3e4b8ea466efca0d05c9952b80f00f96f5dd0e4e (diff) | |
download | ale-86205967ea0a31bacc600eb162d6668cdf0fd726.zip |
Refactor to be less verbose
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/fixers/prettier.vim | 73 |
1 files changed, 33 insertions, 40 deletions
diff --git a/autoload/ale/fixers/prettier.vim b/autoload/ale/fixers/prettier.vim index e798dfb3..23120777 100644 --- a/autoload/ale/fixers/prettier.vim +++ b/autoload/ale/fixers/prettier.vim @@ -39,51 +39,44 @@ function! ale#fixers#prettier#ApplyFixForVersion(buffer, version) abort let l:options = ale#Var(a:buffer, 'javascript_prettier_options') let l:parser = '' - " 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 empty(expand('#' . a:buffer . ':e')) - " Mimic Prettier's defaults. In cases without a file extension or - " filetype (scratch buffer), Prettier needs `parser` set to know how - " to process the buffer. - if ale#semver#GTE(a:version, [1, 16, 0]) - let l:parser = 'babel' - else - let l:parser = 'babylon' - endif + let l:filetypes = split(getbufvar(a:buffer, '&filetype'), '\.') - let l:prettier_parsers = { - \ 'typescript': 'typescript', - \ 'css': 'css', - \ 'less': 'less', - \ 'scss': 'scss', - \ 'json': 'json', - \ 'json5': 'json5', - \ 'graphql': 'graphql', - \ 'markdown': 'markdown', - \ 'vue': 'vue', - \ 'yaml': 'yaml', - \ 'html': 'html', - \} + if index(l:filetypes, 'handlebars') > -1 + let l:parser = 'glimmer' + endif - for l:filetype in split(getbufvar(a:buffer, '&filetype'), '\.') - if has_key(l:prettier_parsers, l:filetype) - let l:parser = l:prettier_parsers[l:filetype] - break - endif - endfor + " Append the --parser flag depending on the current filetype (unless it's + " already set in g:javascript_prettier_options). + if empty(expand('#' . a:buffer . ':e')) && l:parser is# '' && match(l:options, '--parser') == -1 + " Mimic Prettier's defaults. In cases without a file extension or + " filetype (scratch buffer), Prettier needs `parser` set to know how + " to process the buffer. + if ale#semver#GTE(a:version, [1, 16, 0]) + let l:parser = 'babel' else - " Append a --parser flag. In cases the filetype has an exprimental - " support in Prettier and has to be appended manually. - let l:prettier_experimental_parsers = { - \ 'html.handlebars': 'glimmer', - \} - let l:filetype = getbufvar(a:buffer, '&filetype') + let l:parser = 'babylon' + endif - if has_key(l:prettier_experimental_parsers, l:filetype) - let l:parser = l:prettier_experimental_parsers[l:filetype] + let l:prettier_parsers = { + \ 'typescript': 'typescript', + \ 'css': 'css', + \ 'less': 'less', + \ 'scss': 'scss', + \ 'json': 'json', + \ 'json5': 'json5', + \ 'graphql': 'graphql', + \ 'markdown': 'markdown', + \ 'vue': 'vue', + \ 'yaml': 'yaml', + \ 'html': 'html', + \} + + for l:filetype in l:filetypes + if has_key(l:prettier_parsers, l:filetype) + let l:parser = l:prettier_parsers[l:filetype] + break endif - endif + endfor endif if !empty(l:parser) |