From 4083df79694d4a5fb75ab8388755285c38fd1a11 Mon Sep 17 00:00:00 2001 From: Emirhan Pala Date: Wed, 4 Oct 2023 23:25:43 +0300 Subject: [PATCH 1/6] feat: add taplo formatter (#22) --- README.md | 2 +- lua/guard-collection/formatter.lua | 6 ++++++ test/formatter/taplo_spec.lua | 24 ++++++++++++++++++++++++ test/setup.sh | 2 +- 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 test/formatter/taplo_spec.lua diff --git a/README.md b/README.md index cd7c150..1df80ee 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ - [x] [prettier](https://github.com/prettier/prettier) - [ ] [rubocop](https://github.com/rubocop/rubocop) - [x] [rustfmt](https://github.com/rust-lang/rustfmt) +- [x] [taplo](https://github.com/tamasfe/taplo) - [ ] [shfmt](https://github.com/mvdan/sh) - [x] [stylua](https://github.com/JohnnyMorganz/StyLua) - [ ] [swiftformat](https://github.com/nicklockwood/SwiftFormat) @@ -37,7 +38,6 @@ - [x] [ruff](https://github.com/astral-sh/ruff) as `ruff format` - [x] [ruff_fix](https://github.com/astral-sh/ruff) as `ruff --fix` - ## Linters - [x] [clang-tidy](https://clang.llvm.org/extra/clang-tidy/) diff --git a/lua/guard-collection/formatter.lua b/lua/guard-collection/formatter.lua index c66dd9f..8670174 100644 --- a/lua/guard-collection/formatter.lua +++ b/lua/guard-collection/formatter.lua @@ -132,6 +132,12 @@ M.rustfmt = { stdin = true, } +M.taplo = { + cmd = 'taplo', + args = { 'format', '-' }, + stdin = true, +} + M.shfmt = { cmd = 'shfmt', stdin = true, diff --git a/test/formatter/taplo_spec.lua b/test/formatter/taplo_spec.lua new file mode 100644 index 0000000..cc6eb64 --- /dev/null +++ b/test/formatter/taplo_spec.lua @@ -0,0 +1,24 @@ +describe('taplo', function() + it('can format', function() + local ft = require('guard.filetype') + ft('toml'):fmt('taplo') + require('guard').setup() + + local formatted = require('test.formatter.helper').test_with('toml', { + [[ [dependencies] ]], + [[ async-process = "^1.7"]], + [[strum = { version = "^0.25", features = ["derive"] } ]], + [[anyhow = "1" ]], + [[tracing-error = "0.2" ]], + [[]], + [[]] + }) + assert.are.same({ + "[dependencies]", + [[async-process = "^1.7"]], + [[strum = { version = "^0.25", features = ["derive"] }]], + [[anyhow = "1"]], + [[tracing-error = "0.2"]], + }, formatted) + end) +end) diff --git a/test/setup.sh b/test/setup.sh index 45e34b9..afbdb92 100644 --- a/test/setup.sh +++ b/test/setup.sh @@ -10,7 +10,7 @@ luarocks install luacheck & go install github.com/segmentio/golines@latest & pip -qqq install autopep8 black djhtml flake8 isort pylint yapf codespell ruff & npm install -g --silent \ - prettier @fsouza/prettierd sql-formatter shellcheck shfmt & + prettier @fsouza/prettierd sql-formatter shellcheck shfmt @taplo/cli & gem install -q rubocop & # Block, homebrew takes the longest time brew install \ From 057f1a354ded2b7328bbf3d8a4d707702000eba3 Mon Sep 17 00:00:00 2001 From: Kayaba Akihiko Date: Thu, 5 Oct 2023 03:25:51 +0700 Subject: [PATCH 2/6] feat: register eslint_d formatter (#18) --- README.md | 1 + lua/guard-collection/formatter.lua | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/README.md b/README.md index 1df80ee..8967af0 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ - [x] [clang-format](https://www.kernel.org/doc/html/latest/process/clang-format.html) - [ ] [djhtml](https://github.com/rtts/djhtml) - [ ] [dprint](https://dprint.dev/) +- [x] [eslint_d](https://github.com/mantoni/eslint_d.js) - [ ] [fish_indent](https://fishshell.com/docs/current/cmds/fish_indent.html) - [ ] [fnlfmt](https://git.sr.ht/~technomancy/fnlfmt) - [ ] [gofmt](https://pkg.go.dev/cmd/gofmt) diff --git a/lua/guard-collection/formatter.lua b/lua/guard-collection/formatter.lua index 8670174..2f547c0 100644 --- a/lua/guard-collection/formatter.lua +++ b/lua/guard-collection/formatter.lua @@ -43,6 +43,13 @@ M.dprint = { find = { 'dprint.json', 'dprint.jsonc', '.dprint.json', '.dprint.jsonc' }, } +M.eslint_d = { + cmd = 'eslint_d', + args = { '--fix-to-stdout', '--stdin', '--stdin-filename' }, + fname = true, + stdin = true, +} + M.fish_indent = { cmd = 'fish_indent', stdin = true, From 12eba27e595734fb4a118bc4ac730cad30cdaebc Mon Sep 17 00:00:00 2001 From: Kayaba Akihiko Date: Thu, 5 Oct 2023 03:26:09 +0700 Subject: [PATCH 3/6] feat: register dotnet-csharpier formatter (#16) --- README.md | 1 + lua/guard-collection/formatter.lua | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index 8967af0..54860f0 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ - [x] [black](https://github.com/psf/black) - [ ] [cbfmt](https://github.com/lukas-reineke/cbfmt) - [x] [clang-format](https://www.kernel.org/doc/html/latest/process/clang-format.html) +- [x] [csharpier](https://csharpier.com/) - [ ] [djhtml](https://github.com/rtts/djhtml) - [ ] [dprint](https://dprint.dev/) - [x] [eslint_d](https://github.com/mantoni/eslint_d.js) diff --git a/lua/guard-collection/formatter.lua b/lua/guard-collection/formatter.lua index 2f547c0..42f5c5e 100644 --- a/lua/guard-collection/formatter.lua +++ b/lua/guard-collection/formatter.lua @@ -29,6 +29,12 @@ M['clang-format'] = { stdin = true, } +M.csharpier = { + cmd = 'dotnet-csharpier', + args = { '--write-stdout' }, + stdin = true, +} + M.djhtml = { cmd = 'djhtml', args = { '-' }, From 6a2c1433270be01627c38db45729a7637eed21d4 Mon Sep 17 00:00:00 2001 From: xiaoshihou514 <108414369+xiaoshihou514@users.noreply.github.com> Date: Thu, 5 Oct 2023 04:30:05 +0800 Subject: [PATCH 4/6] feat: zigfmt (#23) authored by @fluctlight-kayaba --- README.md | 1 + lua/guard-collection/formatter.lua | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index 54860f0..c3bd1e8 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ - [x] [yapf](https://github.com/google/yapf) - [x] [ruff](https://github.com/astral-sh/ruff) as `ruff format` - [x] [ruff_fix](https://github.com/astral-sh/ruff) as `ruff --fix` +- [ ] [zigfmt](https://github.com/ziglang/zig) ## Linters diff --git a/lua/guard-collection/formatter.lua b/lua/guard-collection/formatter.lua index 42f5c5e..afd32b5 100644 --- a/lua/guard-collection/formatter.lua +++ b/lua/guard-collection/formatter.lua @@ -196,4 +196,10 @@ M.ruff_fix = { fname = true, } +M.zigfmt = { + cmd = 'zig', + args = { 'fmt', '--stdin' }, + stdin = true, +} + return M From e522264a85ccce4b2fb55b1c42f70ac422165b9b Mon Sep 17 00:00:00 2001 From: xiaoshihou514 <108414369+xiaoshihou514@users.noreply.github.com> Date: Thu, 5 Oct 2023 04:33:46 +0800 Subject: [PATCH 5/6] chore: stylua (#24) --- test/formatter/taplo_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/formatter/taplo_spec.lua b/test/formatter/taplo_spec.lua index cc6eb64..3ef911e 100644 --- a/test/formatter/taplo_spec.lua +++ b/test/formatter/taplo_spec.lua @@ -11,10 +11,10 @@ describe('taplo', function() [[anyhow = "1" ]], [[tracing-error = "0.2" ]], [[]], - [[]] + [[]], }) assert.are.same({ - "[dependencies]", + '[dependencies]', [[async-process = "^1.7"]], [[strum = { version = "^0.25", features = ["derive"] }]], [[anyhow = "1"]], From fe5e3d6297a62576fb0701c1b47ddbe611938b12 Mon Sep 17 00:00:00 2001 From: Emirhan Pala Date: Sat, 7 Oct 2023 19:26:52 +0300 Subject: [PATCH 6/6] feat: add sqlfluff linter, formatter (#25) --- README.md | 3 + lua/guard-collection/formatter.lua | 12 +++ lua/guard-collection/linter/init.lua | 1 + lua/guard-collection/linter/sqlfluff.lua | 22 +++++ test/formatter/sqlfluff_fix_spec.lua | 21 +++++ test/formatter/sqlfluff_spec.lua | 24 +++++ test/linter/sqlfluff_spec.lua | 115 +++++++++++++++++++++++ test/setup.sh | 2 +- 8 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 lua/guard-collection/linter/sqlfluff.lua create mode 100644 test/formatter/sqlfluff_fix_spec.lua create mode 100644 test/formatter/sqlfluff_spec.lua create mode 100644 test/linter/sqlfluff_spec.lua diff --git a/README.md b/README.md index c3bd1e8..3c1d28d 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,8 @@ - [x] [stylua](https://github.com/JohnnyMorganz/StyLua) - [ ] [swiftformat](https://github.com/nicklockwood/SwiftFormat) - [ ] [swift-format](https://github.com/apple/swift-format) +- [x] [sqlfluff](https://github.com/sqlfluff/sqlfluff) as `sqlfluff format` +- [x] [sqlfluff_fix](https://github.com/sqlfluff/sqlfluff) as `sqlfluff fix` - [x] [sql-formatter](https://github.com/sql-formatter-org/sql-formatter) - [x] [yapf](https://github.com/google/yapf) - [x] [ruff](https://github.com/astral-sh/ruff) as `ruff format` @@ -51,6 +53,7 @@ - [ ] [hadolint](https://github.com/hadolint/hadolint) - [x] [ktlint](https://github.com/pinterest/ktlint) - [x] [luacheck](https://github.com/lunarmodules/luacheck) +- [x] [sqlfluff](https://github.com/sqlfluff/sqlfluff) - [x] [pylint](https://github.com/PyCQA/pylint) - [ ] [rubocop](https://github.com/rubocop/rubocop) - [x] [selene](https://github.com/Kampfkarren/selene) diff --git a/lua/guard-collection/formatter.lua b/lua/guard-collection/formatter.lua index afd32b5..08866bd 100644 --- a/lua/guard-collection/formatter.lua +++ b/lua/guard-collection/formatter.lua @@ -172,6 +172,18 @@ M['swift-format'] = { stdin = true, } +M.sqlfluff = { + cmd = 'sqlfluff', + args = { 'format', '-' }, + stdin = true, +} + +M.sqlfluff_fix = { + cmd = 'sqlfluff', + args = { 'fix', '-' }, + stdin = true, +} + M['sql-formatter'] = { cmd = 'sql-formatter', stdin = true, diff --git a/lua/guard-collection/linter/init.lua b/lua/guard-collection/linter/init.lua index ffdaa8b..d97886f 100644 --- a/lua/guard-collection/linter/init.lua +++ b/lua/guard-collection/linter/init.lua @@ -7,6 +7,7 @@ return { hadolint = require('guard-collection.linter.hadolint'), ktlint = require('guard-collection.linter.ktlint'), luacheck = require('guard-collection.linter.luacheck'), + sqlfluff = require('guard-collection.linter.sqlfluff'), pylint = require('guard-collection.linter.pylint'), rubocop = require('guard-collection.linter.rubocop'), selene = require('guard-collection.linter.selene'), diff --git a/lua/guard-collection/linter/sqlfluff.lua b/lua/guard-collection/linter/sqlfluff.lua new file mode 100644 index 0000000..b0766cd --- /dev/null +++ b/lua/guard-collection/linter/sqlfluff.lua @@ -0,0 +1,22 @@ +local lint = require('guard.lint') + +return { + cmd = 'sqlfluff', + args = { 'lint', '-f', 'github-annotation' }, + stdin = true, + parse = lint.from_json({ + attributes = { + row = 'line', + col = 'start_column', + end_col = 'end_column', + severity = 'annotation_level', + message = 'message', + }, + severities = { + notice = lint.severities.info, + warning = lint.severities.warning, + error = lint.severities.error, + }, + source = 'sqlfluff', + }), +} diff --git a/test/formatter/sqlfluff_fix_spec.lua b/test/formatter/sqlfluff_fix_spec.lua new file mode 100644 index 0000000..cd1f729 --- /dev/null +++ b/test/formatter/sqlfluff_fix_spec.lua @@ -0,0 +1,21 @@ +describe('sqlfluff_fix', function() + it('can format', function() + local ft = require('guard.filetype') + local tool = ft('sql'):fmt('sqlfluff_fix') + tool.formatter[1].args = vim.list_extend(tool.formatter[1].args, { '--dialect', 'ansi' }) + require('guard').setup() + + local formatted = require('test.formatter.helper').test_with('sql', { + [[SELECT]], + [[ a + b AS foo,]], + [[ c AS bar]], + [[FROM my_table]], + }) + assert.are.same({ + [[SELECT]], + [[ c AS bar,]], + [[ a + b AS foo]], + [[FROM my_table]], + }, formatted) + end) +end) diff --git a/test/formatter/sqlfluff_spec.lua b/test/formatter/sqlfluff_spec.lua new file mode 100644 index 0000000..615f6fd --- /dev/null +++ b/test/formatter/sqlfluff_spec.lua @@ -0,0 +1,24 @@ +describe('sqlfluff', function() + it('can format', function() + local ft = require('guard.filetype') + local tool = ft('sql'):fmt('sqlfluff') + tool.formatter[1].args = vim.list_extend(tool.formatter[1].args,{ '--dialect', 'ansi' }) + require('guard').setup() + + local formatted = require('test.formatter.helper').test_with('sql', { + [[SELECT *]], + [[FROM]], + [[ World ]], + [[WHERE "Someone"]], + [[ LIKE '%YOU%']], + }) + assert.are.same({ + [[SELECT *]], + [[FROM]], + [[ World]], + [[WHERE]], + [[ "Someone"]], + [[ LIKE '%YOU%']], + }, formatted) + end) +end) diff --git a/test/linter/sqlfluff_spec.lua b/test/linter/sqlfluff_spec.lua new file mode 100644 index 0000000..e72591c --- /dev/null +++ b/test/linter/sqlfluff_spec.lua @@ -0,0 +1,115 @@ +describe('sqlfluff', function() + it('can lint', function() + local helper = require('test.linter.helper') + local ft = require('guard.filetype') + local tool = ft('sql'):lint('sqlfluff') + tool.linter[1].args = vim.list_extend(tool.linter[1].args, { '--dialect', 'ansi' }) + require('guard').setup() + + local diagnostics = helper.test_with('sql', { + [[SELECT a+b AS foo,]], + [[c AS bar from my_table]], + }) + assert.are.same({ + { + bufnr = 3, + col = 0, + end_col = 0, + end_lnum = 0, + lnum = 0, + message = 'LT09: Select targets should be on a new line unless there is only one select target. [nil]', + namespace = 1, + severity = 3, + source = 'sqlfluff', + }, + { + bufnr = 3, + col = 0, + end_col = 0, + end_lnum = 0, + lnum = 0, + message = 'ST06: Select wildcards then simple targets before calculations and aggregates. [nil]', + namespace = 1, + severity = 3, + source = 'sqlfluff', + }, + { + bufnr = 3, + col = 6, + end_col = 6, + end_lnum = 0, + lnum = 0, + message = "LT02: Expected line break and indent of 4 spaces before 'a'. [nil]", + namespace = 1, + severity = 3, + source = 'sqlfluff', + }, + { + bufnr = 3, + col = 8, + end_col = 8, + end_lnum = 0, + lnum = 0, + message = "LT01: Expected single whitespace between naked identifier and binary operator '+'. [nil]", + namespace = 1, + severity = 3, + source = 'sqlfluff', + }, + { + bufnr = 3, + col = 9, + end_col = 9, + end_lnum = 0, + lnum = 0, + message = "LT01: Expected single whitespace between binary operator '+' and naked identifier. [nil]", + namespace = 1, + severity = 3, + source = 'sqlfluff', + }, + { + bufnr = 3, + col = 10, + end_col = 10, + end_lnum = 0, + lnum = 0, + message = "LT01: Expected only single space before 'AS' keyword. Found ' '. [nil]", + namespace = 1, + severity = 3, + source = 'sqlfluff', + }, + { + bufnr = 3, + col = 0, + end_col = 0, + end_lnum = 1, + lnum = 1, + message = 'LT02: Expected indent of 4 spaces. [nil]', + namespace = 1, + severity = 3, + source = 'sqlfluff', + }, + { + bufnr = 3, + col = 8, + end_col = 8, + end_lnum = 1, + lnum = 1, + message = "LT02: Expected line break and no indent before 'from'. [nil]", + namespace = 1, + severity = 3, + source = 'sqlfluff', + }, + { + bufnr = 3, + col = 9, + end_col = 9, + end_lnum = 1, + lnum = 1, + message = 'CP01: Keywords must be consistently upper case. [nil]', + namespace = 1, + severity = 3, + source = 'sqlfluff', + }, + }, diagnostics) + end) +end) diff --git a/test/setup.sh b/test/setup.sh index afbdb92..75c4cfd 100644 --- a/test/setup.sh +++ b/test/setup.sh @@ -8,7 +8,7 @@ sudo apt-get install -qqq \ clang-format clang-tidy fish elixir & luarocks install luacheck & go install github.com/segmentio/golines@latest & -pip -qqq install autopep8 black djhtml flake8 isort pylint yapf codespell ruff & +pip -qqq install autopep8 black djhtml flake8 isort pylint yapf codespell ruff sqlfluff & npm install -g --silent \ prettier @fsouza/prettierd sql-formatter shellcheck shfmt @taplo/cli & gem install -q rubocop &