IntelliJ IDEA 2020.1 Help

Grammar

IntelliJ IDEA checks the grammar of text files and elements in your source code: string literals, comments, JavaDocs, and even your commit messages. It highlights mistakes related to morphology, punctuation, overall structure and style.

By default, IntelliJ IDEA includes English language support and suggests to add another language if it detects one. For information about supported languages and how to add them, see Proofreading.

IntelliJ IDEA checks grammar using the Grammar inspection. In the Settings/Preferences dialog Ctrl+Alt+S, select Editor | Inspections. The Grammar inspection is under Proofreading. By default, it is set to the lowest severity level (subtle underline) and applies in all scopes.

Fix grammar mistake

  1. Place the caret at a word highlighted by the Grammar inspection.

  2. Click the Intention action icon or press Alt+Enter to show the available intention actions.

  3. Select Fix and choose the proper fix from the list of suggestions.

Besides applying the fix, you can either disable the rule that triggered the inspection or add the detected phrase as an exception.

Scope of grammar checks

You can configure the types of files and specific code constructs where you want to check grammar. For example, you can enable grammar checks for Markdown files, for strings and comments in Java files, and disable grammar checks for YAML and JSON.

Configure where to check grammar

  1. In the Settings/Preferences dialog Ctrl+Alt+S, select Editor | Proofreading | Grammar.

  2. On the Scope tab, select the code constructs where you want to check grammar and the types of files for which you want to enable grammar checks.

Option

Description

String literals

Check grammar in string literals.

Comments

Check grammar in generic line and block comments.

Documentation

Check grammar in embedded code documentation, such as JavaDoc comments.

Commit messages

Check grammar in commit messages for the configured VCS. If you enable this, IntelliJ IDEA adds the corresponding inspection tool to the .idea/vcs.xml configuration file.

Grammar rules

IntelliJ IDEA checks grammar against a set of rules defined for the language. For example, in English, there are rules how to properly use articles, commas, and past tense forms, stylistic hints for creative and plain writing, common typos and words that are commonly confused, proper collocations, and many more.

Most of these rules are enabled by default and are definitely mistakes. However, some of them are suggestion that you may not agree with or not care about. In this case, you can disable a specific rule from the intention action or in the settings.

Configure the set of rules

  1. In the Settings/Preferences dialog Ctrl+Alt+S, select Editor | Proofreading | Grammar.

  2. On the Rules tab, select the rules that you want to check for.

Use the search field to filter the list of rules with a keyword, such as article or comma.

Exceptions

Exceptions are words and phrases that you want to always consider correct. If some rule triggers a mistake on a phrase that you do not want to highlight, you do not need to disable this rule, because then it will not trigger in other places where the mistake is valid. In this case, you can add the phrase as an exception using the intention action.

See all added exceptions

  1. In the Settings/Preferences dialog Ctrl+Alt+S, select Editor | Proofreading | Grammar.

  2. On the Exceptions tab, see the list of words and phrases added as exceptions. You can remove an exception by selecting it and clicking the Remove button.

Last modified: 15 April 2020