Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESLint Plugin: Configuration option to add words to the dictionary #3233

Closed
tim-fabian opened this issue Jul 15, 2022 · 15 comments · Fixed by #3247
Closed

ESLint Plugin: Configuration option to add words to the dictionary #3233

tim-fabian opened this issue Jul 15, 2022 · 15 comments · Fixed by #3247

Comments

@tim-fabian
Copy link

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.

@Jason3S
Copy link
Collaborator

Jason3S commented Jul 15, 2022

@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 Jason3S removed the new issue label Jul 15, 2022
@Jason3S
Copy link
Collaborator

Jason3S commented Jul 15, 2022

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.

@tim-fabian
Copy link
Author

@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.

Jason3S added a commit that referenced this issue Jul 18, 2022
## Experimental Feature
Add the ability to add words to a custom dictionary.

Mostly fixes: #3233, but is flaky because it is using an unsupported technique to detect when a fix has been applied.
-  Option: `customWordListFile`
      **Experimental**: Specify a path to a custom word list file (A utf-8 text file with one word per line). This file is used to present the option to add words.
@Jason3S Jason3S reopened this Jul 19, 2022
@Jason3S
Copy link
Collaborator

Jason3S commented Jul 19, 2022

@marcoSven
Copy link

@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

@Jason3S
Copy link
Collaborator

Jason3S commented Aug 1, 2022

@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" }],

@marcoSven
Copy link

marcoSven commented Aug 2, 2022

@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

@Jason3S
Copy link
Collaborator

Jason3S commented Aug 2, 2022

@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.

@marcoSven
Copy link

marcoSven commented Aug 2, 2022

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.

@Jason3S
Copy link
Collaborator

Jason3S commented Aug 2, 2022

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

Please try something like:

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

@marcoSven
Copy link

🙏 that works!

@Jason3S
Copy link
Collaborator

Jason3S commented Aug 6, 2022

@marcoSven,

Please double check the dictionary file. It might be full of junk that was added as you type. See: #3233 (comment)

@marcoSven
Copy link

Thank you, I have not tested it yet.

@Jason3S
Copy link
Collaborator

Jason3S commented Oct 13, 2022

Per the RFC discussion on ESLint (eslint/rfcs#93), using ESLint to add words to a file is not possible.

@Jason3S Jason3S closed this as not planned Won't fix, can't repro, duplicate, stale Oct 13, 2022
@github-actions
Copy link
Contributor

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 github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants