cspell icon indicating copy to clipboard operation
cspell copied to clipboard

ESLint Plugin: Configuration option to add words to the dictionary

Open tim-fabian opened this issue 2 years ago • 13 comments

When using words that aren't recognized by cspell (in my case "textbox") there is no way to add these words to the dictionary (Unless I have missed something). The only way to disable the warning/error is by disabling the ESLint rule for that line.

It should be possible to modify the dictionary used by cspell in the ESLint options. This could be as simple as providing an array of strings. I think the vscode plugin already supports that.

I tried to use the "eslint-plugin-spellcheck" but unfortunately, it doesn't support "ignoreImports" or "ignoreImportProperties" and also doesn't provide suggestions.

tim-fabian avatar Jul 15 '22 07:07 tim-fabian

@tim-fabian,

Let me see if I understand you:

You would like the plugin to offer the option to add a word to your dictionary in addition to the suggestions.

I think that is a viable new feature.

Possible Workaround

In the meantime, if you are using the VSCode Code Spell Checker extension, it is possible to bind keys to have the extension add it to your CSpell configuration.

image

Jason3S avatar Jul 15 '22 14:07 Jason3S

Related to #2782

It is going to be a while before the library used to update CSpell Configuration files is ported to CSpell.

It might be possible to make a simpler option for use with the ESLint Plugin:

  • addWordsToFile: <path> This option would allow adding words to either a cspell.json file or a text file.

Jason3S avatar Jul 15 '22 15:07 Jason3S

@Jason3S

Let me see if I understand you

You understood that correctly.

It might be possible to make a simpler option for use with the ESLint Plugin:

  • addWordsToFile: This option would allow adding words to either a cspell.json file or a text file.

That sounds great and should probably be enough configuration for most users.

tim-fabian avatar Jul 15 '22 15:07 tim-fabian

@Jason3S

I added the option but it is not working for me, what could I be missing?

"@cspell/spellchecker": ["warn", { customWordListFile: "words.txt" }],

"words.txt" is in the same directory as ".eslintrc.js" and "cspell.config.js" Screen Shot 2022-08-01 at 9 58 36 AM

marcoSven avatar Aug 01 '22 07:08 marcoSven

@marcoSven,

As far as I can tell, ESLint plug-ins do not know which file loaded them. If you use a relative path name, the plug-in will use the current working directory as the base.

Please try:

"@cspell/spellchecker": ["warn", { customWordListFile: __dirname + "/words.txt" }],

Jason3S avatar Aug 01 '22 13:08 Jason3S

@Jason3S thank you for the suggestion unfortunately using the absolute path is also not working.

Using eslint v8.6.0 and cspell plgin v6.4.2

What else can I try?


id: @cspell/spellchecker cwd: /users/marco/project filename: /users/marco/project/text.js physicalFilename: /users/marco/project/text.js scope: global


id: @cspell/spellchecker cwd: /users/marco/project filename: /users/marco/project/text.js physicalFilename: /users/marco/project/text.js scope: global

Comment.line: ' spell spellchek' Suggestions: [ 'spellcheck', 'spellchecks', 'shellcheck', 'spellchecked', 'spellchecker', 'sepulcher', "spellcheck's", 'spelled', [length]: 8 ]

/users/marco/project/text.js 1:10 warning Unknown word: "spellchek" @cspell/spellchecker

✖ 1 problem (0 errors, 1 warning)

Screen Shot 2022-08-02 at 9 07 05 AM Screen Shot 2022-08-02 at 9 06 43 AM

marcoSven avatar Aug 02 '22 06:08 marcoSven

@marcoSven What are you hoping for? Option to add words or to read the words from you list?

To add words, use: ”addWords”: true opinion.

Reading words should work fine. But, adding words if flaky. The hack used to support that option does play well with the ESLint plug-in. Sometimes words are added as you type.

Jason3S avatar Aug 02 '22 07:08 Jason3S

Yes, I would like to add words to the dictionary from the quick fix.

Getting this error below, I must be missing something obvious.

"Configuration for rule "@cspell/spellchecker" is invalid: Value {"addWords":true,"customWordListFile":"/users/marco/project/words.txt","checkComments":true,"checkIdentifiers":true,"checkStringTemplates":true,"checkStrings":true,"debugMode":false,"generateSuggestions":true,"ignoreImportProperties":true,"ignoreImports":true,"numSuggestions":8} should NOT have additional properties."

Here is my config { addWords: true, customWordListFile: __dirname + "/words.txt",

Don't see the addWords option here

Sometimes words are added as you type.

Good to know thanks.

marcoSven avatar Aug 02 '22 09:08 marcoSven

I'm on my phone, so please forgive the formatting:

Please try something like:

{ customWordListFile: { path:"...", addWords: true }}

Jason3S avatar Aug 02 '22 15:08 Jason3S

🙏 that works!

marcoSven avatar Aug 02 '22 16:08 marcoSven

@marcoSven,

Please double check the dictionary file. It might be full of junk that was added as you type. See: https://github.com/streetsidesoftware/cspell/issues/3233#issuecomment-1188848954

Jason3S avatar Aug 06 '22 06:08 Jason3S

Thank you, I have not tested it yet.

marcoSven avatar Aug 06 '22 08:08 marcoSven

Per the RFC discussion on ESLint (https://github.com/eslint/rfcs/pull/93), using ESLint to add words to a file is not possible.

Jason3S avatar Oct 13 '22 05:10 Jason3S

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Nov 13 '22 05:11 github-actions[bot]