Skip to content

Commit

Permalink
chore(ci): adding base ci and fixing linting problems
Browse files Browse the repository at this point in the history
  • Loading branch information
wllfaria committed Aug 16, 2024
1 parent e5b06b2 commit f1ebdc2
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 15 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Tests

on: [push, pull_request]

jobs:
unit_tests:
name: unit tests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-22.04
rev: nightly/nvim-linux64.tar.gz
- os: ubuntu-22.04
rev: v0.9.0/nvim-linux64.tar.gz
steps:
- uses: actions/checkout@v4
- uses: extractions/setup-just@v2
- run: date +%F > todays-date
- name: Restore from todays cache
uses: actions/cache@v3
with:
path: _neovim
key: ${{ runner.os }}-${{ matrix.rev }}-${{ hashFiles('todays-date') }}

- name: Prepare
run: |
test -d _neovim || {
mkdir -p _neovim
curl -sL "https://github.com/neovim/neovim/releases/download/${{ matrix.rev }}" | tar xzf - --strip-components=1 -C "${PWD}/_neovim"
}
- name: Dependencies
run: |
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim
git clone --depth 1 https://github.com/nvim-treesitter/nvim-treesitter ~/.local/share/nvim/site/pack/vendor/start/nvim-treesitter
git clone --depth 1 https://github.com/hrsh7th/nvim-cmp ~/.local/share/nvim/site/pack/vendor/start/nvim-cmp
git clone --depth 1 https://github.com/L3MON4D3/LuaSnip ~/.local/share/nvim/site/pack/vendor/start/LuaSnip
ln -s "$(pwd)" ~/.local/share/nvim/site/pack/vendor/start
- name: Run tests
run: |
export PATH="${PWD}/_neovim/bin:${PATH}"
nvim --version
just test
26 changes: 26 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Format

on: [push, pull_request]

jobs:
format:
name: Stylua
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: date +%W > weekly

- name: Restore cache
id: cache
uses: actions/cache@v2
with:
path: |
~/.cargo/bin
key: ${{ runner.os }}-cargo-${{ hashFiles('weekly') }}

- name: Install
if: steps.cache.outputs.cache-hit != 'true'
run: cargo install stylua

- name: Format
run: stylua --check lua/ --config-path=stylua.toml
17 changes: 17 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Lint

on: [push, pull_request]

jobs:
lint:
name: Luacheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup
run: |
sudo apt-get update
sudo apt-get install luarocks -y
sudo luarocks install luacheck
- name: Lint
run: luacheck lua/ --globals vim
4 changes: 2 additions & 2 deletions lua/ledger/completion/cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ function M.new()
return setmetatable({}, LedgerCmp)
end

function LedgerCmp:is_available()
function LedgerCmp.is_available()
return common.is_available()
end

--- optional function for debugging purposed that nvim-cmp allows us to
--- specify
---
---@return string
function LedgerCmp:get_debug_name()
function LedgerCmp.get_debug_name()
return "ledger.nvim"
end

Expand Down
8 changes: 2 additions & 6 deletions lua/ledger/diagnostics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ function M.get_missing_accounts()
for filename, postings in pairs(context.postings) do
for _, posting in pairs(postings) do
local account_name = posting.account.text
local has_commodity = false

for _, accounts in pairs(context.accounts) do
has_commodity = vim.tbl_contains(accounts, account_name)
if has_commodity then
if vim.tbl_contains(accounts, account_name) then
goto continue
end
end
Expand Down Expand Up @@ -63,11 +61,9 @@ function M.get_missing_commodities()
end

local commodity_name = posting.commodity.text
local has_commodity = false

for _, commodities in pairs(context.commodities) do
has_commodity = vim.tbl_contains(commodities, commodity_name)
if has_commodity then
if vim.tbl_contains(commodities, commodity_name) then
goto continue
end
end
Expand Down
8 changes: 4 additions & 4 deletions lua/ledger/logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,26 @@ end
---
--- @param level string
--- @return string
function LedgerLogger:get_prefix(level)
function LedgerLogger.get_prefix(level)
local timestamp = os.date("%Y-%m-%d %H:%M:%S")
return "[" .. timestamp .. "] " .. level .. " "
end

--- @param message string
function LedgerLogger:info(message)
local prefix = self:get_prefix("[INFO]")
local prefix = self.get_prefix("[INFO]")
self:log(prefix .. message .. "\n")
end

--- @param message string
function LedgerLogger:error(message)
local prefix = self:get_prefix("[ERROR]")
local prefix = self.get_prefix("[ERROR]")
self:log(prefix .. message .. "\n")
end

--- @param message string
function LedgerLogger:warn(message)
local prefix = self:get_prefix("[WARN]")
local prefix = self.get_prefix("[WARN]")
self:log(prefix .. message .. "\n")
end

Expand Down
3 changes: 0 additions & 3 deletions lua/ledger/snippets/cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ local template_converter = require("ledger.snippets.template_converter")
--- @class CmpSnippetCompletionSource
local M = {}

local LedgerSnippetCmpSource = {}
LedgerSnippetCmpSource.__index = LedgerSnippetCmpSource

--- @param snippets ledger.SnippetList
--- @return lsp.CompletionItem[]
function M.new(snippets)
Expand Down

0 comments on commit f1ebdc2

Please sign in to comment.