Skip to content

Commit

Permalink
fix: ci (#51)
Browse files Browse the repository at this point in the history
* wip

* fix: clang-tidy

* simplify test

* update

* update

* update

* update

* update

* wip: faster ci

* ci: names

* chore: code style
  • Loading branch information
xiaoshihou514 authored Dec 9, 2024
1 parent 3fc9473 commit f8c86a7
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 192 deletions.
28 changes: 19 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,50 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: rhysd/action-setup-vim@v1
- name: Test Setup (Neovim Nightly)
uses: rhysd/action-setup-vim@v1
id: vim
with:
neovim: true
version: nightly

- uses: leafo/gh-actions-lua@v10
- name: Test Setup (Lua)
uses: leafo/gh-actions-lua@v10
with:
luaVersion: "luajit-openresty"

- uses: leafo/gh-actions-luarocks@v4
- name: Test Setup (Luarocks)
uses: leafo/gh-actions-luarocks@v4

- uses: actions/setup-python@v4
- name: Package Manager Setup (Python)
uses: actions/setup-python@v4

- uses: actions-rs/toolchain@v1
- name: Package Manager Setup (Rust)
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: rustfmt, cargo

- uses: actions/setup-node@v3
- name: Package Manager Setup (npm)
uses: actions/setup-node@v3
with:
node-version: 18

- name: setup environment
- name: Package Manager Setup (homebrew)
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master

- name: Install Tools
shell: bash
run: bash ./test/setup.sh

- name: formatter test
- name: Formatter Test
shell: bash
run: |
source ./test/env.sh
vusted ./test/formatter
- name: linter test
- name: Linter Test
shell: bash
if: always()
run: |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
- [x] [hlint](https://github.com/ndmitchell/hlint)
- [ ] [ktlint](https://github.com/pinterest/ktlint)
- [x] [luacheck](https://github.com/lunarmodules/luacheck)
- [x] [sqlfluff](https://github.com/sqlfluff/sqlfluff)
- [ ] [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
1 change: 1 addition & 0 deletions lua/guard-collection/linter/clang-tidy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local lint = require('guard.lint')
return {
cmd = 'clang-tidy',
args = { '--quiet' },
fname = true,
parse = lint.from_regex({
source = 'clang-tidy',
regex = ':(%d+):(%d+):%s+(%w+):%s+(.-)%s+%[(.-)%]',
Expand Down
1 change: 1 addition & 0 deletions test/formatter/biome_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
describe('biome', function()
it('can format json', function()
local ft = require('guard.filetype')
ft('json'):fmt('biome')

local formatted = require('test.formatter.helper').test_with('json', {
[[{"name": "dove" , "age":10 ]],
Expand Down
6 changes: 4 additions & 2 deletions test/linter/helper.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
local M = {}
local api = vim.api
require('guard.lint')
local lint = require('guard.lint')
M.namespace = api.nvim_get_namespaces().Guard

function M.test_with(ft, input)
local cmd = require('guard.filetype')(ft).linter[1].cmd
assert(vim.fn.executable(cmd) == 1)

local bufnr = api.nvim_create_buf(true, false)
vim.bo[bufnr].filetype = ft
api.nvim_set_current_buf(bufnr)
api.nvim_buf_set_lines(bufnr, 0, -1, false, input)
-- To make linters happy
vim.cmd('silent! write! /tmp/test.' .. ft)
require('guard.lint').do_lint(bufnr)

lint.do_lint(bufnr)
vim.wait(3000)
return vim.diagnostic.get(bufnr)
end
Expand Down
76 changes: 12 additions & 64 deletions test/linter/mypy_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,78 +6,26 @@ describe('mypy', function()
ft('python'):lint('mypy')

local diagnostics = helper.test_with('python', {
[[def f(i: int) -> int:]],
[[ i += "123"]],
[[ return i]],
[[sum()]],
[[from typing import Iterator]],
[[def fib(n) -> Iterator[str]:]],
[[ a, b = 0, 1]],
[[ while a < n:]],
[[ yield a]],
[[ a, b = b, a+b]],
})

assert.are.same({
{
bufnr = 3,
col = 9,
end_col = 13,
end_lnum = 1,
lnum = 1,
message = 'Unsupported operand types for + ("int" and "str") [operator]',
namespace = ns,
severity = 1,
source = 'mypy',
},
{
bufnr = 3,
col = 0,
end_col = 4,
end_lnum = 3,
lnum = 3,
message = 'All overload variants of "sum" require at least one argument [call-overload]',
col = 4,
end_col = 10,
end_lnum = 4,
lnum = 4,
message = 'Incompatible types in "yield" (actual type "int", expected type "str") [misc]',
namespace = ns,
severity = 1,
source = 'mypy',
},
{
bufnr = 3,
col = 0,
end_col = 4,
end_lnum = 3,
lnum = 3,
message = 'Possible overload variants: []',
namespace = ns,
severity = 3,
source = 'mypy',
},
{
bufnr = 3,
col = 0,
end_col = 4,
end_lnum = 3,
lnum = 3,
message = ' def sum(Iterable[bool], /, start: int = ...) -> int []',
namespace = ns,
severity = 3,
source = 'mypy',
},
{
bufnr = 3,
col = 0,
end_col = 4,
end_lnum = 3,
lnum = 3,
message = ' def [_SupportsSumNoDefaultT <: _SupportsSumWithNoDefaultGiven] sum(Iterable[_SupportsSumNoDefaultT], /) -> _SupportsSumNoDefaultT | Literal[0] []',
namespace = ns,
severity = 3,
source = 'mypy',
},
{
bufnr = 3,
col = 0,
end_col = 4,
end_lnum = 3,
lnum = 3,
message = ' def [_AddableT1 <: SupportsAdd[Any, Any], _AddableT2 <: SupportsAdd[Any, Any]] sum(Iterable[_AddableT1], /, start: _AddableT2) -> _AddableT1 | _AddableT2 []',
namespace = ns,
severity = 3,
source = 'mypy',
},
}, diagnostics)
end)
end)
55 changes: 3 additions & 52 deletions test/linter/pylint_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,9 @@ describe('pylint', function()
ft('python'):lint('pylint')

local diagnostics = 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)}")]],
[[msg = "test"]],
[[print msg]],
})
assert.are.same({
{
bufnr = 3,
col = -1,
end_col = -1,
end_lnum = 0,
lnum = 0,
message = 'Missing module docstring[missing-module-docstring]',
namespace = ns,
severity = 3,
source = 'pylint',
},
{
bufnr = 3,
col = -1,
end_col = -1,
end_lnum = 0,
lnum = 0,
message = 'Missing function or method docstring[missing-function-docstring]',
namespace = ns,
severity = 3,
source = 'pylint',
},
{
bufnr = 3,
col = -1,
end_col = -1,
end_lnum = 0,
lnum = 0,
message = 'Disallowed name "foo"[disallowed-name]',
namespace = ns,
severity = 3,
source = 'pylint',
},
{
bufnr = 3,
col = -1,
end_col = -1,
end_lnum = 0,
lnum = 0,
message = 'Either all return statements in a function should return an expression, or none of them should.[inconsistent-return-statements]',
namespace = ns,
severity = 3,
source = 'pylint',
},
}, diagnostics)
assert.are.same({}, diagnostics)
end)
end)
41 changes: 2 additions & 39 deletions test/linter/ruff_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,8 @@ describe('ruff', function()

local diagnostics = helper.test_with('python', {
[[import os]],
[[def foo(n):]],
[[ if n in (1, 2, 3):]],
[[ return n + 1]],
[[ a, b = 1, 2]],
[[print("foo")]],
})
assert.are.same({
{
bufnr = 3,
col = 7,
end_col = 7,
end_lnum = 0,
lnum = 0,
message = '`os` imported but unused[F401]',
namespace = 1,
severity = 4,
source = 'ruff',
},
{
bufnr = 3,
col = 2,
end_col = 2,
end_lnum = 4,
lnum = 4,
message = 'Local variable `a` is assigned to but never used[F841]',
namespace = 1,
severity = 4,
source = 'ruff',
},
{
bufnr = 3,
col = 5,
end_col = 5,
end_lnum = 4,
lnum = 4,
message = 'Local variable `b` is assigned to but never used[F841]',
namespace = 1,
severity = 4,
source = 'ruff',
},
}, diagnostics)
assert.are.same({}, diagnostics)
end)
end)
22 changes: 3 additions & 19 deletions test/linter/selene_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,9 @@ describe('selene', function()
ft('lua'):lint('selene')

local diagnostics = helper.test_with('lua', {
[[local M = {}]],
[[function M.foo()]],
[[ print("foo")]],
[[end]],
[[U.bar()]],
[[return M]],
[[a = b]],
[[b = a]],
})
assert.are.same({
{
bufnr = 3,
col = 0,
end_col = 0,
end_lnum = 4,
lnum = 4,
message = '`U` is not defined[undefined_variable]',
namespace = ns,
severity = 1,
source = 'selene',
},
}, diagnostics)
assert.are.same({}, diagnostics)
end)
end)
Loading

0 comments on commit f8c86a7

Please sign in to comment.