-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add stylua & luacheck with pre-commit hooks #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
676212e
53fb7c2
c52df36
35379df
ec426a9
23c8ffb
ccf85df
bf109bc
9f88d21
ab0a161
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # Code quality CI for ghost.nvim | ||
| # Runs stylua formatting check and luacheck linter | ||
|
|
||
| name: Lint | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| lint: | ||
| name: stylua + luacheck | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Install StyLua | ||
| uses: JohnnyMorganz/stylua-action@v4 | ||
| with: | ||
| version: latest | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| args: --check lua | ||
|
|
||
| - name: Install Lua | ||
| uses: leafo/gh-actions-lua@v10 | ||
| with: | ||
| luaVersion: "5.1" | ||
|
|
||
| - name: Install LuaRocks | ||
| uses: leafo/gh-actions-luarocks@v4 | ||
|
|
||
| - name: Install luacheck | ||
| run: luarocks install luacheck | ||
|
|
||
| - name: Run luacheck | ||
| run: luacheck lua |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| -- Luacheck configuration for ghost.nvim | ||
| -- https://luacheck.readthedocs.io/ | ||
|
|
||
| -- Use LuaJIT (Neovim runtime) | ||
| std = "luajit" | ||
|
|
||
| -- Define Neovim globals | ||
| globals = { | ||
| "vim", | ||
| } | ||
|
|
||
| -- Read-only globals (standard Lua + LuaJIT) | ||
| read_globals = { | ||
| "jit", | ||
| "unpack", | ||
| } | ||
|
|
||
| -- Ignore generated/vendor directories | ||
| exclude_files = { | ||
| ".opencode/**", | ||
| "node_modules/**", | ||
| } | ||
|
|
||
| -- Maximum line length (match stylua column_width) | ||
| max_line_length = 120 | ||
|
|
||
| -- Maximum cyclomatic complexity | ||
| max_cyclomatic_complexity = 15 | ||
|
|
||
| -- Warnings configuration | ||
| -- See: https://luacheck.readthedocs.io/en/stable/warnings.html | ||
|
|
||
| -- Allow unused arguments starting with underscore | ||
| unused_args = true | ||
| unused_secondaries = true | ||
|
|
||
| -- Allow self as unused (common in OOP patterns) | ||
| self = false | ||
|
Comment on lines
+37
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment on line 37 indicates the intention to allow unused According to the |
||
|
|
||
| -- Specific file overrides can be added here: | ||
| -- files["lua/ghost/test.lua"] = { ignore = { "212" } } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Pre-commit hooks for ghost.nvim | ||
| # https://pre-commit.com/ | ||
| # | ||
| # Install: pre-commit install | ||
| # Run all: pre-commit run --all-files | ||
| # | ||
| # Prerequisites: stylua, luacheck must be installed locally | ||
|
|
||
| repos: | ||
| - repo: local | ||
| hooks: | ||
| # StyLua formatter - auto-fixes formatting | ||
| # If files are modified, commit will be stopped for re-staging | ||
| - id: stylua | ||
| name: stylua (format) | ||
| entry: stylua | ||
| language: system | ||
| types: [lua] | ||
| args: [] | ||
|
|
||
| # Luacheck linter - blocks on any diagnostics | ||
| - id: luacheck | ||
| name: luacheck (lint) | ||
| entry: luacheck | ||
| language: system | ||
| types: [lua] | ||
| args: ["--no-color"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # StyLua configuration for ghost.nvim | ||
| # https://github.com/JohnnyMorganz/StyLua | ||
|
|
||
| column_width = 120 | ||
| line_endings = "Unix" | ||
| indent_type = "Spaces" | ||
| indent_width = 2 | ||
| quote_style = "AutoPreferDouble" | ||
| call_parentheses = "Always" | ||
|
|
||
| [sort_requires] | ||
| enabled = false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # ghost.nvim Makefile | ||
| # Development tasks for code quality | ||
|
|
||
| .PHONY: all format format-check lint check precommit precommit-install help | ||
|
|
||
| # Default target | ||
| all: check | ||
|
|
||
| # Format all Lua files with stylua | ||
| format: | ||
| @echo "Formatting Lua files..." | ||
| stylua lua | ||
|
|
||
| # Check formatting without modifying files | ||
| format-check: | ||
| @echo "Checking Lua formatting..." | ||
| stylua --check lua | ||
|
|
||
| # Run luacheck linter | ||
| lint: | ||
| @echo "Linting Lua files..." | ||
| luacheck lua | ||
|
|
||
| # Run all checks (format + lint) | ||
| check: format-check lint | ||
| @echo "All checks passed!" | ||
|
|
||
| # Install pre-commit hooks | ||
| precommit-install: | ||
| @echo "Installing pre-commit hooks..." | ||
| pre-commit install | ||
|
|
||
| # Run pre-commit on all files | ||
| precommit: | ||
| @echo "Running pre-commit on all files..." | ||
| pre-commit run --all-files | ||
|
|
||
| # Show help | ||
| help: | ||
| @echo "Available targets:" | ||
| @echo " make format - Format Lua files with stylua" | ||
| @echo " make format-check - Check Lua formatting (no changes)" | ||
| @echo " make lint - Run luacheck linter" | ||
| @echo " make check - Run format-check + lint" | ||
| @echo " make precommit-install - Install pre-commit hooks" | ||
| @echo " make precommit - Run pre-commit on all files" | ||
| @echo " make help - Show this help message" |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,11 +4,12 @@ | |||||
| local M = {} | ||||||
|
|
||||||
| --- Default configuration for Ghost | ||||||
| --- @class GhostConfig | ||||||
| --- @field keybind string Keybind to open the prompt buffer | ||||||
| --- @field backend "opencode"|"codex" Which ACP backend to use | ||||||
| --- @field acp_command string|table Command to run for ACP (default: "opencode"). Table format bypasses "acp" argument for custom scripts. | ||||||
| --- @field acp_cwd string|nil Working directory for ACP subprocess (default: current directory) | ||||||
| --- @class GhostConfig | ||||||
| --- @field keybind string Keybind to open the prompt buffer | ||||||
| --- @field backend "opencode"|"codex" Which ACP backend to use | ||||||
| --- @field acp_command string|table Command to run for ACP (default: "opencode"). | ||||||
| --- Table format bypasses "acp" argument for custom scripts. | ||||||
|
||||||
| --- Table format bypasses "acp" argument for custom scripts. | |
| --- Table format bypasses "acp" argument for custom scripts. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,7 +146,7 @@ end | |
| --- @param bufnr number|nil Buffer number (defaults to current buffer) | ||
| --- @param include_selection boolean|nil Whether to capture visual selection (default false) | ||
| --- @return GhostContext Captured context | ||
| function M.capture(bufnr, include_selection) | ||
| function M.capture(bufnr, include_selection) -- luacheck: ignore 561 | ||
|
||
| -- Safely get buffer number with fallback | ||
| local ok, bufnr_result = pcall(function() | ||
| return bufnr or vim.api.nvim_get_current_buf() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,7 @@ local function check_executable(name, desc, required) | |
| end | ||
| end | ||
|
|
||
| function M.check() | ||
| function M.check() -- luacheck: ignore 561 | ||
|
||
| start("ghost.nvim") | ||
|
|
||
| -- Check Neovim version | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,7 +87,7 @@ end | |
| --- Process an ACP session/update notification | ||
| --- @param update table The update notification params | ||
| --- @param request_id string|nil The request ID | ||
| local function process_session_update(update, request_id) | ||
| local function process_session_update(update, request_id) -- luacheck: ignore 561 | ||
|
||
| state.current_request_id = request_id | ||
|
|
||
| -- Extract ghost_session_id from update (US-009) | ||
|
|
@@ -256,7 +256,7 @@ end | |
| --- @param result table The final result | ||
| --- @param request_id string|nil The request ID | ||
| --- @param ghost_session_id string|nil The ghost session ID | ||
| local function process_completion(result, request_id, ghost_session_id) | ||
| local function process_completion(_result, request_id, ghost_session_id) | ||
| -- Flush any remaining transcript buffer for the correct session (US-009) | ||
| local target_session_id = ghost_session_id | ||
| if not target_session_id then | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cyclomatic complexity threshold is set to 15, but several functions are being suppressed with 'luacheck: ignore 561'. This suggests either the threshold should be raised or those functions should be refactored. Consider reviewing whether 15 is the appropriate threshold or if complex functions warrant refactoring.