Skip to content

chore(ci): lint with StyLua and Luacheck (+ fix image.lua bugs)#27

Merged
delphinus merged 2 commits into
mainfrom
ci/stylua-luacheck
Jul 6, 2026
Merged

chore(ci): lint with StyLua and Luacheck (+ fix image.lua bugs)#27
delphinus merged 2 commits into
mainfrom
ci/stylua-luacheck

Conversation

@delphinus

Copy link
Copy Markdown
Owner

概要

StyLua と Luacheck による lint を導入する。導入過程で Luacheck が検出した image.lua の実バグ 2 件も修正した。

追加した lint 基盤

  • .luacheckrc — LuaJIT/Neovim 前提の設定(std=luajitvim/Snacks globals、vim.bo 等への書き込み許可、行長は StyLua 任せ、tests/ は未使用/shadow/モックを緩和、fixtures/ 除外)。リポジトリ全体で 0 warnings / 0 errors。
  • .pre-commit-config.yaml — StyLua のみ(stylua-github, リリースバイナリを自前 DL するのでローカル依存ゼロ・staged ファイルを自動整形)。
  • .github/workflows/lint.ymlstylua --check と Luacheck(docker イメージ)の 2 ジョブを push / PR で実行。
  • Makefileformat / lint / check ターゲットを追加。

Luacheck を pre-commit に入れず CI 専用にしたのは、配布物が全ローカル環境で素直に動かないため(language:lua は Lua 5.5 でビルド不可、Docker イメージは amd64 のみ)。CI ランナー (amd64) では docker イメージがそのまま動く。

修正した実バグ (lua/md-render/image.lua)

  1. reset_cache() の状態リセット不全_convert_cmd / _anim_cmd / _image_id / _session_cleared 等を local 宣言より前で代入しており、グローバルに書いて実状態をリセットできていなかった。宣言をモジュール先頭へ集約。
  2. transmit_animated() の前方参照get_frames_cache_dir / get_cached_frames を定義より前で呼び、nil グローバル呼び出しで実行時エラーになっていた。前方宣言を追加。

あわせて未使用変数・dead assignment・shadowing・未使用関数を除去(挙動変更なし)。

確認

  • make test 全 11 スイート通過
  • stylua --check . クリーン
  • luacheck .(CI と同一の docker イメージ)で 0 warnings / 0 errors

🤖 Generated with Claude Code

delphinus and others added 2 commits July 7, 2026 00:59
…helpers

Luacheck surfaced two real defects in lua/md-render/image.lua:

- reset_cache() assigned _convert_cmd / _convert_checked / _anim_cmd /
  _anim_checked / _image_id / _session_cleared before their `local`
  declarations, so it wrote to globals and never reset the real module
  state. Hoist those declarations to module scope.
- transmit_animated() called get_frames_cache_dir / get_cached_frames before
  their `local function` definitions, so the names resolved to nil globals
  and errored at runtime. Add forward declarations.

Also drop dead locals/assignments and one unused helper flagged by luacheck
in content_builder, display_utils, markdown, markdown_table, preview, tty
and wrap. No behavior change for those.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a Luacheck config (.luacheckrc) tuned for the LuaJIT/Neovim runtime, a
pre-commit hook running StyLua (downloads its own binary, auto-formats staged
files), and a Lint CI workflow running `stylua --check` and Luacheck on every
push / PR. Luacheck is CI-only because its distribution does not run cleanly
on all local setups (language:lua fails under Lua 5.5; the Docker image is
amd64-only). Add Makefile format / lint / check targets.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@delphinus delphinus merged commit 961439b into main Jul 6, 2026
8 checks passed
@delphinus delphinus deleted the ci/stylua-luacheck branch July 6, 2026 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant