cspell

Last updated on
12 July 2024

Drupal core 9.1.0-alpha1 and later supports automated code spell checking using cspell.

Pre-requisites

Before starting, you need to install node JS and yarn . Then run:

cd core
yarn install

Be mindful of disk space needs for this as well: node, npm, yarn and dependencies use up several hundred megabytes.

How it works

The config file for cspell is located at core/.cspell.json. Visit the official cspell documentation on Github for more information.

Example usages:

  • Checking files inside the core folder:
    cd core
    yarn run spellcheck:core
    

    Warning: the executing time for this command is about 5 to 30 minutes depending on your PC.

  • Or to checking any file or directory:
    cd core
    yarn run spellcheck "path/to/file/or/directory/**/*"
    

Making changes to Drupal's dictionary

Once an unknown word or words are reported, you have three options:

  • If there's a spelling error, spell the word correctly. If a compound word is not recognized, separating words by underscores or converting to CamelCase usually helps.
  • if there's an unrecognized English word or a correctly spelled technical term, add it to the Drupal dictionary file:
    core/misc/cspell/dictionary.txt (Note: all words in the dictionary must be lowercase)
  • if there's a correctly spelled, Drupal-specific noun or adjective (like "Olivero"), add it to the Drupal dictionary file:
    core/misc/cspell/drupal-dictionary.txt
    (Do not add abbreviations or machine, class, function, or method names to this dictionary, only proper words.)

Read the Spelling coding standards for more information and examples.

In general, using In Document Settings to disable checking is not encouraged.

Regenerating the Drupal dictionary

Currently the Drupal dictionary contains words that are misspelt in core at the time we added spellchecking to core. It might be necessary to regenerate the dictionary if misspelt words have been fixed without removing them from the Drupal dictionary.

To do this, from the command line, run:

cd core
yarn spellcheck:make-dict
yarn spellcheck:make-drupal-dict

Adding a flagword

cSpell supports flagwords - a list of words to be always considered incorrect. These are configured in core/.cspell.json. For example:

    // flagWords - list of words to be always considered incorrect
    // This is useful for offensive words and common spelling errors.
    // For example "hte" should be "the"
    "flagWords": [
      "hte"
    ],

Help improve this page

Page status: No known problems

You can: