diff --git a/README.md b/README.md index cef0d8b..350e2c3 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/lua/guard-collection/linter/flake8.lua b/lua/guard-collection/linter/flake8.lua new file mode 100644 index 0000000..28ab8f4 --- /dev/null +++ b/lua/guard-collection/linter/flake8.lua @@ -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, + }, + }), +} diff --git a/test/linter/flake8_spec.lua b/test/linter/flake8_spec.lua new file mode 100644 index 0000000..7a894b6 --- /dev/null +++ b/test/linter/flake8_spec.lua @@ -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) diff --git a/test/setup.sh b/test/setup.sh index 6a3c714..8800339 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 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 &