Repository: apache/nuttx
Pull request #16302: CI: enable codespell
Author: login: sumpfralle
Labels: name: Area: CI
name: Size: S
description: The size of the change in this PR is small
Created: 2025-05-02T12:15:39Z | Merged: 2025-05-05T04:34:39Z

## Summary

These commits add a `.codespellrc` configuration file with suitable defaults and comments for all relevant use-cases in nuttx.

Additionally the github workflow "check" is extended to run the codespell check on changed files.
The log message of the check refers to the `.codespellrc` file in order to help people skip valid false positives.

At the moment, 1990 out of 25838 files in the `nuttx` repository are reported by codespell as containing errors. I already prepared two pull requests, which will reduce the number of reported files to 630. In case I can keep the mood up, I may grind this number down to zero in the next days.


## Impact

### CI
CI tests will start to fail, if a file contains a spelling problem (as detected by codespell).

In case of a problem the PR submitter will:
1. Notice the failed CI workflow "check".
1. Take a look at that CI job log.
1. In case of a real spelling mistake:
    1. Fix the issue and update the PR.
1. In case of a misdetected spelling issue:
    1. Notice the reference to the file `.codespellrc` in the CI log.
    1. Take a look at the file `.codespellrc` and hopefully understands easily, which approach would be suitable for this issue (exclude the word, line or file).

### pre-commit

The `pre-commit` check displays spelling problems in changed files.
The configuration file (`.codespellrc`) is mentioned. 

## Testing

### CI
I did not test the CI workflow for now. This PR will be the first example.

### pre-commit
The pre-commit hook now detects spelling problems in changed files:
```
$ git diff HEAD~..HEAD
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0402b282d3..065b3494b8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,3 +1,4 @@
+# foo
 # ##############################################################################
 # CMakeLists.txt
 #
$ pre-commit run --from HEAD~ --to HEAD
fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
check for added large files..............................................Passed
cmake-format.............................................................Passed
nxstyle..................................................................Failed
- hook id: nxstyle
- exit code: 1

Used config files:
    1: .codespellrc
CMakeLists.txt:162: inital ==> initial
CMakeLists.txt:271: platfrom ==> platform
CMakeLists.txt:318: Unsupport ==> Unsupported
CMakeLists.txt:385: extenstion ==> extension
```


Diff:
diff --git a/.codespell-ignore-lines b/.codespell-ignore-lines
new file mode 100644
index 0000000000000..77b123d24d781
--- /dev/null
+++ b/.codespell-ignore-lines
@@ -0,0 +1,14 @@
+/* Bit fields for LESENSE CURCH */
+  CURCH,
+  Linix,
+Linix 45ZWN24-40           2  0.5 Ohm    0.400 mH  2.34A   24V
+* Linix 45ZWN24-40 (PMSM motor dedicated for NXP FRDM-MC-LVMTR kit)
+          DUE SCHEM. PIN MAPPING    SAM3X       DUE SCHEM. BOARD LABEL
+  SCHEM,
+               * ADDR -> BTC & TBE - Send one more byte
+  TBE,
+      /* All even touch pads have the same position for the THN bits.
+      /* All odd touch pads have the same position for the THN bits.
+  THN,
+#  define AES_ISR_URAT_WORRDACC      (5 << AES_ISR_URAT_SHIFT) /* WRONLY register read access */
+  WRONLY,
diff --git a/.codespellrc b/.codespellrc
new file mode 100644
index 0000000000000..756101a0ab29c
--- /dev/null
+++ b/.codespellrc
@@ -0,0 +1,49 @@
+[codespell]
+
+# Add complete lines to be ignored to this file.
+# Example for ignoring all current occurrences of (verifiably correct) word usage:
+#   grep -hirw "emac" | sort | uniq >>.codespell-ignore-lines
+exclude-file = .codespell-ignore-lines
+
+# Ignore complete files (e.g. legal text or other immutable material).
+skip =
+  LICENSE,
+
+# Ignore seemingly misspelled words.
+#   lowercase: case insensitive
+#   uppercase: case sensitive
+# (see https://github.com/codespell-project/codespell/issues/3638)
+# This setting should be used only for frequently used words.
+# Exotic word occurrences should be filtered with the "exclude-file" setting instead.
+ignore-words-list =
+  ACI,
+  AFE,
+  afile,
+  ALS,
+  AMEBA,
+  ARCHTYPE,
+  DAA,
+  dout,
+  emac,
+  eeeprom,
+  extint,
+  filp,
+  FRAM,
+  hart,
+  hsi,
+  iif,
+  inport,
+  lod,
+  mot,
+  NWE,
+  OEN,
+  PRES,
+  REGONS,
+  SAIs,
+  SER,
+  synopsys,
+  TE,
+  TIMOUT,
+  tolen,
+  UE,
+  WRON,
diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml
index 16be3910732bf..3eeb062da1670 100644
--- a/.github/workflows/check.yml
+++ b/.github/workflows/check.yml
@@ -41,9 +41,9 @@ jobs:
           echo "::add-matcher::nuttx/.github/nxstyle.json"
           python3 -m venv .venv
           source .venv/bin/activate
-          pip install cmake-format black isort flake8
+          pip install codespell cmake-format black isort flake8
           cd nuttx
           commits="${{ github.event.pull_request.base.sha }}..HEAD"
           git log --oneline $commits
-          echo "../nuttx/tools/checkpatch.sh -u -m -g $commits"
-          ../nuttx/tools/checkpatch.sh -u -m -g $commits
+          echo "../nuttx/tools/checkpatch.sh -c -u -m -g $commits"
+          ../nuttx/tools/checkpatch.sh -c -u -m -g $commits
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 918eb224b62d1..c2db384358f9d 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -16,4 +16,4 @@ repos:
     -   id: nxstyle
         name: nxstyle
         language: script
-        entry: ./tools/checkpatch.sh -f
+        entry: ./tools/checkpatch.sh -c -f


Reviews:
user: login: acassis
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-05-02T12:19:00Z
user: login: xiaoxiang781216
body: Thanks for enabling the spell check.
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-03T03:23:11Z
user: login: sumpfralle
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-03T04:08:29Z
user: login: xiaoxiang781216
body: LGTM, thanks.
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-05-03T04:10:26Z
user: login: hartmannathan
body: Thanks for adding codespell to CI!
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-04T17:06:16Z
user: login: sumpfralle
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-04T23:35:21Z
user: login: xiaoxiang781216
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-05T01:36:47Z
user: login: xiaoxiang781216
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-05-05T01:37:28Z
user: login: hartmannathan
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-05T01:43:46Z
user: login: hartmannathan
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-05-05T01:50:34Z
user: login: sumpfralle
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-05T11:24:24Z

Review comments:
diff_hunk: @@ -41,9 +41,11 @@ jobs:
           echo "::add-matcher::nuttx/.github/nxstyle.json"
           python3 -m venv .venv
           source .venv/bin/activate
-          pip install cmake-format black isort flake8
+          pip install codespell cmake-format black isort flake8
           cd nuttx
           commits="${{ github.event.pull_request.base.sha }}..HEAD"
           git log --oneline $commits
           echo "../nuttx/tools/checkpatch.sh -u -m -g $commits"
           ../nuttx/tools/checkpatch.sh -u -m -g $commits
+          echo "Running codespell for changed files (see .codespellrc)"
+          ../nuttx/tools/checkpatch.sh -c -g $commits
path: .github/workflows/check.yml
user: login: xiaoxiang781216
body: why not merge with line 49
created_at: 2025-05-03T03:22:40Z
author_association: CONTRIBUTOR
diff_hunk: @@ -41,9 +41,11 @@ jobs:
           echo "::add-matcher::nuttx/.github/nxstyle.json"
           python3 -m venv .venv
           source .venv/bin/activate
-          pip install cmake-format black isort flake8
+          pip install codespell cmake-format black isort flake8
           cd nuttx
           commits="${{ github.event.pull_request.base.sha }}..HEAD"
           git log --oneline $commits
           echo "../nuttx/tools/checkpatch.sh -u -m -g $commits"
           ../nuttx/tools/checkpatch.sh -u -m -g $commits
+          echo "Running codespell for changed files (see .codespellrc)"
+          ../nuttx/tools/checkpatch.sh -c -g $commits
path: .github/workflows/check.yml
user: login: sumpfralle
body: I intended to display a visible reference to the name of the configuration file (easing the process of dealing with false positives). But the codespell call already emits the configuration file location. Thus, I will merge these. Thanks for the pointer!
created_at: 2025-05-03T04:08:29Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,15 @@
+ *   Set max equivalent capacitance for sheild channel.
path: .codespell-ignore-lines
user: login: hartmannathan
body: I think we should only add codespell exceptions for false positives. For example, Synopsys is the name of a vendor, not a misspelling of "synopsis", so that is a correct exception.

But "sheild" here is actually a misspelling. It should be "shield." I think it would be better to correct the spelling error (in a separate PR). The 2 occurrences of "Set max equivalent capacitance for sheild channel" are in arch/xtensa/src/esp32s2/esp32s2_touch_lowerhalf.h and
arch/xtensa/src/esp32s3/esp32s3_touch_lowerhalf.h.

created_at: 2025-05-04T17:05:14Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,15 @@
+ *   Set max equivalent capacitance for sheild channel.
path: .codespell-ignore-lines
user: login: sumpfralle
body: Thank you for taking a detailed look!

Yes, this file is supposed to contain only *valid exceptions*. It looks like I was tricked by the existence of the function named `touch_lh_waterproof_get_sheild_driver` into believing, that this spelling could be intended.

I corrected the remaining occurrences of the word "sheild" and removed the exception. But I kept the function names containing this string unchanged for now (within the scope of this PR).

Do you have a suggestions, how to treat these function names?
* A) keep them unchanged (annoying, but compatibility-friendly)
* B) rename them (may break compilation for *very few* users, but is easy to fix)
* C) rename and add backwards-compatibility `define` for allow both the wrong spelling and the correct spelling

Your thoughts?
(I will submit this in a separate PR)
created_at: 2025-05-04T23:35:21Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,15 @@
+ *   Set max equivalent capacitance for sheild channel.
path: .codespell-ignore-lines
user: login: xiaoxiang781216
body: B is best choice.
created_at: 2025-05-05T01:36:47Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,15 @@
+ *   Set max equivalent capacitance for sheild channel.
path: .codespell-ignore-lines
user: login: hartmannathan
body: Agree with @xiaoxiang781216, B is best here IMHO.
created_at: 2025-05-05T01:43:46Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,15 @@
+ *   Set max equivalent capacitance for sheild channel.
path: .codespell-ignore-lines
user: login: sumpfralle
body: Thanks for your comments!

I will fix this function name as part of another PR with similar content.
created_at: 2025-05-05T11:24:24Z
author_association: CONTRIBUTOR

PR comments:
user: login: nuttxpr
created_at: 2025-05-02T12:22:46Z
body: [**\[Experimental Bot, please feedback here\]**](https://github.com/search?q=repo%3Aapache%2Fnuttx+13552&type=issues)

__Fill In The Commit Message:__ This PR contains a Commit with an Empty Commit Message. Please fill in the Commit Message with the PR Summary.



Yes, this PR meets the NuttX requirements, although the Testing section could be improved.

**Strengths:**

* **Clear Summary:**  The summary explains the "why," "what," and "how" of the change effectively.
* **Thorough Impact Assessment:** The impact section covers all relevant areas and clearly explains the potential effects of the change, especially on CI and pre-commit workflows.
* **Provides Context:**  The summary provides valuable context about the current state of spelling errors in the repository and your plan to address them.


**Weaknesses:**

* **Incomplete Testing:** While pre-commit testing is shown, the crucial CI testing is missing.  You *must* test and demonstrate the CI integration before merging. Include the CI logs *after* the changes are implemented showing the successful codespell check.  Since this PR introduces the CI check, showing it working is essential.
* **Missing Build Host/Target Information:**  Even though the core change is not platform-specific, it's still good practice to provide information about the environment where you developed and tested these changes (OS, compiler, etc.). While the changes affect the CI pipeline, which runs on various systems, specifying your local development environment is helpful for reproducibility.



**Recommendation:**

Before merging, add the following:

1. **CI Test Results:** Run the CI workflow with this PR and include the successful logs in the Testing section. Show how the CI reacts both to a file with a spelling error and a file without.
2. **Development Environment Details:** Add details about your build host in the Testing section (OS, CPU architecture, compiler). Even if it's not strictly required for this change, it's good practice and improves reproducibility.

By addressing these points, your PR will be even stronger and demonstrate that the changes are thoroughly tested and ready for integration.

author_association: NONE
user: login: xiaoxiang781216
created_at: 2025-05-05T01:38:14Z
body: @sumpfralle you could add the spell check fix in this PR, so we can proceed more quickly.
author_association: CONTRIBUTOR
user: login: simbit18
created_at: 2025-05-05T14:59:48Z
body:  need to do the same also in the **nuttx-apps** repository

https://github.com/apache/nuttx-apps/blob/master/.github/workflows/check.yml

@sumpfralle can you please do it?
author_association: CONTRIBUTOR
user: login: sumpfralle
created_at: 2025-05-08T13:36:51Z
body: > need to do the same also in the **nuttx-apps** repository

Yes, I plan to take a look at the apps repository, after everything is finished for the nuttx repository.
author_association: CONTRIBUTOR
user: login: simbit18
created_at: 2025-05-08T13:40:43Z
body: @sumpfralle Thanks
author_association: CONTRIBUTOR