Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

AtomLinter/linter-spell

Repository files navigation

linter-spell

Travis‑CI Build Status AppVeyor Build Status dependencies Status devDependencies Status

Multilingual grammar-specific spell checking for Atom and linter using Ispell compatible interface such as GNU Aspell or Hunspell.

Installing

Use the Atom package manager and search for "linter-spell", or from a shell run

apm install linter-spell

Prerequisites

This package relies on a Ispell compatible package such as GNU Aspell or Hunspell.

Usage

Spell checking is done upon document save with misspellings displayed by linter. Misspellings can be corrected or added to personal dictionary using the intentions package via ctrl+enter on OSX and alt+enter on Linux and Windows.

Manual language selection can be done by clicking on the status bar language indicator or by using the default keybinding alt+y on Linux or ctrl+shift+y on other platforms.

Grammar and Dictionary Providers

Spell checking plain text, Markdown, or AsciiDoc documents is included in the package. To spell check other document types use a linter-spell-grammar provider. To use additional dictionaries use linter-spell-dictionary provider. Current providers are listed in the table below (D=Dictionary, G=Grammar, D/G=Dictionary/Grammar).

Purpose Package Type Dependencies
Ignore CJK words linter‑spell‑cjk D None
Ispell compatible spell checking Included in linter‑spell D None
Project specific dictionaries linter‑spell‑project D None
AsciiDoc spell checking Included in linter‑spell D/G language‑asciidoc
Git Commit Message spell checking Included in linter‑spell D/G language‑git
GitHub flavored Markdown spell checking Included in linter‑spell D/G language‑gfm
HTML spell checking linter‑spell‑html D/G language‑html
Javascript spell checking linter‑spell‑javascript D/G language‑javascript or language‑babel
JSON spell checking linter‑spell‑javascript D/G language‑json
LaTeX, TeX & BibTeX spell checking linter‑spell‑latex D/G language‑latex
LaTeX spell checking linter‑spell‑latexsimple G language‑latexsimple
Markdown spell checking Included in linter‑spell D/G language‑markdown
Plain Text spell checking Included in linter‑spell D/G language‑text
Ruby spell checking linter‑spell‑ruby D/G language‑ruby
Shell script spell checking linter‑spell‑shellscript D/G language‑shellscript

Creating New Grammar Providers

New grammars can be added by implementing a linter-spell-grammar provider. This can be done by adding the following to package.json

"providedServices": {
  "linter-spell-grammar": {
    "versions": {
      "1.0.0": "provideGrammar"
    }
  }
}

The provided service should be as follows

function provideGrammar () {
  return [{
    grammarScopes: ['source.gfm'],
    findLanguageTags: textEditor => { return ['en-US'] },
    checkedScopes: {
      'source.gfm': true,
      'markup.code.c.gfm': false,
      'markup.underline.link.gfm': () => atom.config.get('linter-spell.checkLinks')
    },
    filterRanges: (textEditor, ranges) => {
      return {
        ranges: ranges,
        ignoredRanges: []
      }
    }
  }]
}

Multiple grammars can be provided by returning an array. grammarScopes is required, but all other properties and methods are optional.

The findLanguageTags method should scan textEditor for a file specific override of the user's default language and return RFC 5646 compliant language codes or [] if no language references were found. See linter‑spell‑latex for an implementation using TeX magic comments.

The checkedScopes list the grammar scopes that either checked or ignored. To explicitly check a scope use a value of true, while false will ignore that scope. To allow dynamic determination of scope spell checking a function may also be supplied. The function should take no arguments and return a truthy value. If this property is not provided then all scopes in grammarScopes will be checked. When it is provided all scopes default to ignored unless specified with a true value.

The filterRanges method should check the ranges parameter for sub-ranges within each ranges which are valid to spell check. It should return a list of modified ranges in ranges and can also return ignoredRanges for ranges that should not be checked. The interval difference between ranges and ignoredRanges will actually be checked.

Create New Dictionary Providers

New dictionaries can be added by implementing a linter-spell-dictionary provider. This can be done by adding the following to package.json

"providedServices": {
  "linter-spell-dictionary": {
    "versions": {
      "1.0.0": "provideDictionary"
    }
  }
}

The provided service should be as follows

function provideDictionary () {
  return [{
    name: 'Your dictionary name',
    grammarScopes: ['source.gfm'],
    languages: ['en-US'],
    checkRange: (textEditor, languages, range) => {
      return new Promise((resolve, reject) => resolve([{
        range: new Range([0, 1], [0, 4]),
        suggestions: ['bar'],
        actions: [{
          title: 'Add to my dictionary',
          apply: () => { /* add word to your dictionary. */ }
        }]
      }])
    },
    checkWord: (textEditor, languages, range) => {
      return new Promise((resolve, reject) => resolve({
        isWord: false, // return true if word is found
        suggestions: ['foo'],
        actions: [{
          title: 'Add to my dictionary',
          apply: () => { /* add word to your dictionary. */ }
        }]
      })
    }
  }]
}

Multiple grammars can be provided by returning an array. name and checkWord are required, but all other properties and methods are optional. If grammarScopes or languages are not provided then provider will be used for all grammar scopes or languages, respectively.

If checkRange is provided then it is assumed that the dictionary knows how find line breaks for all of the languages listed in languages. linter-spell will then move that provider to the front of the queue and allow it to perform word and breaks and return words that are potentially misspelled. Those potential misspellings are then passed to the dictionary providers that only define checkWord for an opportunity to check the word against their dictionary.

If a provider cannot find a word in its dictionary then it should at least return { isWord: false }. It may also return a list of suggestions or a list of actions to take on the misspelled word. For example, adding the word to a language specific dictionary.

About

Multilingual grammar-specific spell checking for Atom and linter using Ispell compatible interface such as GNU Aspell or Hunspell.

Resources

License

Stars

Watchers

Forks

Packages

No packages published