Skip to content

Commit 0021875

Browse files
committed
fix(ci): ci configuration -v2
1 parent 5f5bef9 commit 0021875

File tree

3 files changed

+58
-31
lines changed

3 files changed

+58
-31
lines changed

.luacheckrc

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
-- .luacheckrc
2+
std = luajit
3+
codes = true
4+
5+
read_globals = {
6+
"vim",
7+
}
8+
9+
globals = {
10+
"vim.g",
11+
"vim.b",
12+
"vim.w",
13+
"vim.t",
14+
"vim.v",
15+
"vim.env",
16+
"vim.api",
17+
"vim.ui",
18+
"vim.fn",
19+
"vim.opt",
20+
"vim.opt_local",
21+
"vim.opt_global",
22+
"vim.o",
23+
"vim.go",
24+
"vim.bo",
25+
"vim.wo",
26+
"vim.loop",
27+
"vim.lsp",
28+
"vim.treesitter",
29+
"vim.keymap",
30+
"vim.health",
31+
"vim.version",
32+
"vim.log",
33+
"vim.notify",
34+
"vim.schedule",
35+
"vim.defer_fn",
36+
"vim.wait",
37+
"vim.cmd",
38+
"vim.tbl_contains",
39+
"vim.tbl_deep_extend",
40+
"vim.tbl_extend",
41+
"vim.tbl_filter",
42+
"vim.tbl_map",
43+
"vim.split",
44+
"vim.trim",
45+
"vim.startswith",
46+
"vim.endswith",
47+
"vim.deepcopy",
48+
"vim.pesc",
49+
"vim.inspect",
50+
}
51+
52+
ignore = {
53+
"631", -- max_line_length
54+
}
55+
56+
exclude_files = {
57+
"tests/",
58+
}

lua/sql-formatter/autocmds.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
local M = {}
66
local formatter = require("sql-formatter.formatter")
7-
local utils = require("sql-formatter.utils")
87

98
M.config = {}
109

lua/sql-formatter/formatter.lua

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,18 @@ function M.check_external_formatter()
1717
if not M.config.external_formatter.enabled then
1818
return false
1919
end
20-
2120
local cmd = M.config.external_formatter.command
2221
local handle = io.popen("which " .. cmd .. " 2>/dev/null")
2322
local result = handle:read("*a")
2423
handle:close()
25-
2624
M.external_available = result ~= ""
27-
2825
if not M.external_available then
2926
vim.notify(
3027
"External SQL formatter '" .. cmd .. "' not found. Install with: pip install sqlparse",
3128
vim.log.levels.WARN,
3229
{ title = "SQL Formatter" }
3330
)
3431
end
35-
3632
return M.external_available
3733
end
3834

@@ -41,23 +37,18 @@ function M.format_with_external(text)
4137
if not M.external_available then
4238
return nil, "External formatter not available"
4339
end
44-
4540
local cmd = M.config.external_formatter.command
4641
local args = table.concat(M.config.external_formatter.args, " ")
4742
local full_cmd = string.format("echo %s | %s %s", vim.fn.shellescape(text), cmd, args)
48-
4943
local handle = io.popen(full_cmd)
5044
if not handle then
5145
return nil, "Failed to execute formatter command"
5246
end
53-
5447
local result = handle:read("*a")
5548
local success = handle:close()
56-
5749
if not success then
5850
return nil, "Formatter command failed"
5951
end
60-
6152
return result:gsub("%s+$", ""), nil -- Remove trailing whitespace
6253
end
6354

@@ -67,26 +58,20 @@ function M.format_with_lua(text)
6758
local formatted_lines = {}
6859
local indent_level = 0
6960
local indent = M.config.indent
70-
7161
for _, line in ipairs(lines) do
7262
local trimmed = line:match("^%s*(.-)%s*$")
73-
7463
if trimmed ~= "" and not utils.is_comment_line(trimmed) then
7564
-- Handle keywords that decrease indent
7665
if trimmed:upper():match("^(END|ELSE|ELSIF|WHEN)%s") then
7766
indent_level = math.max(0, indent_level - 1)
7867
end
79-
8068
-- Apply current indentation
8169
local formatted_line = string.rep(indent, indent_level) .. trimmed
82-
8370
-- Format keywords to uppercase if configured
8471
if M.config.uppercase then
8572
formatted_line = M.format_keywords(formatted_line)
8673
end
87-
8874
table.insert(formatted_lines, formatted_line)
89-
9075
-- Handle keywords that increase indent
9176
if trimmed:upper():match("^(SELECT|FROM|WHERE|JOIN|INNER|LEFT|RIGHT|FULL|CASE|BEGIN|IF|LOOP|WHILE)%s") or
9277
trimmed:upper():match("(THEN|ELSE|DO)%s*$") then
@@ -96,7 +81,6 @@ function M.format_with_lua(text)
9681
table.insert(formatted_lines, trimmed)
9782
end
9883
end
99-
10084
return table.concat(formatted_lines, "\n")
10185
end
10286

@@ -112,12 +96,10 @@ function M.format_keywords(line)
11296
"decimal", "float", "double", "boolean", "date", "datetime", "timestamp",
11397
"case", "when", "then", "else", "end", "if", "begin", "commit", "rollback"
11498
}
115-
11699
for _, keyword in ipairs(keywords) do
117100
local pattern = "\\b" .. keyword .. "\\b"
118101
line = line:gsub(pattern, keyword:upper())
119102
end
120-
121103
return line
122104
end
123105

@@ -132,40 +114,31 @@ function M.format_sql(text)
132114
-- Fall back to Lua formatter
133115
end
134116
end
135-
136117
return M.format_with_lua(text)
137118
end
138119

139120
-- Format current buffer
140121
function M.format_buffer()
141122
local buf = vim.api.nvim_get_current_buf()
142-
143123
if not utils.is_sql_buffer(buf) then
144124
vim.notify("Not a SQL buffer", vim.log.levels.WARN)
145125
return
146126
end
147-
148127
local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
149128
local text = table.concat(lines, "\n")
150-
151129
if text:match("^%s*$") then
152130
vim.notify("Buffer is empty", vim.log.levels.INFO)
153131
return
154132
end
155-
156133
local formatted = M.format_sql(text)
157134
local new_lines = vim.split(formatted, "\n")
158-
159135
-- Save cursor position
160136
local cursor = vim.api.nvim_win_get_cursor(0)
161-
162137
vim.api.nvim_buf_set_lines(buf, 0, -1, false, new_lines)
163-
164138
-- Restore cursor position (with bounds checking)
165139
local line_count = vim.api.nvim_buf_line_count(buf)
166140
cursor[1] = math.min(cursor[1], line_count)
167141
vim.api.nvim_win_set_cursor(0, cursor)
168-
169142
if M.config.notify.enabled then
170143
vim.notify("SQL formatted successfully", vim.log.levels.INFO, { title = "SQL Formatter" })
171144
end
@@ -176,12 +149,9 @@ function M.format_range(start_line, end_line)
176149
local buf = vim.api.nvim_get_current_buf()
177150
local lines = vim.api.nvim_buf_get_lines(buf, start_line - 1, end_line, false)
178151
local text = table.concat(lines, "\n")
179-
180152
local formatted = M.format_sql(text)
181153
local new_lines = vim.split(formatted, "\n")
182-
183154
vim.api.nvim_buf_set_lines(buf, start_line - 1, end_line, false, new_lines)
184-
185155
if M.config.notify.enabled then
186156
vim.notify("SQL range formatted successfully", vim.log.levels.INFO, { title = "SQL Formatter" })
187157
end

0 commit comments

Comments
 (0)