From d9ec6305547c5c566f2377e17d16f6d5f5875bc9 Mon Sep 17 00:00:00 2001 From: Se7enZ Date: Fri, 29 Nov 2024 21:10:29 +0100 Subject: [PATCH 1/7] chore: Add shellcheck to pre-commit. --- .pre-commit-config.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fe1a13e4c102..e0b7d30f6bac 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,3 +11,9 @@ repos: - id: ruff-format args: [ --diff ] exclude: "contrib/pyln-grpc-proto/pyln/grpc/(primitives|node)_pb2(|_grpc).py" + +- repo: https://github.com/koalaman/shellcheck-precommit + rev: v0.10.0 + hooks: + - id: shellcheck + args: [ -fgcc ] From 4f2e630da97e3ff66c52c2e8b36a16a87b193e2b Mon Sep 17 00:00:00 2001 From: Se7enZ Date: Sat, 30 Nov 2024 16:28:18 +0100 Subject: [PATCH 2/7] chore: Add amount access check to pre-commit. Reimplements `make check-amount-access` for Python regex. --- .pre-commit-config.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e0b7d30f6bac..21f1a8e86f62 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,3 +17,14 @@ repos: hooks: - id: shellcheck args: [ -fgcc ] + +- repo: local + hooks: + # Reimplementation of `make check-amount-access` for pygrep. + - id: check-amount-access + name: Check amount_msat and amount_sat members are not accessed directly + description: "Don't access amount_msat and amount_sat members directly without a good reason since it risks overflow." + language: pygrep + entry: (->|\.)(milli)?satoshis(?!.*\/\*\ Raw:)|(? Date: Sun, 1 Dec 2024 13:15:25 +0100 Subject: [PATCH 3/7] chore: Add clang-format to pre-commit. Also intends to replace `make check-src-include-order` and `make check-hdr-include-order` by adding configuration to check for include ordering. --- .clang-format | 2 ++ .pre-commit-config.yaml | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/.clang-format b/.clang-format index a3ef233a243d..bc97efc80c61 100644 --- a/.clang-format +++ b/.clang-format @@ -4,3 +4,5 @@ UseTab: Always BreakBeforeBraces: Linux AllowShortIfStatementsOnASingleLine: false IndentCaseLabels: false +SortIncludes: CaseSensitive +IncludeBlocks: Preserve diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 21f1a8e86f62..5311979d45b5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,6 +18,18 @@ repos: - id: shellcheck args: [ -fgcc ] +- repo: https://github.com/pre-commit/mirrors-clang-format + rev: v19.1.4 + hooks: + - id: clang-format + description: Runs formatting checks on the c code and and throws errors if suggestions + are detected, without modifying the code. Style is defined in `.clang-format`. When + encountering formatting-related errors, run `clang-format -i ` to make + (destructively) the suggestions and evalute the resulting diff for more context. + args: [ --dry-run, -Werror ] + entry: clang-format + types: [ c ] + - repo: local hooks: # Reimplementation of `make check-amount-access` for pygrep. From a455383acc2fa75cb53df43eb5934aba18eb19ee Mon Sep 17 00:00:00 2001 From: Se7enZ Date: Sun, 1 Dec 2024 13:52:59 +0100 Subject: [PATCH 4/7] chore: Add discouraged function check to pre-commit. Reimplements `make check-discouraged-functions` for Python regex. --- .pre-commit-config.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5311979d45b5..b38a73b33c91 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -40,3 +40,11 @@ repos: entry: (->|\.)(milli)?satoshis(?!.*\/\*\ Raw:)|(? Date: Mon, 16 Dec 2024 19:13:38 +0100 Subject: [PATCH 5/7] chore: Add codespell to pre-commit. Includes default config file and an initial word list to ignore. --- .codespellignore | 3 +++ .codespellrc | 4 ++++ .pre-commit-config.yaml | 7 +++++++ 3 files changed, 14 insertions(+) create mode 100644 .codespellignore create mode 100644 .codespellrc diff --git a/.codespellignore b/.codespellignore new file mode 100644 index 000000000000..972d0b2596ab --- /dev/null +++ b/.codespellignore @@ -0,0 +1,3 @@ +connectd +crate +mut diff --git a/.codespellrc b/.codespellrc new file mode 100644 index 000000000000..092dcccfc418 --- /dev/null +++ b/.codespellrc @@ -0,0 +1,4 @@ +[codespell] + +count = true +ignore-words = .codespellignore diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b38a73b33c91..2b6a26623737 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,6 +30,13 @@ repos: entry: clang-format types: [ c ] +- repo: https://github.com/codespell-project/codespell + rev: v2.3.0 + hooks: + - id: codespell + description: Checks for common misspellings. + exclude: ccan|contrib|tests/fuzz/corpora + - repo: local hooks: # Reimplementation of `make check-amount-access` for pygrep. From 6ff1ff2603fb3346beb186479977ffc4f59d1de6 Mon Sep 17 00:00:00 2001 From: Se7enZ Date: Tue, 17 Dec 2024 11:25:28 +0100 Subject: [PATCH 6/7] chore: Add doc JSON schema checks and formatting to pre-commit. --- .pre-commit-config.yaml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2b6a26623737..b713467f078d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,6 +30,29 @@ repos: entry: clang-format types: [ c ] +- repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.30.0 + hooks: + - id: check-jsonschema + name: check doc JSON schemas + args: ["--schemafile", "doc/rpc-schema-draft.json"] + files: ^doc/schemas/.*\.json$ + types: [ json ] + + - id: check-metaschema + name: check doc JSON metaschemas + args: ["--verbose"] + files: ^doc/schemas/.*\.json$ + types: [ json ] + +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: pretty-format-json + args: [ "--indent", "2", "--no-sort-keys" ] + files: ^doc/schemas/.*\.json$ + types: [ json ] + - repo: https://github.com/codespell-project/codespell rev: v2.3.0 hooks: From 3265aeabc4f05ab811d570628010a8b0c8cdd79b Mon Sep 17 00:00:00 2001 From: Se7enZ Date: Wed, 18 Dec 2024 20:34:31 +0100 Subject: [PATCH 7/7] chore: Add conventional commit linting to pre-commit. --- .pre-commit-config.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b713467f078d..75506b376739 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -60,6 +60,25 @@ repos: description: Checks for common misspellings. exclude: ccan|contrib|tests/fuzz/corpora +- repo: https://github.com/compilerla/conventional-pre-commit + rev: v3.6.0 + hooks: + - id: conventional-pre-commit + stages: [commit-msg] + args: + - --scopes=askrene,bkpr,channeld,cli,closingd,cln-grpc,cln-rpc,common,connectd,db,gossipd,hsmd,lightningd,onchaind,openingd,pay,pylightning,pyln-client,pyln-spec,pyln-testing,pytest,splice,tools,wallet,wire,xpay + - --verbose + - build + - chore + - ci + - docs + - feat + - fix + - style + - refactor + - perf + - test + - repo: local hooks: # Reimplementation of `make check-amount-access` for pygrep.