Skip to content

Commit 9546821

Browse files
authored
Add support for astro (dense-analysis#4780)
* feat: prettier for astro * feat: eslint for astro * feat: doc for astro
1 parent 48d73c8 commit 9546821

File tree

16 files changed

+114
-2
lines changed

16 files changed

+114
-2
lines changed

ale_linters/astro/eslint.vim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
" Author: Hyuksang Kwon <[email protected]>
2+
" Description: eslint for astro files
3+
4+
call ale#linter#Define('astro', {
5+
\ 'name': 'eslint',
6+
\ 'output_stream': 'both',
7+
\ 'executable': function('ale#handlers#eslint#GetExecutable'),
8+
\ 'cwd': function('ale#handlers#eslint#GetCwd'),
9+
\ 'command': function('ale#handlers#eslint#GetCommand'),
10+
\ 'callback': 'ale#handlers#eslint#HandleJSON',
11+
\})

autoload/ale/fix/registry.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ let s:default_registry = {
137137
\ },
138138
\ 'eslint': {
139139
\ 'function': 'ale#fixers#eslint#Fix',
140-
\ 'suggested_filetypes': ['javascript', 'typescript'],
140+
\ 'suggested_filetypes': ['javascript', 'typescript', 'astro'],
141141
\ 'description': 'Apply eslint --fix to a file.',
142142
\ },
143143
\ 'mix_format': {
@@ -152,7 +152,7 @@ let s:default_registry = {
152152
\ },
153153
\ 'prettier': {
154154
\ 'function': 'ale#fixers#prettier#Fix',
155-
\ 'suggested_filetypes': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'json5', 'graphql', 'markdown', 'vue', 'svelte', 'html', 'yaml', 'openapi', 'ruby'],
155+
\ 'suggested_filetypes': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'json5', 'graphql', 'markdown', 'vue', 'svelte', 'html', 'yaml', 'openapi', 'ruby', 'astro'],
156156
\ 'description': 'Apply prettier to a file.',
157157
\ },
158158
\ 'prettier_eslint': {

autoload/ale/fixers/prettier.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ function! ale#fixers#prettier#ApplyFixForVersion(buffer, version) abort
7979
\ 'openapi': 'yaml',
8080
\ 'html': 'html',
8181
\ 'ruby': 'ruby',
82+
\ 'astro': 'astro',
8283
\}
8384

8485
for l:filetype in l:filetypes

autoload/ale/linter.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ let s:default_ale_linter_aliases = {
4040
" NOTE: Update the g:ale_linters documentation when modifying this.
4141
let s:default_ale_linters = {
4242
\ 'apkbuild': ['apkbuild_lint', 'secfixes_check'],
43+
\ 'astro': ['eslint'],
4344
\ 'csh': ['shell'],
4445
\ 'elixir': ['credo', 'dialyxir', 'dogma'],
4546
\ 'go': ['gofmt', 'golangci-lint', 'gopls', 'govet'],

doc/ale-astro.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
===============================================================================
2+
ALE Astro Integration *ale-astro-options*
3+
4+
5+
===============================================================================
6+
eslint *ale-astro-eslint*
7+
8+
See |ale-javascript-eslint| for information about the available options.
9+
10+
===============================================================================
11+
prettier *ale-astro-prettier*
12+
13+
See |ale-javascript-prettier| for information about the available options.
14+
15+
===============================================================================
16+
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

doc/ale-supported-languages-and-tools.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Notes:
3737
* ASM
3838
* `gcc`
3939
* `llvm-mc`
40+
* Astro
41+
* `eslint`
42+
* `prettier`
4043
* AVRA
4144
* `avra`
4245
* Awk

doc/ale.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2899,6 +2899,9 @@ documented in additional help files.
28992899
asm.....................................|ale-asm-options|
29002900
gcc...................................|ale-asm-gcc|
29012901
llvm_mc...............................|ale-asm-llvm_mc|
2902+
astro...................................|ale-astro-options|
2903+
eslint................................|ale-astro-eslint|
2904+
prettier..............................|ale-astro-prettier|
29022905
avra....................................|ale-avra-options|
29032906
avra..................................|ale-avra-avra|
29042907
awk.....................................|ale-awk-options|

supported-tools.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ formatting.
4646
* ASM
4747
* [gcc](https://gcc.gnu.org)
4848
* [llvm-mc](https://llvm.org)
49+
* Astro
50+
* [eslint](http://eslint.org/)
51+
* [prettier](https://github.com/prettier/prettier)
4952
* AVRA
5053
* [avra](https://github.com/Ro5bert/avra)
5154
* Awk

test/fixers/test_eslint_fixer_callback.vader

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,18 @@ Execute(The eslint_d post-processor should handle failing to connect properly):
304304
\ ale#fixers#eslint#ProcessEslintDOutput(bufnr(''), [
305305
\ 'Could not connect',
306306
\ ])
307+
308+
Execute(The executable path should be correct for astro app):
309+
call ale#test#SetFilename('../test-files/eslint/astro-app/src/pages/index.astro')
310+
311+
" eslint_d output with an older eslint version is used here.
312+
GivenCommandOutput ['v4.4.1 (eslint_d v5.1.0)']
313+
AssertFixer
314+
\ {
315+
\ 'read_temporary_file': 1,
316+
\ 'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/astro-app'),
317+
\ 'command': (has('win32') ? 'node.exe ' : '')
318+
\ . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/astro-app/node_modules/eslint/bin/eslint.js'))
319+
\ . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/astro-app/.eslintrc.js'))
320+
\ . ' --fix %t',
321+
\ }

test/fixers/test_prettier_fixer_callback.vader

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,20 @@ Execute(Should set --parser based on first filetype of multiple filetypes):
293293
\ . ' --stdin-filepath %s --stdin',
294294
\ }
295295

296+
Execute(Should set --parser based on first filetype of multiple filetypes):
297+
call ale#test#SetFilename('../test-files/prettier/testfile')
298+
299+
set filetype=astro
300+
301+
GivenCommandOutput ['1.6.0']
302+
AssertFixer
303+
\ {
304+
\ 'cwd': '%s:h',
305+
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
306+
\ . ' --parser astro'
307+
\ . ' --stdin-filepath %s --stdin',
308+
\ }
309+
296310
Execute(Should set --parser for experimental language, Handlebars):
297311
call ale#test#SetFilename('../test-files/prettier/testfile.hbs')
298312

0 commit comments

Comments
 (0)