Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add flake8 for python lint #9

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

- [x] [clang-tidy](https://clang.llvm.org/extra/clang-tidy/)
- [ ] [codespell](https://github.com/codespell-project/codespell)
- [x] [flake8](https://github.com/PyCQA/flake8)
- [x] [hadolint](https://github.com/hadolint/hadolint)
- [x] [luacheck](https://github.com/lunarmodules/luacheck)
- [x] [pylint](https://github.com/PyCQA/pylint)
Expand Down
18 changes: 18 additions & 0 deletions lua/guard-collection/linter/flake8.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
local lint = require('guard.lint')

return {
cmd = 'flake8',
args = { '--format', 'default', '-', '--stdin-display-name' },
stdin = true,
fname = true,
parse = lint.from_regex({
source = 'flake8',
regex = ':(%d+):(%d+):%s(%a)(%w+) (.+)',
severities = {
E = lint.severities.error,
W = lint.severities.warning,
C = lint.severities.warning,
F = lint.severities.info,
},
}),
}
106 changes: 106 additions & 0 deletions test/linter/flake8_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
describe('flake8', function()
it('can lint', function()
local ft = require('guard.filetype')
ft('python'):lint('flake8')
require('guard').setup()

local diagnostics = require('test.linter.helper').test_with('python', {
[[import os]],
[[]],
[[def foo(n):]],
[[ if n == 0:]],
[[ return bar]],
[[print("it's too long sentence to be displayed in one line, blah blah blah blah")]],
})
assert.are.same({
{
bufnr = 3,
col = 0,
end_col = 0,
end_lnum = 0,
lnum = 0,
message = "'os' imported but unused [401]",
namespace = 4,
severity = 3,
source = 'flake8',
},
{
bufnr = 3,
col = 0,
end_col = 0,
end_lnum = 2,
lnum = 2,
message = 'expected 2 blank lines, found 1 [302]',
namespace = 4,
severity = 1,
source = 'flake8',
},
{
bufnr = 3,
col = 9,
end_col = 9,
end_lnum = 4,
lnum = 4,
message = 'indentation is not a multiple of 4 [111]',
namespace = 4,
severity = 1,
source = 'flake8',
},
{
bufnr = 3,
col = 9,
end_col = 9,
end_lnum = 4,
lnum = 4,
message = 'over-indented [117]',
namespace = 4,
severity = 1,
source = 'flake8',
},
{
bufnr = 3,
col = 15,
end_col = 15,
end_lnum = 4,
lnum = 4,
message = 'multiple spaces after keyword [271]',
namespace = 4,
severity = 1,
source = 'flake8',
},
{
bufnr = 3,
col = 17,
end_col = 17,
end_lnum = 4,
lnum = 4,
message = "undefined name 'bar' [821]",
namespace = 4,
severity = 3,
source = 'flake8',
},
{
bufnr = 3,
col = 0,
end_col = 0,
end_lnum = 5,
lnum = 5,
message = 'expected 2 blank lines after class or function definition, found 0 [305]',
namespace = 4,
severity = 1,
source = 'flake8',
},
{
bufnr = 3,
col = 79,
end_col = 79,
end_lnum = 5,
lnum = 5,
message = 'line too long (80 > 79 characters) [501]',
namespace = 4,
severity = 1,
source = 'flake8',
},
}, diagnostics)
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 yapf &
pip -qqq install autopep8 black djhtml flake8 isort pylint yapf &
npm install -g --silent \
prettier @fsouza/prettierd sql-formatter shellcheck shfmt &
gem install -q rubocop &
Expand Down