Skip to content

Commit 607d18c

Browse files
committed
feat: add stylua code formatting
- Add stylua configuration (stylua.toml) with project-specific settings - Add format and format-check targets to Makefile - Add stylua formatting job to CI workflow - Update README with formatting documentation - Add stylua binary to .gitignore - Apply formatting to all Lua files - All tests passing with consistent code style
1 parent 08587c9 commit 607d18c

29 files changed

Lines changed: 974 additions & 684 deletions

.github/workflows/ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,22 @@ jobs:
9595
eval "$(luarocks path --bin)" || true
9696
luacheck lua/ test/ validate.lua --exclude-files test/plenary.nvim --no-max-line-length || echo "Linting completed with warnings"
9797
98+
format:
99+
runs-on: ubuntu-latest
100+
steps:
101+
- name: Checkout code
102+
uses: actions/checkout@v4
103+
104+
- name: Install stylua
105+
run: |
106+
curl -sL https://github.com/JohnnyMorganz/stylua/releases/latest/download/stylua-linux.zip | funzip > stylua
107+
chmod +x stylua
108+
sudo mv stylua /usr/local/bin/
109+
110+
- name: Check code formatting
111+
run: |
112+
stylua --check lua/ plugin/ test/ validate.lua
113+
98114
build:
99115
runs-on: ubuntu-latest
100116
steps:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ mona_nvim_cache.json
5555
.mona_nvim_cache.json
5656
cache/
5757

58+
# Development tools
59+
stylua
60+
5861
# Temporary files
5962
*.tmp
6063
*.temp

Makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: test test-unit test-integration validate clean lint help
1+
.PHONY: test test-unit test-integration validate clean lint format format-check help
22

33
# Default target
44
help:
@@ -8,6 +8,8 @@ help:
88
@echo " test-integration - Run integration tests only"
99
@echo " validate - Run validation script"
1010
@echo " lint - Run luacheck linting"
11+
@echo " format - Format code with stylua"
12+
@echo " format-check - Check code formatting"
1113
@echo " clean - Clean up test artifacts"
1214

1315
# Run all tests
@@ -44,6 +46,18 @@ lint:
4446
@luacheck lua/ test/ validate.lua --exclude-files test/plenary.nvim --no-max-line-length
4547
@echo "✓ Linting completed"
4648

49+
# Format code with stylua
50+
format:
51+
@echo "Formatting code with stylua..."
52+
@stylua lua/ plugin/ test/ validate.lua
53+
@echo "✓ Code formatting completed"
54+
55+
# Check code formatting
56+
format-check:
57+
@echo "Checking code formatting..."
58+
@stylua --check lua/ plugin/ test/ validate.lua
59+
@echo "✓ Code formatting check completed"
60+
4761
# Clean up test artifacts
4862
clean:
4963
@echo "Cleaning up..."

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,26 @@ make test
250250
make test-unit # Unit tests
251251
make test-integration # Integration tests
252252
make validate # Validation script
253+
make lint # Run luacheck linting
254+
make format # Format code with stylua
255+
make format-check # Check code formatting
253256
make clean # Clean artifacts
254257
```
255258

259+
### Code Formatting
260+
261+
This project uses [stylua](https://github.com/JohnnyMorganz/stylua) for consistent code formatting:
262+
263+
```bash
264+
# Format all Lua files
265+
make format
266+
267+
# Check formatting without making changes
268+
make format-check
269+
```
270+
271+
The formatting configuration is in `stylua.toml`.
272+
256273
## License
257274

258275
MIT License - see [LICENSE](LICENSE) for details.

lua/mona/cache.lua

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local utils = require("mona.utils")
44
-- Cache configuration
55
M.config = {
66
cache_file = nil, -- Will be set in M.get_cache_file()
7-
default_ttl = 300 -- 5 minutes default TTL
7+
default_ttl = 300, -- 5 minutes default TTL
88
}
99

1010
-- Get cache file path
@@ -14,11 +14,11 @@ M.get_cache_file = function()
1414
M.config.cache_file = vim.fn.stdpath("cache") .. "/mona_nvim_cache.json"
1515
else
1616
-- Fallback for testing
17-
local home = (vim and vim.env and vim.env.HOME) or
18-
(vim and vim.env and vim.env.USERPROFILE) or
19-
os.getenv and os.getenv("HOME") or
20-
os.getenv and os.getenv("USERPROFILE") or
21-
"/tmp"
17+
local home = (vim and vim.env and vim.env.HOME)
18+
or (vim and vim.env and vim.env.USERPROFILE)
19+
or os.getenv and os.getenv("HOME")
20+
or os.getenv and os.getenv("USERPROFILE")
21+
or "/tmp"
2222
M.config.cache_file = home .. "/.mona_nvim_cache.json"
2323
end
2424
end
@@ -34,7 +34,7 @@ M.load = function()
3434
if cache_loaded then
3535
return
3636
end
37-
37+
3838
local cache_file = M.get_cache_file()
3939
if vim.fn and vim.fn.filereadable and vim.fn.filereadable(cache_file) == 1 then
4040
local ok, content = pcall(vim.fn.readfile, cache_file)
@@ -46,7 +46,7 @@ M.load = function()
4646
end
4747
end
4848
end
49-
49+
5050
cache_loaded = true
5151
end
5252

@@ -57,7 +57,7 @@ M.save = function()
5757
local cache_dir = vim.fn.fnamemodify(cache_file, ":h")
5858
utils.safe_mkdir(cache_dir, false)
5959
end
60-
60+
6161
if vim.fn and vim.fn.json_encode then
6262
local ok, json = pcall(vim.fn.json_encode, cache)
6363
if ok then
@@ -69,56 +69,56 @@ end
6969
-- Get value from cache
7070
M.get = function(key)
7171
M.load()
72-
72+
7373
local entry = cache[key]
7474
if not entry then
7575
return nil
7676
end
77-
77+
7878
-- Check expiration
7979
if entry.expires and entry.expires < os.time() then
8080
cache[key] = nil
8181
return nil
8282
end
83-
83+
8484
return entry.value
8585
end
8686

8787
-- Set value in cache
8888
M.set = function(key, value, ttl)
8989
M.load()
90-
90+
9191
cache[key] = {
9292
value = value,
9393
expires = ttl and (os.time() + ttl) or nil,
94-
created = os.time()
94+
created = os.time(),
9595
}
96-
96+
9797
M.save()
9898
end
9999

100100
-- Remove value from cache
101101
M.delete = function(key)
102102
M.load()
103-
103+
104104
cache[key] = nil
105105
M.save()
106106
end
107107

108108
-- Clear expired entries
109109
M.clean = function()
110110
M.load()
111-
111+
112112
local now = os.time()
113113
local cleaned = false
114-
114+
115115
for key, entry in pairs(cache) do
116116
if entry.expires and entry.expires < now then
117117
cache[key] = nil
118118
cleaned = true
119119
end
120120
end
121-
121+
122122
if cleaned then
123123
M.save()
124124
end
@@ -133,28 +133,28 @@ end
133133
-- Get cache statistics
134134
M.stats = function()
135135
M.load()
136-
136+
137137
local total = 0
138138
local expired = 0
139139
local now = os.time()
140-
140+
141141
for _, entry in pairs(cache) do
142142
total = total + 1
143143
if entry.expires and entry.expires < now then
144144
expired = expired + 1
145145
end
146146
end
147-
147+
148148
local file_size = 0
149149
if vim.fn and vim.fn.getfsize then
150150
file_size = vim.fn.getfsize(M.get_cache_file())
151151
end
152-
152+
153153
return {
154154
total = total,
155155
expired = expired,
156156
active = total - expired,
157-
file_size = file_size
157+
file_size = file_size,
158158
}
159159
end
160160

@@ -164,21 +164,21 @@ M.keys = {
164164
font_installed = function(family, font_type)
165165
return string.format("font:installed:%s:%s", family or "all", font_type or "default")
166166
end,
167-
167+
168168
-- Font version
169169
font_version = function()
170170
return "font:version:latest"
171171
end,
172-
172+
173173
-- Terminal detection
174174
terminal_type = function()
175175
return "terminal:detected"
176176
end,
177-
177+
178178
-- Font file paths
179179
font_files = function(family)
180180
return string.format("font:files:%s", family)
181-
end
181+
end,
182182
}
183183

184-
return M
184+
return M

0 commit comments

Comments
 (0)