Skip to content

Commit 5e67a2d

Browse files
authored
Merge pull request #70 from dave3d/DisableOption
Disable option
2 parents 46c04d4 + 6c80858 commit 5e67a2d

File tree

4 files changed

+61
-13
lines changed

4 files changed

+61
-13
lines changed

README.md

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,66 @@ Here is how it is typically run:
1111

1212
python comment_spell_check.py --exclude Ancillary $SIMPLEITK_SOURCE_DIR/Code
1313

14-
This command will recursively find all the '.h' files in a directory,
14+
This command will recursively find all the \'.h\' files in a directory,
1515
extract the C/C++ comments from the code, and run a spell checker on them.
16-
The **'--exclude'** flag tells the script to ignore any file that has
17-
'Ancillary' in its full path name. This flag will accept any
16+
The **\'\-\-exclude\'** flag tells the script to ignore any file that has
17+
\'Ancillary\' in its full path name. This flag will accept any
1818
regular expression.
1919

20-
In addition to pyenchant's English dictionary, we use the words in
20+
In addition to pyenchant\'s English dictionary, we use the words in
2121
**additional_dictionary.txt**. These words are proper names and
2222
technical terms harvest by hand from the SimpleITK and ITK code bases.
2323

2424
If a word is not found in the dictionaries, we try two additional checks.
2525

2626
1. If the word starts with some known prefix, the prefix is removed
27-
...and the remaining word is checked against the dictionary. The prefixes
28-
...used by default are **'sitk'**, **'itk'**, and **'vtk'**. Additional
29-
...prefixes can be specified with the **'--prefix'** command line argument.
27+
and the remaining word is checked against the dictionary. The prefixes
28+
used by default are **\'sitk\'**, **\'itk\'**, and **\'vtk\'**. Additional
29+
prefixes can be specified with the **\'\-\-prefix\'** command line argument.
3030

3131
2. We attempt to split the word by capitalization and check each
32-
...sub-word against the dictionary. This method is an attempt to detect
33-
...camel-case words such as 'GetArrayFromImage', which would get split into
34-
...'Get', 'Array', 'From', and 'Image'. Camel-case words are very commonly
35-
...used for code elements.
32+
sub\-word against the dictionary. This method is an attempt to detect
33+
camel-case words such as \'GetArrayFromImage\', which would get split into
34+
\'Get\', \'Array\', \'From\', and \'Image\'. Camel-case words are very commonly
35+
used for code elements.
3636

37-
The script can also process other file types. With the **'--suffix'**
37+
The script can also process other file types. With the **\'\-\-suffix\'**
3838
option, the following file types are available: Python (.py), C/C++
3939
(.c/.cxx), CSharp (.cs), Text (.txt), reStructuredText(.rst), Markdown (.md),
4040
Ruby (.ruby), R (.R), and Java (.java). Note that reStructuredText files are
4141
treated as standard text. Consequentially, all markup keywords that are not
4242
actual words will need to be added to the additional/exception dictionary.
4343

44+
## Disabling Spell Checking
45+
46+
Spell checking can be disabled for sections of code by using special
47+
48+
comments. The following comments will disable spell checking until
49+
the corresponding end comment is found.
50+
```
51+
// spell-check-disable
52+
53+
// This comment will not be spell checked.
54+
55+
// spell-check-enable
56+
```
57+
58+
Note that for C-style, multi-line comments, the disable and enable
59+
comments must be in seperate comments. If the disable command
60+
is found in a multi-line comment, spell checking will be
61+
disabled for the entire multi-line comment.
62+
63+
```
64+
/*
65+
spell-check-disable
66+
spell-check-enable
67+
This comment will NOT be spell checked
68+
*/
69+
/* spell-check-enable */
70+
/* This comment WILL be spell checked */
71+
```
72+
73+
4474
## Dictionary notes
4575

4676
We use [PySpellChecker](https://github.com/barrust/pyspellchecker) as the

comment_spell_check/comment_spell_check.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,21 @@ def spell_check_file(
268268
bad_words = []
269269
line_count = 0
270270

271+
disable_spell_check = False
272+
271273
for c in clist:
274+
if "spell-check-disable" in c.text().lower():
275+
disable_spell_check = True
276+
logger.info(" Spell checking disabled")
277+
continue
278+
279+
if "spell-check-enable" in c.text().lower():
280+
disable_spell_check = False
281+
logger.info(" Spell checking enabled")
282+
283+
if disable_spell_check:
284+
continue
285+
272286
mistakes = spell_check_comment(spell_checker, c, prefixes=prefixes)
273287
if len(mistakes) > 0:
274288
logger.info("\nLine number %s", c.line_number())

tests/example.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
// With node id's.
2626
// With the itemIndex'th where itemIndex is a variable name.
2727

28+
// spell-check-disable
29+
// Some comment with a misspelled word: definately
30+
// spell-check-enable
31+
2832
#include <stdio.h>
2933

3034
int test_int;

tests/test_comment_spell_check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def test_url(self):
109109
"""URL test"""
110110
url = (
111111
"https://raw.githubusercontent.com/SimpleITK/SimpleITK/"
112-
"refs/heads/master/.github/workflows/additional_dictionary.txt"
112+
"refs/heads/main/.github/workflows/additional_dictionary.txt"
113113
)
114114
runresult = subprocess.run(
115115
[

0 commit comments

Comments
 (0)