Use codespell's dictionary for spell checking

When we first enabled spell checking, we duplicated the dictionary file
used by the kernel community and named it `openbmc-spelling.txt`. Since
we added the dictionary in 2021, only two changes have been made to it.

Meanwhile, the size of the kernel community’s dictionary has grown from
32 KB to 1.4 MB and is now included as part of the codespell library.
As the dictionary is readily available on the system, we will now use
it directly for spell checks. This offers several benefits:

1. Automatically use the latest dictionary whenever the codespell
   library is updated.
2. Reduce maintenance overhead and avoid data duplication.

In the future, if we need to add a word that is specific to OpenBMC, we
can create a new dictionary file with just those entries and run a
separate codespell check using that file.

Change-Id: I2897ab159e0a6c14480e1ee2593761ab550a19e9
Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
diff --git a/scripts/format-code.sh b/scripts/format-code.sh
index d909f33..43a3278 100755
--- a/scripts/format-code.sh
+++ b/scripts/format-code.sh
@@ -151,6 +151,22 @@
 }
 trap clean_up_file EXIT
 
+function find_codespell_dict_file() {
+    local python_codespell_dict
+    # @formatter:off
+    python_codespell_dict=$(python3 -c "
+import os.path as op
+import codespell_lib
+codespell_dir = op.dirname(codespell_lib.__file__)
+codespell_file = op.join(codespell_dir, 'data', 'dictionary.txt')
+print(codespell_file if op.isfile(codespell_file) else '', end='')
+" 2> /dev/null)
+    # @formatter:on
+
+    # Return the path if found, otherwise return an empty string
+    echo "$python_codespell_dict"
+}
+
 function do_commit_spelling() {
     # Write the commit message to a temporary file
     git log --format='%B' -1 > "$commit_filename"
@@ -158,12 +174,21 @@
     # Some names or emails appear as false-positive misspellings, remove them
     sed -i "s/Signed-off-by.*//" "$commit_filename"
 
-    # Run the codespell with openbmc specific spellings on the patchset
-    echo -n "openbmc-dictionary - misspelling count >> "
+    # Get the path to the dictionary.txt file
+    local codespell_dict
+    codespell_dict=$(find_codespell_dict_file)
 
-    codespell -D "${CONFIG_PATH}/openbmc-spelling.txt" -d --count "$commit_filename"
+    # Check if the dictionary file was found
+    if [[ -z "$codespell_dict" ]]; then
+        echo "Error: Could not find dictionary.txt file"
+        exit 1
+    fi
 
-    # Run the codespell with generic dictionary on the patchset
+    # Run the codespell with codespell dictionary on the patchset
+    echo -n "codespell-dictionary - misspelling count >> "
+    codespell -D "$codespell_dict" -d --count "$commit_filename"
+
+    # Run the codespell with builtin dictionary on the patchset
     echo -n "generic-dictionary - misspelling count >> "
     codespell --builtin clear,rare,en-GB_to_en-US -d --count "$commit_filename"
 }