aboutsummaryrefslogtreecommitdiff
path: root/scripts/lintcommit.lua
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-04-12 09:50:48 +0800
committerGitHub <noreply@github.com>2023-04-12 09:50:48 +0800
commite23c6ebed7a6dcc878a64690bbd7252c18591d54 (patch)
tree662325f8047a5da74b0b77d681231b02a5ce146f /scripts/lintcommit.lua
parent57e9b7f2e5c82316661888a88cad711fc72d5043 (diff)
downloadrneovim-e23c6ebed7a6dcc878a64690bbd7252c18591d54.tar.gz
rneovim-e23c6ebed7a6dcc878a64690bbd7252c18591d54.tar.bz2
rneovim-e23c6ebed7a6dcc878a64690bbd7252c18591d54.zip
ci(lintcommit): allow colon not followed by space in description (#23035)
Diffstat (limited to 'scripts/lintcommit.lua')
-rw-r--r--scripts/lintcommit.lua30
1 files changed, 24 insertions, 6 deletions
diff --git a/scripts/lintcommit.lua b/scripts/lintcommit.lua
index 92b07c4f73..f9a4631b7e 100644
--- a/scripts/lintcommit.lua
+++ b/scripts/lintcommit.lua
@@ -51,7 +51,7 @@ local function validate_commit(commit_message)
return nil
end
- local commit_split = vim.split(commit_message, ":")
+ local commit_split = vim.split(commit_message, ":", {plain = true})
-- Return nil if the type is vim-patch since most of the normal rules don't
-- apply.
if commit_split[1] == "vim-patch" then
@@ -63,13 +63,22 @@ local function validate_commit(commit_message)
return [[Commit message is too long, a maximum of 80 characters is allowed.]]
end
+ local before_colon = commit_split[1]
- if vim.tbl_count(commit_split) < 2 then
+ local after_idx = 2
+ if before_colon:match('^[^%(]*%([^%)]*$') then
+ -- Need to find the end of commit scope when commit scope contains colons.
+ while after_idx <= vim.tbl_count(commit_split) do
+ after_idx = after_idx + 1
+ if commit_split[after_idx - 1]:find(')') then
+ break
+ end
+ end
+ end
+ if after_idx > vim.tbl_count(commit_split) then
return [[Commit message does not include colons.]]
end
-
- local before_colon = commit_split[1]
- local after_colon = commit_split[#commit_split]
+ local after_colon = commit_split[after_idx]
-- Check if commit introduces a breaking change.
if vim.endswith(before_colon, "!") then
@@ -77,7 +86,7 @@ local function validate_commit(commit_message)
end
-- Check if type is correct
- local type = vim.split(before_colon, "%(")[1]
+ local type = vim.split(before_colon, "(", {plain = true})[1]
local allowed_types = {'build', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'test', 'vim-patch'}
if not vim.tbl_contains(allowed_types, type) then
return string.format(
@@ -234,7 +243,16 @@ function M._test()
['ci: Capitalized first word'] = false,
['ci: UPPER_CASE First Word'] = true,
['unknown: using unknown type'] = false,
+ ['feat: foo:bar'] = true,
+ ['feat(something): foo:bar'] = true,
['feat(:grep): read from pipe'] = true,
+ ['feat(:grep/:make): read from pipe'] = true,
+ ['feat(:grep): foo:bar'] = true,
+ ['feat(:grep/:make): foo:bar'] = true,
+ ['feat(:grep)'] = false,
+ ['feat(:grep/:make)'] = false,
+ ['feat(:grep'] = false,
+ ['feat(:grep/:make'] = false,
['ci: you\'re saying this commit message just goes on and on and on and on and on and on for way too long?'] = false,
}