Skip to main content

CommentSpellCheck

python testing

The CommentSpellCheck (CSC) package provides a script that automatically spell checks the comments of a code base. It was originally developed to be run on the SimpleITK and ITK code bases.

Here is how it is typically run:

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

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

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

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

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

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

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

Disabling Spell Checking

Spell checking can be disabled for sections of code by using special

comments. The following comments will disable spell checking until the corresponding end comment is found.

// spell-check-disable

// This comment will not be spell checked.

// spell-check-enable

Note that for C-style, multi-line comments, the disable and enable comments must be in seperate comments. If the disable command is found in a multi-line comment, spell checking will be disabled for the entire multi-line comment.

/*
spell-check-disable
spell-check-enable
This comment will NOT be spell checked
*/
/* spell-check-enable */
/* This comment WILL be spell checked */

Dictionary notes

We use PySpellChecker as the underlying spellchecker and its associated default dictionary. Previously we used the pyenchant package and its default dictionary. The pyenchant package requires an underlying C library, which is not available on all platforms. PySpellChecker is a pure Python package and works on all platforms with no additional dependencies.

Metadata

Release files for comment-spell-check 0.4.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for comment-spell-check 0.4.4
File Size Uploaded
comment_spell_check-0.4.4.tar.gz 89.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for comment-spell-check 0.4.4
File Interpreter ABI Platform
comment_spell_check-0.4.4-py3-none-any.whl Python 3 none any Details

Total release size: 118.4 kB

Release files / comment_spell_check-0.4.4.tar.gz

Download URL comment_spell_check-0.4.4.tar.gz
Size 89.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9212a1a962df9366965d95399d3ffba1f3ec82bd6f088c53a65654cc1f8a7396
BLAKE2b-256 checksum
How to use checksums
c65061b2cf9201dd7a9dadd1ef6299ffdf1251d5cad24a92970d325e7d96bb8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.13

Release files / comment_spell_check-0.4.4-py3-none-any.whl

Download URL comment_spell_check-0.4.4-py3-none-any.whl
Size 28.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9968046b233b5fe9fd8dda807aafdc48107154b3d88117814d26a22b84ce0d9a
BLAKE2b-256 checksum
How to use checksums
4905a33083d1173bf589d38986a1795f0166f05dc93e662227fd25a271857276
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.13

Release history Release notifications | RSS feed

This release

0.4.4 This release

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page