Skip to content

Commit

Permalink
Merge branch 'main' into add-gofumpt
Browse files Browse the repository at this point in the history
  • Loading branch information
rcholla authored Oct 7, 2023
2 parents 8d14894 + fe5e3d6 commit cf1fa6e
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 4 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
- [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)
- [ ] [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)
Expand All @@ -29,15 +31,18 @@
- [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)
- [ ] [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`
- [x] [ruff_fix](https://github.com/astral-sh/ruff) as `ruff --fix`

- [ ] [zigfmt](https://github.com/ziglang/zig)

## Linters

Expand All @@ -49,6 +54,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)
Expand Down
37 changes: 37 additions & 0 deletions lua/guard-collection/formatter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ M['clang-format'] = {
stdin = true,
}

M.csharpier = {
cmd = 'dotnet-csharpier',
args = { '--write-stdout' },
stdin = true,
}

M.djhtml = {
cmd = 'djhtml',
args = { '-' },
Expand All @@ -43,6 +49,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,
Expand Down Expand Up @@ -137,6 +150,12 @@ M.rustfmt = {
stdin = true,
}

M.taplo = {
cmd = 'taplo',
args = { 'format', '-' },
stdin = true,
}

M.shfmt = {
cmd = 'shfmt',
stdin = true,
Expand All @@ -158,6 +177,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,
Expand All @@ -182,4 +213,10 @@ M.ruff_fix = {
fname = true,
}

M.zigfmt = {
cmd = 'zig',
args = { 'fmt', '--stdin' },
stdin = true,
}

return M
1 change: 1 addition & 0 deletions lua/guard-collection/linter/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
22 changes: 22 additions & 0 deletions lua/guard-collection/linter/sqlfluff.lua
Original file line number Diff line number Diff line change
@@ -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',
}),
}
21 changes: 21 additions & 0 deletions test/formatter/sqlfluff_fix_spec.lua
Original file line number Diff line number Diff line change
@@ -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)
24 changes: 24 additions & 0 deletions test/formatter/sqlfluff_spec.lua
Original file line number Diff line number Diff line change
@@ -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)
24 changes: 24 additions & 0 deletions test/formatter/taplo_spec.lua
Original file line number Diff line number Diff line change
@@ -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)
115 changes: 115 additions & 0 deletions test/linter/sqlfluff_spec.lua
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 3 additions & 3 deletions test/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
sudo apt-get install -qqq \
clang-format clang-tidy fish elixir &
luarocks install luacheck &
go install github.com/segmentio/golines@latest mvdan.cc/gofumpt@latest &
pip -qqq install autopep8 black djhtml flake8 isort pylint yapf codespell ruff &
go install github.com/segmentio/golines@latest &
pip -qqq install autopep8 black djhtml flake8 isort pylint yapf codespell ruff sqlfluff &
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 \
Expand Down

0 comments on commit cf1fa6e

Please sign in to comment.