Skip to content

Commit fd93c54

Browse files
authored
feat: Modified format_checkers to add checker name to dictionary allow (#1571)
* fixes #1567 * feat: Modified format_checkers to add checker name to dictionary allow if needed * fix: insertion method * fix: removed network request for online dictionary * docs: updated contributing.md for format_cherckers * refactor: added type hints
1 parent 89008a4 commit fd93c54

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ We use [pyupgrade](https://github.com/asottile/pyupgrade) to make sure our synta
237237

238238
We also have a spell checker set up to help us avoid typos in documentation. The [spelling actions readme file](https://github.com/intel/cve-bin-tool/tree/main/.github/actions/spelling) gives more information including how to add new words to the dictionary if needed.
239239

240-
We also have a tool to help make sure that new checkers are added to the tables in our documentation, this is automatically done with github actions. [The format_checkers code is here](https://github.com/intel/cve-bin-tool/blob/main/cve_bin_tool/format_checkers.py), if you're curious.
240+
We also have a tool to help make sure that new checkers are added to the tables in our documentation and relevant words associated with checker names are put in allow dictionary for spelling checks, this is done automatically with GitHub actions. [The format_checkers code is here](https://github.com/intel/cve-bin-tool/blob/main/cve_bin_tool/format_checkers.py), if you're curious.
241241

242242
You can view all the config files for GitHub Actions (what we use for Continuous Integration (CI)) in [the .github/workflows directory](https://github.com/intel/cve-bin-tool/tree/main/.github/workflows).
243243

cve_bin_tool/format_checkers.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""To reformat checkers table when cve_bin_tool/checkers/__init__.py is updated."""
55

66
import os
7+
import re
78

89
from cve_bin_tool import checkers
910

@@ -76,9 +77,33 @@ def update_checker_table(file_path, markdown):
7677
f.writelines(lines)
7778

7879

80+
def update_allowed_words(checkers_array: list[str]) -> None:
81+
"""Updates the allow.txt file with the new checkers"""
82+
file_path = os.path.join(
83+
os.path.abspath("."), ".github", "actions", "spelling", "allow.txt"
84+
)
85+
86+
checkers_words = re.findall(r"[^0-9_]+", "_".join(checkers_array))
87+
fileObj = open(file_path)
88+
words = fileObj.read().splitlines()
89+
fileObj.close()
90+
91+
for checker in checkers_words:
92+
if checker not in words:
93+
words.append(checker)
94+
95+
words = sorted(words, key=str.casefold)
96+
97+
fileObj = open(file_path, "w+")
98+
fileObj.writelines("\n".join(words))
99+
fileObj.close()
100+
101+
79102
if __name__ == "__main__":
80103
checkers_array = list(set(checkers.__all__) - {"Checker", "VendorProductPair"})
81-
checkers_array = reshape_list(sorted(checkers_array))
104+
checkers_array.sort()
105+
update_allowed_words(checkers_array)
106+
checkers_array = reshape_list(checkers_array)
82107
shape_list = max_checker_length(checkers_array)
83108
checkers_markdown = reformat_checkers(checkers_array, shape_list)
84109
update_checker_table(

0 commit comments

Comments
 (0)