npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

cspell-grammar

v9.4.0

Published

Grammar parsing support for cspell

Readme

cspell-grammar

CSpell Grammar is used to generate a parser. The Parser is used to add context / scope to parts of a document, making it easier to define the parts to spell spell checked.

This is to address the issues and limitations related to ignoreRegExpList and includeRegExpList.

The parser is use to add scope to sections of a document. The scope can then be used to apply spell checking rules.

Example: Only check comments and strings

rules:
  '*': false
  comment: true
  string: true

It can be even more powerful like controlling the language settings based upon scope.

rules:
  comment:
    language: en
  string:
    language: en,fr
    dictionaries: ['marketing-terms'],
    caseSensitive: true
  string.javascript:
    caseSensitive: false

Rules are applied in the order they match the scope of the text.

When checking JavaScript files with the above example rules:

  • strings will:
    • use the locale en,fr
    • the marketing-terms dictionary will be enabled
    • caseSensitive will be true
  • everything else:
    • locale: en
    • caseSensitive will be false

At its core, cspell-grammar uses a simplified form of the TextMate grammar.

Reasoning

Why use a grammar parser? Couldn't a colorizer / highlighter or a language AST be used? At one level, needs of the spell checker are simpler and different from colorizers or language AST parsers. The goal of a spell checker is to spell check relevant text. The spell check does not need to care about the syntactical correctness of a document or presentation.

The goal of a grammar parser for the spell checker is to allow the user to decide:

  1. What text should be checked.
  2. Which dictionaries (or languages) should be used.
  3. Are accents and case important

Note: CSpell is a pure JavaScript application, so including the Oniguruma is not an option.

Considerations

  • Parsing a document should be fast - meaning the grammar should be as simple as possible to meet the needs of the spell checker and not focus on scope detail. This is where a colorizer grammar is not a good fit to be used.
  • AST's are a bit of an overkill for a spell checker. They provide too much detail while not bringing much benefit from the detail.

Transformation

Consider the following bit of LaTeX:

k\"{o}nnen
können

For the spell checker to work correctly, the \"{o} should be transformed into ö before it is checked against the German dictionary.

This creates a few challenges.

Possible options:

  1. Simple whole document substitution
    • Challenges
      • It is not context aware and might replace the wrong text.
      • It changes the location of the words and messes up issue reporting (some sort of Map would be needed to get the correct line / character offset).
  • Advantages
    • Easy to implement except for the context and mapping.
  1. Scope level substitution Transformations occur at the scope level.
    • Challenges
      • offset mapping is still and issue (maybe)
      • need a way to merge text with adjacent scopes after transformation
    • Advantages
      • it is context aware