chore(ci): lint with StyLua and Luacheck (+ fix image.lua bugs)#27
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
StyLua と Luacheck による lint を導入する。導入過程で Luacheck が検出した
image.luaの実バグ 2 件も修正した。追加した lint 基盤
.luacheckrc— LuaJIT/Neovim 前提の設定(std=luajit、vim/Snacksglobals、vim.bo等への書き込み許可、行長は StyLua 任せ、tests/は未使用/shadow/モックを緩和、fixtures/除外)。リポジトリ全体で 0 warnings / 0 errors。.pre-commit-config.yaml— StyLua のみ(stylua-github, リリースバイナリを自前 DL するのでローカル依存ゼロ・staged ファイルを自動整形)。.github/workflows/lint.yml—stylua --checkと Luacheck(docker イメージ)の 2 ジョブを push / PR で実行。Makefile—format/lint/checkターゲットを追加。Luacheck を pre-commit に入れず CI 専用にしたのは、配布物が全ローカル環境で素直に動かないため(
language:luaは Lua 5.5 でビルド不可、Docker イメージは amd64 のみ)。CI ランナー (amd64) では docker イメージがそのまま動く。修正した実バグ (
lua/md-render/image.lua)reset_cache()の状態リセット不全 —_convert_cmd/_anim_cmd/_image_id/_session_cleared等をlocal宣言より前で代入しており、グローバルに書いて実状態をリセットできていなかった。宣言をモジュール先頭へ集約。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