Skip to content

Commit

Permalink
feat: add yapf python format (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
gepbird authored Sep 10, 2023
1 parent 26c5c72 commit fdb9b71
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- [ ] [swiftformat](https://github.com/nicklockwood/SwiftFormat)
- [ ] [swift-format](https://github.com/apple/swift-format)
- [x] [sql-formatter](https://github.com/sql-formatter-org/sql-formatter)
- [x] [yapf](https://github.com/google/yapf)

## Linters

Expand Down
6 changes: 6 additions & 0 deletions lua/guard-collection/formatter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,10 @@ M['sql-formatter'] = {
stdin = true,
}

M.yapf = {
cmd = 'yapf',
args = { '--quiet' },
stdin = true,
}

return M
26 changes: 26 additions & 0 deletions test/formatter/yapf_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
describe('yapf', function()
it('can format', function()
local ft = require('guard.filetype')
ft('python'):fmt('yapf')
require('guard').setup()

local formatted = require('test.formatter.helper').test_with('python', {
[[def foo(n):]],
[[ if n in (1,2,3):]],
[[ return n+1]],
[[a, b = 1, 2]],
[[b, a = a, b]],
[[print( f"The factorial of {a} is: {foo(a)}")]],
})
assert.are.same({
[[def foo(n):]],
[[ if n in (1, 2, 3):]],
[[ return n + 1]],
[[]],
[[]],
[[a, b = 1, 2]],
[[b, a = a, b]],
[[print(f"The factorial of {a} is: {foo(a)}")]],
}, formatted)
end)
end)
2 changes: 1 addition & 1 deletion test/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 isort pylint &
pip -qqq install autopep8 black djhtml isort pylint yapf &
npm install -g --silent \
prettier @fsouza/prettierd sql-formatter shellcheck shfmt &
gem install -q rubocop &
Expand Down

0 comments on commit fdb9b71

Please sign in to comment.