From e5d8220179f932ab9c9ef59996cab357a25eaaf8 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 10 Feb 2023 17:03:01 +0100 Subject: ci: simplify lintcommit output (#22204) - Suggest reading CONTRIBUTING.md once, not for each commit failure - Suggest using "fix" type if none of the provided types are appropriate - Remove "dist" type. It's rarely used and can be replaced by using the "build" type --- scripts/lintcommit.lua | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'scripts/lintcommit.lua') diff --git a/scripts/lintcommit.lua b/scripts/lintcommit.lua index 87a8e62503..71796a5e02 100644 --- a/scripts/lintcommit.lua +++ b/scripts/lintcommit.lua @@ -78,10 +78,12 @@ local function validate_commit(commit_message) -- Check if type is correct local type = vim.split(before_colon, "%(")[1] - local allowed_types = {'build', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'test', 'dist', 'vim-patch'} + 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( - 'Invalid commit type "%s". Allowed types are:\n %s', + [[Invalid commit type "%s". Allowed types are: + %s. + If none of these seem appropriate then use "fix"]], type, vim.inspect(allowed_types)) end @@ -164,13 +166,16 @@ function M.main(opt) local invalid_msg = validate_commit(msg) if invalid_msg then failed = failed + 1 + + -- Some breathing room + if failed == 1 then + p('\n') + end + p(string.format([[ Invalid commit message: "%s" Commit: %s %s - See also: - https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages - https://www.conventionalcommits.org/en/v1.0.0/ ]], msg, commit_id, @@ -180,6 +185,10 @@ Invalid commit message: "%s" end if failed > 0 then + p([[ +See also: + https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages +]]) die() -- Exit with error. else p('') @@ -198,7 +207,6 @@ function M._test() ['refactor: normal message'] = true, ['revert: normal message'] = true, ['test: normal message'] = true, - ['dist: normal message'] = true, ['ci(window): message with scope'] = true, ['ci!: message with breaking change'] = true, ['ci(tui)!: message with scope and breaking change'] = true, -- cgit From 84cf6a0a7e58aace0e659f2c6bb61d7179164add Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 13 Feb 2023 12:26:27 -0500 Subject: ci(lintcommit): allow UPPER_CASE first word (#22245) --- scripts/lintcommit.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'scripts/lintcommit.lua') diff --git a/scripts/lintcommit.lua b/scripts/lintcommit.lua index 71796a5e02..977f7e7e46 100644 --- a/scripts/lintcommit.lua +++ b/scripts/lintcommit.lua @@ -128,10 +128,10 @@ local function validate_commit(commit_message) return [[There should only be one whitespace after the colon.]] end - -- Check that first character after space isn't uppercase. - if string.match(after_colon:sub(2,2), '%u') then - return [[First character should not be uppercase.]] - end + -- Allow lowercase or ALL_UPPER but not Titlecase. + if after_colon:match(' *%u%l') then + return [[Description should not be Capitalized.]] + end -- Check that description isn't just whitespaces if vim.trim(after_colon) == "" then @@ -231,7 +231,8 @@ function M._test() ['refactor(): empty scope'] = false, ['ci( ): whitespace as scope'] = false, ['ci: period at end of sentence.'] = false, - ['ci: Starting sentence capitalized'] = false, + ['ci: Capitalized first word'] = false, + ['ci: UPPER_CASE first word'] = true, ['unknown: using unknown type'] = 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, } -- cgit From 5420bf99988be798938f7ee45b2f993e3c4ff2ee Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 16 Feb 2023 09:43:05 -0500 Subject: fix(lintcommit): capitalized description #22282 Problem: The "Capitalized" check should only check the first word of a description. Solution: Specify "^". --- scripts/lintcommit.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'scripts/lintcommit.lua') diff --git a/scripts/lintcommit.lua b/scripts/lintcommit.lua index 977f7e7e46..7e08ca4ea0 100644 --- a/scripts/lintcommit.lua +++ b/scripts/lintcommit.lua @@ -129,8 +129,8 @@ local function validate_commit(commit_message) end -- Allow lowercase or ALL_UPPER but not Titlecase. - if after_colon:match(' *%u%l') then - return [[Description should not be Capitalized.]] + if after_colon:match('^ *%u%l') then + return [[Description first word should not be Capitalized.]] end -- Check that description isn't just whitespaces @@ -232,7 +232,7 @@ function M._test() ['ci( ): whitespace as scope'] = false, ['ci: period at end of sentence.'] = false, ['ci: Capitalized first word'] = false, - ['ci: UPPER_CASE first word'] = true, + ['ci: UPPER_CASE First Word'] = true, ['unknown: using unknown type'] = 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, } -- cgit From a7b537c7a4e5b6114cd75df5178199f4449c6480 Mon Sep 17 00:00:00 2001 From: Ankit Goel Date: Wed, 22 Mar 2023 02:57:23 +0000 Subject: ci(lintcommit): allow colon in commit message scope Close #21464 --- scripts/lintcommit.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'scripts/lintcommit.lua') diff --git a/scripts/lintcommit.lua b/scripts/lintcommit.lua index 7e08ca4ea0..92b07c4f73 100644 --- a/scripts/lintcommit.lua +++ b/scripts/lintcommit.lua @@ -69,7 +69,7 @@ local function validate_commit(commit_message) end local before_colon = commit_split[1] - local after_colon = commit_split[2] + local after_colon = commit_split[#commit_split] -- Check if commit introduces a breaking change. if vim.endswith(before_colon, "!") then @@ -90,7 +90,7 @@ local function validate_commit(commit_message) -- Check if scope is appropriate if before_colon:match("%(") then - local scope = vim.trim(before_colon:match("%((.*)%)")) + local scope = vim.trim(commit_message:match("%((.-)%)")) if scope == '' then return [[Scope can't be empty]] @@ -234,6 +234,7 @@ function M._test() ['ci: Capitalized first word'] = false, ['ci: UPPER_CASE First Word'] = true, ['unknown: using unknown type'] = false, + ['feat(:grep): read from pipe'] = true, ['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, } -- cgit From e23c6ebed7a6dcc878a64690bbd7252c18591d54 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 12 Apr 2023 09:50:48 +0800 Subject: ci(lintcommit): allow colon not followed by space in description (#23035) --- scripts/lintcommit.lua | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'scripts/lintcommit.lua') 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, } -- cgit From 4d04feb6629cb049cb2a13ba35f0c8d3c6b67ff4 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Fri, 14 Apr 2023 10:39:57 +0200 Subject: feat(lua): vim.tbl_contains supports general tables and predicates (#23040) * feat(lua): vim.tbl_contains supports general tables and predicates Problem: `vim.tbl_contains` only works for list-like tables (integer keys without gaps) and primitive values (in particular, not for nested tables). Solution: Rename `vim.tbl_contains` to `vim.list_contains` and add new `vim.tbl_contains` that works for general tables and optionally allows `value` to be a predicate function that is checked for every key. --- scripts/lintcommit.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/lintcommit.lua') diff --git a/scripts/lintcommit.lua b/scripts/lintcommit.lua index f9a4631b7e..7f3dffd22c 100644 --- a/scripts/lintcommit.lua +++ b/scripts/lintcommit.lua @@ -88,7 +88,7 @@ local function validate_commit(commit_message) -- Check if type is correct 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 + if not vim.list_contains(allowed_types, type) then return string.format( [[Invalid commit type "%s". Allowed types are: %s. -- cgit From 5465adcbab29b57d497d7260c6f85ddbf76c43ab Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 14 Apr 2023 12:41:50 +0100 Subject: fix(lint): use tbl_contains --- scripts/lintcommit.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/lintcommit.lua') diff --git a/scripts/lintcommit.lua b/scripts/lintcommit.lua index 7f3dffd22c..f9a4631b7e 100644 --- a/scripts/lintcommit.lua +++ b/scripts/lintcommit.lua @@ -88,7 +88,7 @@ local function validate_commit(commit_message) -- Check if type is correct 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.list_contains(allowed_types, type) then + if not vim.tbl_contains(allowed_types, type) then return string.format( [[Invalid commit type "%s". Allowed types are: %s. -- cgit From 732cb9e1e0a90f40d9189bffe009bbb7f8456eeb Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Sat, 22 Apr 2023 14:10:35 +0100 Subject: ci(lintcommit): use nvim -l --- scripts/lintcommit.lua | 70 +++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 29 deletions(-) (limited to 'scripts/lintcommit.lua') diff --git a/scripts/lintcommit.lua b/scripts/lintcommit.lua index f9a4631b7e..7193821afe 100644 --- a/scripts/lintcommit.lua +++ b/scripts/lintcommit.lua @@ -1,41 +1,30 @@ -- Usage: -- # verbose --- nvim -es +"lua require('scripts.lintcommit').main()" +-- nvim -l scripts/lintcommit.lua main -- -- # silent --- nvim -es +"lua require('scripts.lintcommit').main({trace=false})" +-- nvim -l scripts/lintcommit.lua main --notrace -- -- # self-test --- nvim -es +"lua require('scripts.lintcommit')._test()" +-- nvim -l scripts/lintcommit.lua _test +--- @type table local M = {} local _trace = false --- Print message -local function p(s) - vim.cmd('set verbose=1') - vim.api.nvim_echo({{s, ''}}, false, {}) - vim.cmd('set verbose=0') -end - -local function die() - p('') - vim.cmd("cquit 1") -end - -- Executes and returns the output of `cmd`, or nil on failure. -- -- Prints `cmd` if `trace` is enabled. local function run(cmd, or_die) if _trace then - p('run: '..vim.inspect(cmd)) + print('run: '..vim.inspect(cmd)) end local rv = vim.trim(vim.fn.system(cmd)) or '' if vim.v.shell_error ~= 0 then if or_die then - p(rv) - die() + print(rv) + os.exit(1) end return nil end @@ -150,6 +139,7 @@ local function validate_commit(commit_message) return nil end +--- @param opt? LintcommitOptions function M.main(opt) _trace = not opt or not not opt.trace @@ -160,17 +150,18 @@ function M.main(opt) ancestor = run({'git', 'merge-base', 'upstream/master', branch}) end local commits_str = run({'git', 'rev-list', ancestor..'..'..branch}, true) + assert(commits_str) - local commits = {} + local commits = {} --- @type string[] for substring in commits_str:gmatch("%S+") do - table.insert(commits, substring) + table.insert(commits, substring) end local failed = 0 for _, commit_id in ipairs(commits) do local msg = run({'git', 'show', '-s', '--format=%s' , commit_id}) if vim.v.shell_error ~= 0 then - p('Invalid commit-id: '..commit_id..'"') + print('Invalid commit-id: '..commit_id..'"') else local invalid_msg = validate_commit(msg) if invalid_msg then @@ -178,10 +169,10 @@ function M.main(opt) -- Some breathing room if failed == 1 then - p('\n') + print('\n') end - p(string.format([[ + print(string.format([[ Invalid commit message: "%s" Commit: %s %s @@ -194,13 +185,13 @@ Invalid commit message: "%s" end if failed > 0 then - p([[ + print([[ See also: https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages ]]) - die() -- Exit with error. + os.exit(1) else - p('') + print('') end end @@ -261,14 +252,35 @@ function M._test() local is_valid = (nil == validate_commit(message)) if is_valid ~= expected then failed = failed + 1 - p(string.format('[ FAIL ]: expected=%s, got=%s\n input: "%s"', expected, is_valid, message)) + print(string.format('[ FAIL ]: expected=%s, got=%s\n input: "%s"', expected, is_valid, message)) end end if failed > 0 then - die() -- Exit with error. + os.exit(1) end end -return M +--- @class LintcommitOptions +--- @field trace? boolean +local opt = {} + +for _, a in ipairs(arg) do + if vim.startswith(a, '--') then + local nm, val = a:sub(3), true + if vim.startswith(a, '--no') then + nm, val = a:sub(5), false + end + + if nm == 'trace' then + opt.trace = val + end + end +end + +for _, a in ipairs(arg) do + if M[a] then + M[a](opt) + end +end -- cgit From ccce200cde296aa65a720e028a5eacf715f29e4f Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 22 Apr 2023 17:37:45 +0200 Subject: ci(lintcommit): fix error output Using print() alone doesn't work properly, toggling the verbose option is still required. --- scripts/lintcommit.lua | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'scripts/lintcommit.lua') diff --git a/scripts/lintcommit.lua b/scripts/lintcommit.lua index 7193821afe..d2c8601c25 100644 --- a/scripts/lintcommit.lua +++ b/scripts/lintcommit.lua @@ -1,9 +1,9 @@ -- Usage: -- # verbose --- nvim -l scripts/lintcommit.lua main +-- nvim -l scripts/lintcommit.lua main --trace -- -- # silent --- nvim -l scripts/lintcommit.lua main --notrace +-- nvim -l scripts/lintcommit.lua main -- -- # self-test -- nvim -l scripts/lintcommit.lua _test @@ -13,17 +13,24 @@ local M = {} local _trace = false +-- Print message +local function p(s) + vim.cmd('set verbose=1') + vim.api.nvim_echo({{s, ''}}, false, {}) + vim.cmd('set verbose=0') +end + -- Executes and returns the output of `cmd`, or nil on failure. -- -- Prints `cmd` if `trace` is enabled. local function run(cmd, or_die) if _trace then - print('run: '..vim.inspect(cmd)) + p('run: '..vim.inspect(cmd)) end local rv = vim.trim(vim.fn.system(cmd)) or '' if vim.v.shell_error ~= 0 then if or_die then - print(rv) + p(rv) os.exit(1) end return nil @@ -161,7 +168,7 @@ function M.main(opt) for _, commit_id in ipairs(commits) do local msg = run({'git', 'show', '-s', '--format=%s' , commit_id}) if vim.v.shell_error ~= 0 then - print('Invalid commit-id: '..commit_id..'"') + p('Invalid commit-id: '..commit_id..'"') else local invalid_msg = validate_commit(msg) if invalid_msg then @@ -169,10 +176,10 @@ function M.main(opt) -- Some breathing room if failed == 1 then - print('\n') + p('\n') end - print(string.format([[ + p(string.format([[ Invalid commit message: "%s" Commit: %s %s @@ -185,13 +192,14 @@ Invalid commit message: "%s" end if failed > 0 then - print([[ + p([[ See also: https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages + ]]) os.exit(1) else - print('') + p('') end end @@ -252,7 +260,7 @@ function M._test() local is_valid = (nil == validate_commit(message)) if is_valid ~= expected then failed = failed + 1 - print(string.format('[ FAIL ]: expected=%s, got=%s\n input: "%s"', expected, is_valid, message)) + p(string.format('[ FAIL ]: expected=%s, got=%s\n input: "%s"', expected, is_valid, message)) end end -- cgit