Skip to content

Commit

Permalink
feat: add autopep8 for python format (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
gepbird authored Sep 10, 2023
1 parent 3940bae commit 26c5c72
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 @@ -7,6 +7,7 @@
## Formatters

- `lsp` using `vim.lsp.buf.format`
- [x] [autopep8](https://github.com/hhatto/autopep8)
- [x] [black](https://github.com/psf/black)
- [x] [cbfmt](https://github.com/lukas-reineke/cbfmt)
- [x] [clang-format](https://www.kernel.org/doc/html/latest/process/clang-format.html)
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 @@ -6,6 +6,12 @@ M.lsp = {
end,
}

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

M.black = {
cmd = 'black',
args = { '--quiet', '-' },
Expand Down
26 changes: 26 additions & 0 deletions test/formatter/autopep8_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
describe('autopep8', function()
it('can format', function()
local ft = require('guard.filetype')
ft('python'):fmt('autopep8')
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 black djhtml isort pylint &
pip -qqq install autopep8 black djhtml isort pylint &
npm install -g --silent \
prettier @fsouza/prettierd sql-formatter shellcheck shfmt &
gem install -q rubocop &
Expand Down

0 comments on commit 26c5c72

Please sign in to comment.