Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .codespellignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
connectd
crate
mut
Comment on lines +1 to +3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a comprehensive list based on what's triggered by codespell? Does this also run on all files, or all C files?

Copy link
Contributor Author

@s373nZ s373nZ Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a comprehensive list based on what's triggered by codespell?

Not by any means. This is just demo of how to add words to the ignore list. Attached is recent output for pre-commit run --all-files codespell > codespell.txt

codespell.txt

I suggest going through these items to decide which typos to fix versus which to add to the ignore list is worth a separate PR?

Does this also run on all files, or all C files?

This runs on all files submitted with the changeset (during a commit) and all files in total when using pre-commit run --all-files. The mut in the ignore list is actually for Rust code.

4 changes: 4 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[codespell]

count = true
ignore-words = .codespellignore
60 changes: 60 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,63 @@ repos:
- id: ruff-format
args: [ --diff ]
exclude: "contrib/pyln-grpc-proto/pyln/grpc/(primitives|node)_pb2(|_grpc).py"

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.11.0.1
hooks:
- id: shellcheck
args: [ -fgcc ]

- 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 ]
- id: trailing-whitespace
args: [ "--markdown-linebreak-ext=md" ]
exclude: ccan|contrib|tests/fuzz/corpora
- id: end-of-file-fixer
exclude: ccan|contrib|tests/fuzz/corpora

- 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.
- 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:)|(?<!sizeof)\(struct\ amount_(m)?sat\)
types: [ c ]
exclude: common/amount|.*/test/.*

# Reimplementation of `make check-discouraged-functions` for pygrep.
- id: check-discouraged-functions
name: Check for usage of discouraged funtions
language: pygrep
entry: '[^a-z_/](?:fgets|fputs|gets|scanf|sprintf)\('
types: [ c ]
exclude: ccan|contrib
13 changes: 13 additions & 0 deletions doc/contribute-to-core-lightning/contributor-workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ uv build contrib/pyln-client/
uv build contrib/pyln-proto/
```

## Local checks with pre-commit

You can avoid common mistakes, speed up your development workflow and avoid wasteful CI runs by opting in to the local code checks managed by [pre-commit](https://pre-commit.com). The `pre-commit` Python package is part of the `dev` group and should be installed along with the other packages using `pip` or `uv` when [installing from source](https://docs.corelightning.org/docs/installation#installing-from-source). Activate it on your local development environment from the root of your Core Lightning working directory with:
```shell
pre-commit install
```

You can disable and remove it with:
```shell
pre-commit uninstall
pre-commit clean
```

## Making BOLT Modifications

All of code for marshalling/unmarshalling BOLT protocol messages is generated directly from the spec. These are pegged to the BOLTVERSION, as specified in `Makefile`.
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dev = [
"tqdm",
"pytest-benchmark",
"pdoc3>=0.11.6",
"pre-commit>=4.3.0",
]

[project.optional-dependencies]
Expand Down
18 changes: 18 additions & 0 deletions tools/fix-style-errors
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Takes a list of files and applies style fixes for Python using `ruff` and C using
# `clang-format`. Also corrects spelling using `codespell`. This tool is an auxiliary to the
# `pre-commit` hooks found in:
# `.pre-commit-config.yaml`
#
# WARNING: Changes are destructive. Ensure a clean working environment before running.
#
# By: @sangbida

for file in "$@"; do
case "$file" in
*.py) ruff check --fix "$file"; ruff format "$file" ;;
*.c|*.h) clang-format -i "$file" 2>/dev/null ;;
esac
codespell -w "$file" 2>/dev/null
done
Loading
Loading