2021-09-19 11:06:29 -07:00
|
|
|
-- Usage:
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
-- # verbose
|
2023-04-22 08:37:45 -07:00
|
|
|
-- nvim -l scripts/lintcommit.lua main --trace
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
--
|
|
|
|
-- # silent
|
2023-04-22 08:37:45 -07:00
|
|
|
-- nvim -l scripts/lintcommit.lua main
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
--
|
|
|
|
-- # self-test
|
2023-04-22 06:10:35 -07:00
|
|
|
-- nvim -l scripts/lintcommit.lua _test
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
|
2023-04-22 06:10:35 -07:00
|
|
|
--- @type table<string,fun(opt: LintcommitOptions)>
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
local M = {}
|
2021-09-19 11:06:29 -07:00
|
|
|
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
local _trace = false
|
2021-09-19 11:06:29 -07:00
|
|
|
|
2023-04-22 08:37:45 -07:00
|
|
|
-- Print message
|
|
|
|
local function p(s)
|
|
|
|
vim.cmd('set verbose=1')
|
|
|
|
vim.api.nvim_echo({{s, ''}}, false, {})
|
|
|
|
vim.cmd('set verbose=0')
|
|
|
|
end
|
|
|
|
|
2021-09-19 11:06:29 -07:00
|
|
|
-- Executes and returns the output of `cmd`, or nil on failure.
|
|
|
|
--
|
|
|
|
-- Prints `cmd` if `trace` is enabled.
|
|
|
|
local function run(cmd, or_die)
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
if _trace then
|
2023-04-22 08:37:45 -07:00
|
|
|
p('run: '..vim.inspect(cmd))
|
2021-09-19 11:06:29 -07:00
|
|
|
end
|
|
|
|
local rv = vim.trim(vim.fn.system(cmd)) or ''
|
|
|
|
if vim.v.shell_error ~= 0 then
|
|
|
|
if or_die then
|
2023-04-22 08:37:45 -07:00
|
|
|
p(rv)
|
2023-04-22 06:10:35 -07:00
|
|
|
os.exit(1)
|
2021-09-19 11:06:29 -07:00
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
return rv
|
|
|
|
end
|
|
|
|
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
-- Returns nil if the given commit message is valid, or returns a string
|
|
|
|
-- message explaining why it is invalid.
|
|
|
|
local function validate_commit(commit_message)
|
2022-05-13 05:37:33 -07:00
|
|
|
-- Return nil if the commit message starts with "fixup" as it signifies it's
|
|
|
|
-- a work in progress and shouldn't be linted yet.
|
|
|
|
if vim.startswith(commit_message, "fixup") then
|
|
|
|
return nil
|
|
|
|
end
|
2021-09-19 09:27:08 -07:00
|
|
|
|
2023-04-11 18:50:48 -07:00
|
|
|
local commit_split = vim.split(commit_message, ":", {plain = true})
|
2021-11-27 09:10:48 -07:00
|
|
|
-- Return nil if the type is vim-patch since most of the normal rules don't
|
2021-09-19 09:27:08 -07:00
|
|
|
-- apply.
|
|
|
|
if commit_split[1] == "vim-patch" then
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
return nil
|
2021-09-19 09:27:08 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Check that message isn't too long.
|
|
|
|
if commit_message:len() > 80 then
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
return [[Commit message is too long, a maximum of 80 characters is allowed.]]
|
2021-09-19 09:27:08 -07:00
|
|
|
end
|
|
|
|
|
2023-04-11 18:50:48 -07:00
|
|
|
local before_colon = commit_split[1]
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
|
2023-04-11 18:50:48 -07:00
|
|
|
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
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
return [[Commit message does not include colons.]]
|
2021-09-19 09:27:08 -07:00
|
|
|
end
|
2023-04-11 18:50:48 -07:00
|
|
|
local after_colon = commit_split[after_idx]
|
2021-09-19 09:27:08 -07:00
|
|
|
|
|
|
|
-- Check if commit introduces a breaking change.
|
|
|
|
if vim.endswith(before_colon, "!") then
|
|
|
|
before_colon = before_colon:sub(1, -2)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Check if type is correct
|
2023-04-11 18:50:48 -07:00
|
|
|
local type = vim.split(before_colon, "(", {plain = true})[1]
|
2023-02-10 09:03:01 -07:00
|
|
|
local allowed_types = {'build', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'test', 'vim-patch'}
|
2023-04-14 04:41:50 -07:00
|
|
|
if not vim.tbl_contains(allowed_types, type) then
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
return string.format(
|
2023-02-10 09:03:01 -07:00
|
|
|
[[Invalid commit type "%s". Allowed types are:
|
|
|
|
%s.
|
|
|
|
If none of these seem appropriate then use "fix"]],
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
type,
|
|
|
|
vim.inspect(allowed_types))
|
2021-09-19 09:27:08 -07:00
|
|
|
end
|
|
|
|
|
2022-10-24 04:24:08 -07:00
|
|
|
-- Check if scope is appropriate
|
2021-09-19 09:27:08 -07:00
|
|
|
if before_colon:match("%(") then
|
2023-03-21 19:57:23 -07:00
|
|
|
local scope = vim.trim(commit_message:match("%((.-)%)"))
|
2022-10-24 04:24:08 -07:00
|
|
|
|
2021-09-19 09:27:08 -07:00
|
|
|
if scope == '' then
|
2022-10-24 04:24:08 -07:00
|
|
|
return [[Scope can't be empty]]
|
|
|
|
end
|
|
|
|
|
|
|
|
if vim.startswith(scope, "nvim_") then
|
|
|
|
return [[Scope should be "api" instead of "nvim_..."]]
|
|
|
|
end
|
|
|
|
|
|
|
|
local alternative_scope = {
|
|
|
|
['filetype.vim'] = 'filetype',
|
|
|
|
['filetype.lua'] = 'filetype',
|
|
|
|
['tree-sitter'] = 'treesitter',
|
|
|
|
['ts'] = 'treesitter',
|
|
|
|
['hl'] = 'highlight',
|
|
|
|
}
|
|
|
|
|
|
|
|
if alternative_scope[scope] then
|
|
|
|
return ('Scope should be "%s" instead of "%s"'):format(alternative_scope[scope], scope)
|
2021-09-19 09:27:08 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Check that description doesn't end with a period
|
|
|
|
if vim.endswith(after_colon, ".") then
|
2021-09-26 12:13:59 -07:00
|
|
|
return [[Description ends with a period (".").]]
|
2021-09-19 09:27:08 -07:00
|
|
|
end
|
|
|
|
|
2022-02-11 11:47:59 -07:00
|
|
|
-- Check that description starts with a whitespace.
|
|
|
|
if after_colon:sub(1,1) ~= " " then
|
|
|
|
return [[There should be a whitespace after the colon.]]
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Check that description doesn't start with multiple whitespaces.
|
|
|
|
if after_colon:sub(1,2) == " " then
|
|
|
|
return [[There should only be one whitespace after the colon.]]
|
|
|
|
end
|
|
|
|
|
2023-02-13 10:26:27 -07:00
|
|
|
-- Allow lowercase or ALL_UPPER but not Titlecase.
|
2023-02-16 07:43:05 -07:00
|
|
|
if after_colon:match('^ *%u%l') then
|
|
|
|
return [[Description first word should not be Capitalized.]]
|
2023-02-13 10:26:27 -07:00
|
|
|
end
|
2022-02-11 11:47:59 -07:00
|
|
|
|
|
|
|
-- Check that description isn't just whitespaces
|
|
|
|
if vim.trim(after_colon) == "" then
|
|
|
|
return [[Description shouldn't be empty.]]
|
2021-09-19 09:27:08 -07:00
|
|
|
end
|
|
|
|
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
return nil
|
2021-09-19 09:27:08 -07:00
|
|
|
end
|
|
|
|
|
2023-04-22 06:10:35 -07:00
|
|
|
--- @param opt? LintcommitOptions
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
function M.main(opt)
|
|
|
|
_trace = not opt or not not opt.trace
|
|
|
|
|
2021-10-14 01:13:56 -07:00
|
|
|
local branch = run({'git', 'rev-parse', '--abbrev-ref', 'HEAD'}, true)
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
-- TODO(justinmk): check $GITHUB_REF
|
2021-09-19 11:06:29 -07:00
|
|
|
local ancestor = run({'git', 'merge-base', 'origin/master', branch})
|
|
|
|
if not ancestor then
|
|
|
|
ancestor = run({'git', 'merge-base', 'upstream/master', branch})
|
|
|
|
end
|
|
|
|
local commits_str = run({'git', 'rev-list', ancestor..'..'..branch}, true)
|
2023-04-22 06:10:35 -07:00
|
|
|
assert(commits_str)
|
2021-09-19 09:27:08 -07:00
|
|
|
|
2023-04-22 06:10:35 -07:00
|
|
|
local commits = {} --- @type string[]
|
2021-09-19 09:27:08 -07:00
|
|
|
for substring in commits_str:gmatch("%S+") do
|
2023-04-22 06:10:35 -07:00
|
|
|
table.insert(commits, substring)
|
2021-09-19 09:27:08 -07:00
|
|
|
end
|
|
|
|
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
local failed = 0
|
|
|
|
for _, commit_id in ipairs(commits) do
|
|
|
|
local msg = run({'git', 'show', '-s', '--format=%s' , commit_id})
|
2021-09-19 09:27:08 -07:00
|
|
|
if vim.v.shell_error ~= 0 then
|
2023-04-22 08:37:45 -07:00
|
|
|
p('Invalid commit-id: '..commit_id..'"')
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
else
|
|
|
|
local invalid_msg = validate_commit(msg)
|
|
|
|
if invalid_msg then
|
|
|
|
failed = failed + 1
|
2023-02-10 09:03:01 -07:00
|
|
|
|
|
|
|
-- Some breathing room
|
|
|
|
if failed == 1 then
|
2023-04-22 08:37:45 -07:00
|
|
|
p('\n')
|
2023-02-10 09:03:01 -07:00
|
|
|
end
|
|
|
|
|
2023-04-22 08:37:45 -07:00
|
|
|
p(string.format([[
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
Invalid commit message: "%s"
|
|
|
|
Commit: %s
|
|
|
|
%s
|
|
|
|
]],
|
|
|
|
msg,
|
|
|
|
commit_id,
|
|
|
|
invalid_msg))
|
|
|
|
end
|
2021-09-19 09:27:08 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
if failed > 0 then
|
2023-04-22 08:37:45 -07:00
|
|
|
p([[
|
2023-02-10 09:03:01 -07:00
|
|
|
See also:
|
|
|
|
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
|
2023-04-22 08:37:45 -07:00
|
|
|
|
2023-02-10 09:03:01 -07:00
|
|
|
]])
|
2023-04-22 06:10:35 -07:00
|
|
|
os.exit(1)
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
else
|
2023-04-22 08:37:45 -07:00
|
|
|
p('')
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
end
|
|
|
|
end
|
2021-09-19 09:27:08 -07:00
|
|
|
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
function M._test()
|
|
|
|
-- message:expected_result
|
|
|
|
local test_cases = {
|
|
|
|
['ci: normal message'] = true,
|
|
|
|
['build: normal message'] = true,
|
|
|
|
['docs: normal message'] = true,
|
|
|
|
['feat: normal message'] = true,
|
|
|
|
['fix: normal message'] = true,
|
|
|
|
['perf: normal message'] = true,
|
|
|
|
['refactor: normal message'] = true,
|
|
|
|
['revert: normal message'] = true,
|
|
|
|
['test: normal message'] = true,
|
|
|
|
['ci(window): message with scope'] = true,
|
|
|
|
['ci!: message with breaking change'] = true,
|
|
|
|
['ci(tui)!: message with scope and breaking change'] = true,
|
|
|
|
['vim-patch:8.2.3374: Pyret files are not recognized (#15642)'] = true,
|
|
|
|
['vim-patch:8.1.1195,8.2.{3417,3419}'] = true,
|
2022-02-11 11:47:59 -07:00
|
|
|
['revert: "ci: use continue-on-error instead of "|| true""'] = true,
|
2022-05-13 05:37:33 -07:00
|
|
|
['fixup'] = true,
|
|
|
|
['fixup: commit message'] = true,
|
|
|
|
['fixup! commit message'] = true,
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
[':no type before colon 1'] = false,
|
|
|
|
[' :no type before colon 2'] = false,
|
|
|
|
[' :no type before colon 3'] = false,
|
|
|
|
['ci(empty description):'] = false,
|
2022-02-11 11:47:59 -07:00
|
|
|
['ci(only whitespace as description): '] = false,
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
['docs(multiple whitespaces as description): '] = false,
|
2022-02-11 11:47:59 -07:00
|
|
|
['revert(multiple whitespaces and then characters as description): description'] = false,
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
['ci no colon after type'] = false,
|
|
|
|
['test: extra space after colon'] = false,
|
|
|
|
['ci: tab after colon'] = false,
|
|
|
|
['ci:no space after colon'] = false,
|
|
|
|
['ci :extra space before colon'] = false,
|
|
|
|
['refactor(): empty scope'] = false,
|
|
|
|
['ci( ): whitespace as scope'] = false,
|
2022-05-17 05:42:48 -07:00
|
|
|
['ci: period at end of sentence.'] = false,
|
2023-02-13 10:26:27 -07:00
|
|
|
['ci: Capitalized first word'] = false,
|
2023-02-16 07:43:05 -07:00
|
|
|
['ci: UPPER_CASE First Word'] = true,
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
['unknown: using unknown type'] = false,
|
2023-04-11 18:50:48 -07:00
|
|
|
['feat: foo:bar'] = true,
|
|
|
|
['feat(something): foo:bar'] = true,
|
2023-03-21 19:57:23 -07:00
|
|
|
['feat(:grep): read from pipe'] = true,
|
2023-04-11 18:50:48 -07:00
|
|
|
['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,
|
2022-05-17 05:42:48 -07:00
|
|
|
['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,
|
2021-09-19 09:27:08 -07:00
|
|
|
}
|
|
|
|
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
local failed = 0
|
|
|
|
for message, expected in pairs(test_cases) do
|
|
|
|
local is_valid = (nil == validate_commit(message))
|
|
|
|
if is_valid ~= expected then
|
|
|
|
failed = failed + 1
|
2023-04-22 08:37:45 -07:00
|
|
|
p(string.format('[ FAIL ]: expected=%s, got=%s\n input: "%s"', expected, is_valid, message))
|
2021-09-19 09:27:08 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
if failed > 0 then
|
2023-04-22 06:10:35 -07:00
|
|
|
os.exit(1)
|
2021-09-19 09:27:08 -07:00
|
|
|
end
|
build(lint): commit linter #15725
Example test failure:
$ nvim -es +"lua require('scripts.lintcommit')._test()"
[ FAIL ]: expected=true, got=false
input: ":no type before colon 1"
[ FAIL ]: expected=true, got=false
input: "ci: tab after colon"
Example main({trace=true}) output:
$ nvim -es +"lua require('scripts.lintcommit').main()"
run: { "git", "branch", "--show-current" }
run: { "git", "merge-base", "origin/master", "master" }
run: { "git", "merge-base", "upstream/master", "master" }
run: { "git", "rev-list", "89db07556dbdce97c0c150ed7e47d80e1ddacad3..master" }
run: { "git", "show", "-s", "--format=%s", "d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc" }
Invalid commit message: "buildlint): commit linter #15620"
Commit: d2e6d2f5fc93b6da3c6153229135ba2f0b24f8cc
Invalid commit type "buildlint)". Allowed types are:
{ "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "test", "chore", "vim-patch" }
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
https://www.conventionalcommits.org/en/v1.0.0/
2021-09-19 12:57:57 -07:00
|
|
|
|
2021-09-19 09:27:08 -07:00
|
|
|
end
|
|
|
|
|
2023-04-22 06:10:35 -07:00
|
|
|
--- @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
|