summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorghsang <66662835+ghsang@users.noreply.github.com>2024-08-14 16:24:22 +0900
committerGitHub <noreply@github.com>2024-08-14 08:24:22 +0100
commit954682108d21b412561fb32e3fa766c7ee539984 (patch)
tree64ade148264a5ce1c8c8bc09ec0b868368090561
parent48d73c87c3c321e6298755abc5449267192d07e6 (diff)
downloadale-954682108d21b412561fb32e3fa766c7ee539984.zip
Add support for astro (#4780)
* feat: prettier for astro * feat: eslint for astro * feat: doc for astro
-rw-r--r--ale_linters/astro/eslint.vim11
-rw-r--r--autoload/ale/fix/registry.vim4
-rw-r--r--autoload/ale/fixers/prettier.vim1
-rw-r--r--autoload/ale/linter.vim1
-rw-r--r--doc/ale-astro.txt16
-rw-r--r--doc/ale-supported-languages-and-tools.txt3
-rw-r--r--doc/ale.txt3
-rw-r--r--supported-tools.md3
-rw-r--r--test/fixers/test_eslint_fixer_callback.vader15
-rw-r--r--test/fixers/test_prettier_fixer_callback.vader14
-rw-r--r--test/linter/test_eslint.vader9
-rw-r--r--test/test-files/eslint/astro-app/.eslintrc.js0
-rw-r--r--test/test-files/eslint/astro-app/node_modules/eslint/bin/eslint.js0
-rw-r--r--test/test-files/eslint/astro-app/package.json17
-rw-r--r--test/test-files/eslint/astro-app/src/pages/index.astro16
-rw-r--r--test/test-files/eslint/astro-app/tsconfig.json3
16 files changed, 114 insertions, 2 deletions
diff --git a/ale_linters/astro/eslint.vim b/ale_linters/astro/eslint.vim
new file mode 100644
index 00000000..9fb51ad2
--- /dev/null
+++ b/ale_linters/astro/eslint.vim
@@ -0,0 +1,11 @@
+" Author: Hyuksang Kwon <gwonhyuksang@gmail.com>
+" Description: eslint for astro files
+
+call ale#linter#Define('astro', {
+\ 'name': 'eslint',
+\ 'output_stream': 'both',
+\ 'executable': function('ale#handlers#eslint#GetExecutable'),
+\ 'cwd': function('ale#handlers#eslint#GetCwd'),
+\ 'command': function('ale#handlers#eslint#GetCommand'),
+\ 'callback': 'ale#handlers#eslint#HandleJSON',
+\})
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 38a87153..661fa1e1 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -137,7 +137,7 @@ let s:default_registry = {
\ },
\ 'eslint': {
\ 'function': 'ale#fixers#eslint#Fix',
-\ 'suggested_filetypes': ['javascript', 'typescript'],
+\ 'suggested_filetypes': ['javascript', 'typescript', 'astro'],
\ 'description': 'Apply eslint --fix to a file.',
\ },
\ 'mix_format': {
@@ -152,7 +152,7 @@ let s:default_registry = {
\ },
\ 'prettier': {
\ 'function': 'ale#fixers#prettier#Fix',
-\ 'suggested_filetypes': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'json5', 'graphql', 'markdown', 'vue', 'svelte', 'html', 'yaml', 'openapi', 'ruby'],
+\ 'suggested_filetypes': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'json5', 'graphql', 'markdown', 'vue', 'svelte', 'html', 'yaml', 'openapi', 'ruby', 'astro'],
\ 'description': 'Apply prettier to a file.',
\ },
\ 'prettier_eslint': {
diff --git a/autoload/ale/fixers/prettier.vim b/autoload/ale/fixers/prettier.vim
index 8a67e2ff..c9210e63 100644
--- a/autoload/ale/fixers/prettier.vim
+++ b/autoload/ale/fixers/prettier.vim
@@ -79,6 +79,7 @@ function! ale#fixers#prettier#ApplyFixForVersion(buffer, version) abort
\ 'openapi': 'yaml',
\ 'html': 'html',
\ 'ruby': 'ruby',
+ \ 'astro': 'astro',
\}
for l:filetype in l:filetypes
diff --git a/autoload/ale/linter.vim b/autoload/ale/linter.vim
index fb30fb11..618557d7 100644
--- a/autoload/ale/linter.vim
+++ b/autoload/ale/linter.vim
@@ -40,6 +40,7 @@ let s:default_ale_linter_aliases = {
" NOTE: Update the g:ale_linters documentation when modifying this.
let s:default_ale_linters = {
\ 'apkbuild': ['apkbuild_lint', 'secfixes_check'],
+\ 'astro': ['eslint'],
\ 'csh': ['shell'],
\ 'elixir': ['credo', 'dialyxir', 'dogma'],
\ 'go': ['gofmt', 'golangci-lint', 'gopls', 'govet'],
diff --git a/doc/ale-astro.txt b/doc/ale-astro.txt
new file mode 100644
index 00000000..0132aa80
--- /dev/null
+++ b/doc/ale-astro.txt
@@ -0,0 +1,16 @@
+===============================================================================
+ALE Astro Integration *ale-astro-options*
+
+
+===============================================================================
+eslint *ale-astro-eslint*
+
+See |ale-javascript-eslint| for information about the available options.
+
+===============================================================================
+prettier *ale-astro-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-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index 37cc8335..ec787d22 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -37,6 +37,9 @@ Notes:
* ASM
* `gcc`
* `llvm-mc`
+* Astro
+ * `eslint`
+ * `prettier`
* AVRA
* `avra`
* Awk
diff --git a/doc/ale.txt b/doc/ale.txt
index e235e44c..d9be7682 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -2899,6 +2899,9 @@ documented in additional help files.
asm.....................................|ale-asm-options|
gcc...................................|ale-asm-gcc|
llvm_mc...............................|ale-asm-llvm_mc|
+ astro...................................|ale-astro-options|
+ eslint................................|ale-astro-eslint|
+ prettier..............................|ale-astro-prettier|
avra....................................|ale-avra-options|
avra..................................|ale-avra-avra|
awk.....................................|ale-awk-options|
diff --git a/supported-tools.md b/supported-tools.md
index fee80d23..f49b5a02 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -46,6 +46,9 @@ formatting.
* ASM
* [gcc](https://gcc.gnu.org)
* [llvm-mc](https://llvm.org)
+* Astro
+ * [eslint](http://eslint.org/)
+ * [prettier](https://github.com/prettier/prettier)
* AVRA
* [avra](https://github.com/Ro5bert/avra)
* Awk
diff --git a/test/fixers/test_eslint_fixer_callback.vader b/test/fixers/test_eslint_fixer_callback.vader
index 2a20243c..5cf58014 100644
--- a/test/fixers/test_eslint_fixer_callback.vader
+++ b/test/fixers/test_eslint_fixer_callback.vader
@@ -304,3 +304,18 @@ Execute(The eslint_d post-processor should handle failing to connect properly):
\ ale#fixers#eslint#ProcessEslintDOutput(bufnr(''), [
\ 'Could not connect',
\ ])
+
+Execute(The executable path should be correct for astro app):
+ call ale#test#SetFilename('../test-files/eslint/astro-app/src/pages/index.astro')
+
+ " eslint_d output with an older eslint version is used here.
+ GivenCommandOutput ['v4.4.1 (eslint_d v5.1.0)']
+ AssertFixer
+ \ {
+ \ 'read_temporary_file': 1,
+ \ 'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/astro-app'),
+ \ 'command': (has('win32') ? 'node.exe ' : '')
+ \ . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/astro-app/node_modules/eslint/bin/eslint.js'))
+ \ . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/astro-app/.eslintrc.js'))
+ \ . ' --fix %t',
+ \ }
diff --git a/test/fixers/test_prettier_fixer_callback.vader b/test/fixers/test_prettier_fixer_callback.vader
index 8da13fcd..5726fbc3 100644
--- a/test/fixers/test_prettier_fixer_callback.vader
+++ b/test/fixers/test_prettier_fixer_callback.vader
@@ -293,6 +293,20 @@ Execute(Should set --parser based on first filetype of multiple filetypes):
\ . ' --stdin-filepath %s --stdin',
\ }
+Execute(Should set --parser based on first filetype of multiple filetypes):
+ call ale#test#SetFilename('../test-files/prettier/testfile')
+
+ set filetype=astro
+
+ GivenCommandOutput ['1.6.0']
+ AssertFixer
+ \ {
+ \ 'cwd': '%s:h',
+ \ 'command': ale#Escape(g:ale_javascript_prettier_executable)
+ \ . ' --parser astro'
+ \ . ' --stdin-filepath %s --stdin',
+ \ }
+
Execute(Should set --parser for experimental language, Handlebars):
call ale#test#SetFilename('../test-files/prettier/testfile.hbs')
diff --git a/test/linter/test_eslint.vader b/test/linter/test_eslint.vader
index f4f2e309..6c05fc6d 100644
--- a/test/linter/test_eslint.vader
+++ b/test/linter/test_eslint.vader
@@ -76,3 +76,12 @@ Execute(eslint.js should be run from a containing project with .yarn/sdks):
AssertLinter b:executable,
\ (has('win32') ? ale#Escape('node.exe') . ' ' : '')
\ . ale#Escape(b:executable) . b:args
+
+Execute(astro directories should be detected correctly):
+ call ale#test#SetFilename('../test-files/eslint/astro-app/src/pages/index.astro')
+
+ let b:executable = ale#path#Simplify(g:dir . '/../test-files/eslint/astro-app/node_modules/eslint/bin/eslint.js')
+ AssertLinterCwd ale#path#Simplify(g:dir . '/../test-files/eslint/astro-app')
+ AssertLinter b:executable,
+ \ (has('win32') ? ale#Escape('node.exe') . ' ' : '')
+ \ . ale#Escape(b:executable) . b:args
diff --git a/test/test-files/eslint/astro-app/.eslintrc.js b/test/test-files/eslint/astro-app/.eslintrc.js
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/test-files/eslint/astro-app/.eslintrc.js
diff --git a/test/test-files/eslint/astro-app/node_modules/eslint/bin/eslint.js b/test/test-files/eslint/astro-app/node_modules/eslint/bin/eslint.js
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/test-files/eslint/astro-app/node_modules/eslint/bin/eslint.js
diff --git a/test/test-files/eslint/astro-app/package.json b/test/test-files/eslint/astro-app/package.json
new file mode 100644
index 00000000..527a99fc
--- /dev/null
+++ b/test/test-files/eslint/astro-app/package.json
@@ -0,0 +1,17 @@
+{
+ "name": "astro-app",
+ "type": "module",
+ "version": "0.0.1",
+ "scripts": {
+ "dev": "astro dev",
+ "start": "astro dev",
+ "build": "astro check && astro build",
+ "preview": "astro preview",
+ "astro": "astro"
+ },
+ "dependencies": {
+ "astro": "^4.8.3",
+ "@astrojs/check": "^0.7.0",
+ "typescript": "^5.4.5"
+ }
+} \ No newline at end of file
diff --git a/test/test-files/eslint/astro-app/src/pages/index.astro b/test/test-files/eslint/astro-app/src/pages/index.astro
new file mode 100644
index 00000000..2d141073
--- /dev/null
+++ b/test/test-files/eslint/astro-app/src/pages/index.astro
@@ -0,0 +1,16 @@
+---
+
+---
+
+<html lang="en">
+ <head>
+ <meta charset="utf-8" />
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
+ <meta name="viewport" content="width=device-width" />
+ <meta name="generator" content={Astro.generator} />
+ <title>Astro</title>
+ </head>
+ <body>
+ <h1>Astro</h1>
+ </body>
+</html>
diff --git a/test/test-files/eslint/astro-app/tsconfig.json b/test/test-files/eslint/astro-app/tsconfig.json
new file mode 100644
index 00000000..77da9dd0
--- /dev/null
+++ b/test/test-files/eslint/astro-app/tsconfig.json
@@ -0,0 +1,3 @@
+{
+ "extends": "astro/tsconfigs/strict"
+} \ No newline at end of file