summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/dotnet_format.vim18
-rw-r--r--doc/ale-cs.txt33
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale.txt1
-rw-r--r--supported-tools.md1
-rw-r--r--test/fixers/test_dotnet_format_fixer_callback.vader41
7 files changed, 100 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 15a6632d..975d02f6 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -396,6 +396,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['dart'],
\ 'description': 'Fix Dart files with dart format.',
\ },
+\ 'dotnet-format': {
+\ 'function': 'ale#fixers#dotnet_format#Fix',
+\ 'suggested_filetypes': ['cs'],
+\ 'description': 'Fix C# files with dotnet format.',
+\ },
\ 'xmllint': {
\ 'function': 'ale#fixers#xmllint#Fix',
\ 'suggested_filetypes': ['xml'],
diff --git a/autoload/ale/fixers/dotnet_format.vim b/autoload/ale/fixers/dotnet_format.vim
new file mode 100644
index 00000000..b44a28bd
--- /dev/null
+++ b/autoload/ale/fixers/dotnet_format.vim
@@ -0,0 +1,18 @@
+" Author: ghsang <gwonhyuksang@gmail.com>
+" Description: Integration of dotnet format with ALE.
+
+call ale#Set('cs_dotnet_format_executable', 'dotnet')
+call ale#Set('cs_dotnet_format_options', '')
+
+function! ale#fixers#dotnet_format#Fix(buffer) abort
+ let l:executable = ale#Var(a:buffer, 'cs_dotnet_format_executable')
+ let l:options = ale#Var(a:buffer, 'cs_dotnet_format_options')
+
+ return {
+ \ 'command': ale#Escape(l:executable)
+ \ . ' format'
+ \ . (empty(l:options) ? '' : ' ' . l:options)
+ \ . ' --folder --include %t "$(dirname %t)"',
+ \ 'read_temporary_file': 1,
+ \}
+endfunction
diff --git a/doc/ale-cs.txt b/doc/ale-cs.txt
index bb13863f..bef495b9 100644
--- a/doc/ale-cs.txt
+++ b/doc/ale-cs.txt
@@ -91,6 +91,39 @@ g:ale_cs_csc_assemblies *g:ale_cs_csc_assemblies*
<
===============================================================================
+dotnet-format *ale-cs-dotnet-format*
+
+Installation
+-------------------------------------------------------------------------------
+
+Installing .NET SDK should probably ensure that `dotnet` is in your `$PATH`.
+For .NET 6 the `dotnet format` tool is already included in the .NET SDK. For
+.NET 5 or below you will have to manually install it using the instructions
+from listed in this repository: https://github.com/dotnet/format
+
+
+Options
+-------------------------------------------------------------------------------
+
+g:ale_cs_dotnet_format_executable *g:ale_cs_dotnet_format_executable*
+ *b:ale_cs_dotnet_format_executable*
+ Type: |String|
+ Default: `'dotnet'`
+
+ This variable can be set to specify an absolute path to the
+ `dotnet` executable (or to specify an alternate executable).
+
+
+g:ale_cs_dotnet_format_options *g:ale_cs_dotnet_format_options*
+ *b:ale_cs_dotnet_format_options*
+ Type: |String|
+ Default: `''`
+
+ This variable can be set to pass additional options to the `dotnet format`
+ fixer.
+
+
+===============================================================================
mcs *ale-cs-mcs*
The `mcs` linter looks only for syntax errors while you type. See
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index db67b593..ba2d2255 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -66,6 +66,7 @@ Notes:
* `uncrustify`
* C#
* `csc`!!
+ * `dotnet-format`
* `mcs`
* `mcsc`!!
* `uncrustify`
diff --git a/doc/ale.txt b/doc/ale.txt
index c2a1b01e..351c34ce 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -2681,6 +2681,7 @@ documented in additional help files.
uncrustify............................|ale-cpp-uncrustify|
c#......................................|ale-cs-options|
csc...................................|ale-cs-csc|
+ dotnet-format.........................|ale-cs-dotnet-format|
mcs...................................|ale-cs-mcs|
mcsc..................................|ale-cs-mcsc|
uncrustify............................|ale-cs-uncrustify|
diff --git a/supported-tools.md b/supported-tools.md
index b8db6ffb..4de9328c 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -75,6 +75,7 @@ formatting.
* [uncrustify](https://github.com/uncrustify/uncrustify)
* C#
* [csc](http://www.mono-project.com/docs/about-mono/languages/csharp/) :floppy_disk: see:`help ale-cs-csc` for details and configuration
+ * [dotnet-format](https://github.com/dotnet/format)
* [mcs](http://www.mono-project.com/docs/about-mono/languages/csharp/) see:`help ale-cs-mcs` for details
* [mcsc](http://www.mono-project.com/docs/about-mono/languages/csharp/) :floppy_disk: see:`help ale-cs-mcsc` for details and configuration
* [uncrustify](https://github.com/uncrustify/uncrustify)
diff --git a/test/fixers/test_dotnet_format_fixer_callback.vader b/test/fixers/test_dotnet_format_fixer_callback.vader
new file mode 100644
index 00000000..a3993573
--- /dev/null
+++ b/test/fixers/test_dotnet_format_fixer_callback.vader
@@ -0,0 +1,41 @@
+Before:
+ Save g:ale_cs_dotnet_format_executable
+ Save g:ale_cs_dotnet_format_options
+
+ " Use an invalid global executable, so we don't match it.
+ let g:ale_cs_dotnet_format_executable = 'xxxinvalid'
+ let g:ale_cs_dotnet_format_options = ''
+
+ call ale#test#SetDirectory('/testplugin/test/fixers')
+
+After:
+ Restore
+
+ call ale#test#RestoreDirectory()
+
+Execute(The dotnet format callback should return the correct default values):
+ call ale#test#SetFilename('../test-files/cs/testfile.cs')
+
+ AssertEqual
+ \ {
+ \ 'read_temporary_file': 1,
+ \ 'command': ale#Escape('xxxinvalid')
+ \ . ' format'
+ \ . ' --folder --include %t "$(dirname %t)"',
+ \ },
+ \ ale#fixers#dotnet_format#Fix(bufnr(''))
+
+Execute(The dotnet format callback should include custom dotnet format options):
+ let g:ale_cs_dotnet_format_options = "-l 80"
+ call ale#test#SetFilename('../test-files/cs/testfile.cs')
+
+ AssertEqual
+ \ {
+ \ 'read_temporary_file': 1,
+ \ 'command': ale#Escape('xxxinvalid')
+ \ . ' format'
+ \ . ' ' . g:ale_cs_dotnet_format_options
+ \ . ' --folder --include %t "$(dirname %t)"',
+ \ },
+ \ ale#fixers#dotnet_format#Fix(bufnr(''))
+