From 623300d6a3857e6384c9b6a5af732cb98a5dbbbe Mon Sep 17 00:00:00 2001 From: Se7enZ Date: Mon, 12 Jan 2026 18:49:28 +0100 Subject: [PATCH] devtools: Add commitlint to pre-commit. --- .pre-commit-config.yaml | 6 +++++ commitlint.config.js | 56 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 commitlint.config.js diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 497750a0c..2db847f34 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -67,6 +67,12 @@ repos: exclude: ccan|contrib|tests/fuzz/corpora stages: [ manual ] +- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook + rev: v9.23.0 + hooks: + - id: commitlint + stages: [commit-msg] + - repo: local hooks: # Reimplementation of `make check-amount-access` for pygrep. diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 000000000..f156abd38 --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,56 @@ +module.exports = { + + plugins: [ + { + rules: { + 'core-lightning': ({ type }) => { + // Allow standard Core Lightning types + const standardTypes = [ + // Daemons + 'channeld', 'closingd', 'connectd', 'gossipd', 'hsmd', 'lightningd', 'onchaind', + 'openingd', + // Related + 'bitcoin', 'cli', 'cln-grpc', 'cln-rpc', 'db', 'wallet', 'wire', + // Others + 'ci', 'common', 'contrib', 'devtools', 'docs', 'docker', 'github', 'global', + 'meta', 'nit', 'nix', 'release', 'script', 'tests', + ]; + + // Extensions + const extensions = ['plugin-', 'pyln-', 'tool-'] + if (type) { + for (const prefix of extensions) { + if (type.startsWith(prefix)) { + return [true]; + } + } + } + + // Otherwise, must be a standard type + if (standardTypes.includes(type)) { + return [true]; + } + + return [ + false, + `Type must be one of [${standardTypes.join(', ')}] or match patterns [${extensions.join(', ')}]` + ]; + }, + }, + }, + ], + + rules: { + // Disable the default type-enum rule since we're using custom validation + 'type-enum': [0], + + // Enable our custom rule + 'core-lightning': [2, 'always'], + + // Keep other standard rules + 'type-case': [2, 'always', 'lower-case'], + 'type-empty': [2, 'never'], + 'subject-empty': [2, 'never'], + 'subject-case': [2, 'never', ['upper-case']], + }, +};