Eclipse: how to selectively disable spell check in certain comments
Categories:
Eclipse: Selectively Disabling Spell Check in Comments

Learn how to configure Eclipse to ignore specific comments or comment blocks during spell checking, improving code readability and reducing false positives.
Eclipse's built-in spell checker is a valuable tool for maintaining code quality and ensuring clear documentation. However, it can sometimes be overly zealous, flagging technical terms, code snippets, or non-English phrases within comments as errors. This article will guide you through various methods to selectively disable spell checking in Eclipse comments, allowing you to maintain a clean and accurate codebase without unnecessary distractions.
Understanding Eclipse's Spell Check Mechanism
Eclipse's spell checker operates based on dictionaries and configurable rules. By default, it checks all text within comments and string literals. While this is generally helpful, there are scenarios where you might want to bypass it. For instance, comments often contain code examples, URLs, or domain-specific terminology that are not standard dictionary words. Manually adding every such term to the user dictionary can be cumbersome and impractical. Fortunately, Eclipse provides mechanisms to control this behavior more granularly.
flowchart TD A[Start Spell Check] --> B{Is text in comment?} B -- Yes --> C{Is comment type excluded?} C -- Yes --> D[Skip Spell Check] C -- No --> E{Contains @SuppressWarnings("SpellChecking")?} E -- Yes --> D[Skip Spell Check] E -- No --> F{Check against Dictionaries} F --> G{Found in Dictionary?} G -- Yes --> H[No Error] G -- No --> I[Flag as Error] D --> J[Continue] H --> J[Continue] I --> J[Continue] B -- No --> J[Continue] J --> K[End Spell Check]
Eclipse Spell Check Decision Flow
Method 1: Using the @SuppressWarnings Annotation
For Java projects, Eclipse's Java Development Tools (JDT) offer a convenient way to suppress warnings, including spell check warnings, using annotations. While @SuppressWarnings("SpellChecking")
is not a standard Java annotation, Eclipse's JDT recognizes it for this specific purpose. This method is ideal for disabling spell check on a specific method, class, or even a single line of code within a comment block.
public class MyClass {
// @SuppressWarnings("SpellChecking")
// This comment contains technical terms like 'HttpServletRequest' and 'JSON parsing'.
// These terms would normally be flagged by the spell checker.
public void processRequest(HttpServletRequest request) {
// ... implementation ...
}
/**
* @SuppressWarnings("SpellChecking")
* This Javadoc comment describes a complex algorithm involving 'multithreading' and 'asynchronous' operations.
* The spell checker will ignore this entire block.
*/
public void performComplexTask() {
// ... implementation ...
}
}
Using @SuppressWarnings("SpellChecking")
in Java comments
@SuppressWarnings("SpellChecking")
annotation directly above the comment block or the code element you wish to exempt. For single-line comments, you can place it on the line immediately preceding the comment.Method 2: Configuring Spell Check Exclusions in Preferences
Eclipse provides global and project-specific preferences to fine-tune the spell checker. You can specify file types or even exclude certain regions within files from spell checking. This method is more suitable for broader exclusions, such as ignoring specific comment styles or entire file types.
1. Access Preferences
Go to Window > Preferences
(or Eclipse > Preferences
on macOS).
2. Navigate to Spell Checking Settings
In the preferences dialog, navigate to General > Editors > Text Editors > Spelling
.
3. Configure Exclusions
Here you can:
- Disable for specific content types: Uncheck the box next to 'Comments' or 'Strings' if you want to disable spell checking entirely for these elements across all files.
- Add words to user dictionary: For specific technical terms, you can add them to the 'User defined dictionary'.
- Ignore words with digits/mixed case: These options can help reduce false positives for variable names or version numbers.
4. Apply Changes
Click Apply and Close
to save your settings.
Method 3: Using Comment Tags for Exclusion (Advanced)
While not a direct spell check exclusion, you can leverage Eclipse's Task Tags or custom comment formatting to visually distinguish comments that should be ignored. This is more of a convention than a direct technical exclusion, but it can be effective in team environments. For example, you could define a custom task tag like // NO_SPELLCHECK:
and train your team to use it for specific comment blocks. While Eclipse won't automatically ignore these, it provides a visual cue.
// NO_SPELLCHECK: This comment contains a URL: https://example.com/technical-specifications
// and some non-English text: "Lorem ipsum dolor sit amet."
/*
* NO_SPELLCHECK:
* This block describes a complex data structure:
* {"id": "uuid", "name": "string", "value": "number"}
* The spell checker would flag 'uuid' and 'string' as errors.
*/
public class DataProcessor {
// ...
}
Using a custom NO_SPELLCHECK
tag in comments