diff --git a/ale_linters/javascript/oxlint.vim b/ale_linters/javascript/oxlint.vim new file mode 100644 index 0000000000..c8c81a1100 --- /dev/null +++ b/ale_linters/javascript/oxlint.vim @@ -0,0 +1,11 @@ +" Author: Jeff Miccolis +" Description: oxlint for JavaScript files. + +call ale#linter#Define('javascript', { +\ 'name': 'oxlint', +\ 'lsp': 'stdio', +\ 'executable': function('ale#handlers#oxlint#GetExecutable'), +\ 'command': '%e --lsp', +\ 'project_root': function('ale#handlers#oxlint#GetProjectRoot'), +\ 'initialization_options': function('ale#handlers#oxlint#GetInitializationOptions'), +\}) diff --git a/ale_linters/typescript/oxlint.vim b/ale_linters/typescript/oxlint.vim new file mode 100644 index 0000000000..85d858e642 --- /dev/null +++ b/ale_linters/typescript/oxlint.vim @@ -0,0 +1,12 @@ +" Author: Jeff Miccolis +" Description: oxlint for TypeScript files. + +call ale#linter#Define('typescript', { +\ 'name': 'oxlint', +\ 'lsp': 'stdio', +\ 'executable': function('ale#handlers#oxlint#GetExecutable'), +\ 'command': '%e --lsp', +\ 'project_root': function('ale#handlers#oxlint#GetProjectRoot'), +\ 'initialization_options': function('ale#handlers#oxlint#GetInitializationOptions'), +\}) + diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 0770e0f1b6..4f1b79d270 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -176,6 +176,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['javascript', 'typescript', 'astro'], \ 'description': 'Apply eslint --fix to a file.', \ }, +\ 'oxfmt': { +\ 'function': 'ale#fixers#oxfmt#Fix', +\ 'suggested_filetypes': ['javascript', 'typescript', 'typescriptreact', 'css', 'less', 'scss', 'json', 'json5', 'graphql', 'toml', 'yaml'], +\ 'description': 'Apply oxfmt to a file.', +\ }, \ 'mix_format': { \ 'function': 'ale#fixers#mix_format#Fix', \ 'suggested_filetypes': ['elixir'], diff --git a/autoload/ale/fixers/oxfmt.vim b/autoload/ale/fixers/oxfmt.vim new file mode 100644 index 0000000000..5c4ba99f33 --- /dev/null +++ b/autoload/ale/fixers/oxfmt.vim @@ -0,0 +1,34 @@ +" Author: Jeff Miccolis +" Description: Fixing files with oxlint. + +call ale#Set('javascript_oxfmt_executable', 'oxfmt') +call ale#Set('javascript_oxfmt_use_global', get(g:, 'ale_use_global_executables', 0)) +call ale#Set('javascript_oxfmt_options', '') + +function! ale#fixers#oxfmt#GetExecutable(buffer) abort + return ale#path#FindExecutable(a:buffer, 'javascript_oxfmt', [ + \ 'node_modules/.bin/oxfmt', + \]) +endfunction + +function! ale#fixers#oxfmt#Fix(buffer) abort + let l:executable = ale#fixers#oxfmt#GetExecutable(a:buffer) + let l:options = ale#Var(a:buffer, 'javascript_oxfmt_options') + + " Needs oxfmt with https://github.com/oxc-project/oxc/pull/16868 + return { + \ 'cwd': ale#fixers#oxfmt#GetCwd(a:buffer), + \ 'command': ale#Escape(l:executable) + \ . ale#Pad(l:options) + \ . ' --stdin-filepath %s', + \} + +endfunction + +function! ale#fixers#oxfmt#GetCwd(buffer) abort + let l:config = ale#path#FindNearestFile(a:buffer, '.oxfmtrc.json') + + " Fall back to the directory of the buffer + return !empty(l:config) ? fnamemodify(l:config, ':h') : '%s:h' +endfunction + diff --git a/autoload/ale/handlers/oxlint.vim b/autoload/ale/handlers/oxlint.vim new file mode 100644 index 0000000000..11009b6e2e --- /dev/null +++ b/autoload/ale/handlers/oxlint.vim @@ -0,0 +1,45 @@ +" Author: Jeff Miccolis + +call ale#Set('javascript_oxlint_executable', 'oxlint') +call ale#Set('javascript_oxlint_use_global', get(g:, 'ale_use_global_executables', 0)) +call ale#Set('javascript_oxlint_options', {}) + +function! ale#handlers#oxlint#GetExecutable(buffer) abort + return ale#path#FindExecutable(a:buffer, 'javascript_oxlint', [ + \ 'node_modules/.bin/oxlint', + \]) +endfunction + +function! ale#handlers#oxlint#GetProjectRoot(buffer) abort + let l:possible_project_roots = [ + \ '.oxlintrc.json', + \ '.oxlintrc.jsonc', + \ 'oxlint.config.ts', + \ 'oxlint.config.mts', + \ 'package.json', + \ bufname(a:buffer), + \] + + for l:possible_root in l:possible_project_roots + let l:project_root = ale#path#FindNearestFile(a:buffer, l:possible_root) + + if empty(l:project_root) + let l:project_root = ale#path#FindNearestDirectory(a:buffer, l:possible_root) + endif + + if !empty(l:project_root) + " dir:p expands to /full/path/to/dir/ whereas + " file:p expands to /full/path/to/file (no trailing slash) + " Appending '/' ensures that :h:h removes the path's last segment + " regardless of whether it is a directory or not. + return fnamemodify(l:project_root . '/', ':p:h:h') + endif + endfor + + return '' +endfunction + +function! ale#handlers#oxlint#GetInitializationOptions(buffer) abort + let l:options = ale#Var(a:buffer, 'javascript_oxlint_options') + return l:options +endfunction diff --git a/doc/ale-css.txt b/doc/ale-css.txt index 3fa71f4264..338323109b 100644 --- a/doc/ale-css.txt +++ b/doc/ale-css.txt @@ -56,6 +56,12 @@ them reads `./.fecsrc` as the default configuration file. See: |ale-javascript-fecs|. +=============================================================================== +oxfmt *ale-typescript-oxfmt* + +See |ale-javascript-oxfmt| for information about the available options. + + =============================================================================== prettier *ale-css-prettier* diff --git a/doc/ale-graphql.txt b/doc/ale-graphql.txt index 5a1e096f60..7f454aa473 100644 --- a/doc/ale-graphql.txt +++ b/doc/ale-graphql.txt @@ -19,6 +19,12 @@ You will need the GraphQL ESLint plugin installed for this to work. =============================================================================== gqlint *ale-graphql-gqlint* +=============================================================================== +oxfmt *ale-typescript-oxfmt* + +See |ale-javascript-oxfmt| for information about the available options. + + =============================================================================== prettier *ale-graphql-prettier* diff --git a/doc/ale-javascript.txt b/doc/ale-javascript.txt index ed67c2d4d6..d3ce3a75cb 100644 --- a/doc/ale-javascript.txt +++ b/doc/ale-javascript.txt @@ -255,6 +255,64 @@ g:ale_javascript_jshint_use_global See |ale-integrations-local-executables| +=============================================================================== +oxfmt *ale-javascript-oxfmt* + + *ale-options.javascript_oxfmt_executable* + *g:ale_javascript_oxfmt_executable* + *b:ale_javascript_oxfmt_executable* +javascript_oxfmt_executable +g:ale_javascript_oxfmt_executable + Type: |String| + Default: `'oxfmt'` + + See |ale-integrations-local-executables| + + *ale-options.javascript_oxfmt_options* + *g:ale_javascript_oxfmt_options* + *b:ale_javascript_oxfmt_options* +javascript_oxfmt_options +g:ale_javascript_oxfmt_options + Type: |String| + Default: `''` + + This variable can be set to pass additional options to oxfmt. + + +=============================================================================== +oxlint *ale-javascript-oxlint* + + *ale-options.javascript_oxlint_executable* + *g:ale_javascript_oxlint_executable* + *b:ale_javascript_oxlint_executable* +javascript_oxlint_executable +g:ale_javascript_oxlint_executable + Type: |String| + Default: `'oxlint'` + + See |ale-integrations-local-executables| + + *ale-options.javascript_oxlint_options* + *g:ale_javascript_oxlint_options* + *b:ale_javascript_oxlint_options* +javascript_oxlint_options +g:ale_javascript_oxlint_options + Type: |String| + Default: `''` + + This variable can be set to pass additional options to oxlint. + + *ale-options.javascript_oxlint_use_global* + *g:ale_javascript_oxlint_use_global* + *b:ale_javascript_oxlint_use_global* +javascript_oxlint_use_global +g:ale_javascript_oxlint_use_global + Type: |Number| + Default: `get(g:, 'ale_use_global_executables', 0)` + + See |ale-integrations-local-executables| + + =============================================================================== prettier *ale-javascript-prettier* diff --git a/doc/ale-json.txt b/doc/ale-json.txt index 1e9a0f6517..4de37e2044 100644 --- a/doc/ale-json.txt +++ b/doc/ale-json.txt @@ -190,6 +190,12 @@ g:ale_json_jq_filters This option can be changed to pass custom filters to `jq`. +=============================================================================== +oxfmt *ale-typescript-oxfmt* + +See |ale-javascript-oxfmt| for information about the available options. + + =============================================================================== prettier *ale-json-prettier* diff --git a/doc/ale-json5.txt b/doc/ale-json5.txt index bafa60d176..716c9701a1 100644 --- a/doc/ale-json5.txt +++ b/doc/ale-json5.txt @@ -11,5 +11,11 @@ The `eslint` linter for JSON uses the JavaScript options for `eslint`; see: You will need a JSON5 ESLint plugin installed for this to work. +=============================================================================== +oxfmt *ale-typescript-oxfmt* + +See |ale-javascript-oxfmt| for information about the available options. + + =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale-less.txt b/doc/ale-less.txt index ca02d056e4..871f349499 100644 --- a/doc/ale-less.txt +++ b/doc/ale-less.txt @@ -42,6 +42,12 @@ g:ale_less_lessc_use_global See |ale-integrations-local-executables| +=============================================================================== +oxfmt *ale-typescript-oxfmt* + +See |ale-javascript-oxfmt| for information about the available options. + + =============================================================================== prettier *ale-less-prettier* diff --git a/doc/ale-scss.txt b/doc/ale-scss.txt index 337bc80dc3..9af27edb8d 100644 --- a/doc/ale-scss.txt +++ b/doc/ale-scss.txt @@ -8,6 +8,12 @@ dprint *ale-scss-dprint* See |ale-dprint-options| and https://dprint.dev/plugins/malva/. +=============================================================================== +oxfmt *ale-typescript-oxfmt* + +See |ale-javascript-oxfmt| for information about the available options. + + =============================================================================== prettier *ale-scss-prettier* diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index f8711d89b6..72d3a95c1d 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -143,6 +143,7 @@ Notes: * `csslint` * dprint * `fecs` + * `oxfmt` * `prettier` * `stylelint` * Cucumber @@ -265,6 +266,7 @@ Notes: * dprint * `eslint` * `gqlint` + * `oxfmt` * `prettier` * Groovy * `npm-groovy-lint` @@ -354,6 +356,8 @@ Notes: * `flow` * `jscs` * `jshint` + * `oxfmt` + * `oxlint` * `prettier` * `prettier-eslint` * `prettier-standard` @@ -375,6 +379,7 @@ Notes: * `jq` * `json.tool` * `jsonlint` + * `oxfmt` * `prettier` * `spectral` * JSON5 @@ -409,6 +414,7 @@ Notes: * Less * dprint * `lessc` + * `oxfmt` * `prettier` * `stylelint` * LilyPond @@ -687,6 +693,7 @@ Notes: * `scalastyle` * SCSS * dprint + * `oxfmt` * `prettier` * `sass-lint` * `scss-lint` @@ -754,6 +761,7 @@ Notes: * `thriftcheck` * TOML * `dprint` + * `oxfmt` * `tombi` * Twig * `dprint` @@ -764,6 +772,8 @@ Notes: * `dprint` * `eslint` * `fecs` + * `oxfmt` + * `oxlint` * `prettier` * `standard` * `tslint` @@ -820,6 +830,7 @@ Notes: * `circleci`!! * `dprint` * `gitlablint` + * `oxfmt` * `prettier` * `spectral` * `swaglint` diff --git a/doc/ale-toml.txt b/doc/ale-toml.txt index a5049e86b8..95a3cb5baa 100644 --- a/doc/ale-toml.txt +++ b/doc/ale-toml.txt @@ -8,6 +8,12 @@ dprint *ale-toml-dprint* See |ale-dprint-options| and https://dprint.dev/plugins/toml/. +=============================================================================== +oxfmt *ale-typescript-oxfmt* + +See |ale-javascript-oxfmt| for information about the available options. + + =============================================================================== tombi *ale-toml-tombi* diff --git a/doc/ale-typescript.txt b/doc/ale-typescript.txt index 4d727c7f38..d87ed108cb 100644 --- a/doc/ale-typescript.txt +++ b/doc/ale-typescript.txt @@ -137,6 +137,18 @@ the two languages are, the `eslint` linter for TypeScript uses the JavaScript options for `eslint` too. See: |ale-javascript-eslint|. +=============================================================================== +oxfmt *ale-typescript-oxfmt* + +See |ale-javascript-oxfmt| for information about the available options. + + +=============================================================================== +oxlint *ale-typescript-oxlint* + +See |ale-javascript-oxlint| for information about the available options. + + =============================================================================== prettier *ale-typescript-prettier* diff --git a/doc/ale-yaml.txt b/doc/ale-yaml.txt index 2b5fd6fd2d..9945c11328 100644 --- a/doc/ale-yaml.txt +++ b/doc/ale-yaml.txt @@ -79,6 +79,12 @@ dprint *ale-yaml-dprint* See |ale-dprint-options| and https://dprint.dev/plugins/pretty_yaml/. +=============================================================================== +oxfmt *ale-typescript-oxfmt* + +See |ale-javascript-oxfmt| for information about the available options. + + =============================================================================== prettier *ale-yaml-prettier* diff --git a/test/fixers/test_oxfmt_fixer_callback.vader b/test/fixers/test_oxfmt_fixer_callback.vader new file mode 100644 index 0000000000..ae5c283f5f --- /dev/null +++ b/test/fixers/test_oxfmt_fixer_callback.vader @@ -0,0 +1,25 @@ +Before: + Save g:ale_sql_oxfmt_executable + Save g:ale_sql_oxfmt_options + +After: + Restore + +Execute(The oxfmt callback should return the correct default values): + AssertEqual + \ { + \ 'command': ale#Escape('oxfmt') + \ }, + \ ale#fixers#oxfmt#Fix(bufnr('')) + +Execute(The oxfmt executable and options should be configurable): + let g:ale_sql_oxfmt_executable = '/path/to/sqlfmt' + let g:ale_sql_oxfmt_options = '--write' + + AssertEqual + \ { + \ 'command': ale#Escape('/path/to/oxfmt') + \ . ' -w' + \ . ' -write', + \ }, + \ ale#fixers#oxfmt#Fix(bufnr(''))