streetsidesoftware / cspell

A Spell Checker for Code!

Home Page:https://cspell.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: --config flag does not work

Zamiell opened this issue · comments

commented

Info

Kind of Issue

  • runtime - command-line tools

Which Tool or library

  • cspell -- the command-line spelling tool

Which Version

Version: 7.0.1

Issue with supporting library?

  • No

OS:

  • Windows

version:

10

Bug Description

Describe the bug

The --config command line flag does not work.

To Reproduce

Steps to reproduce the behavior:

mkdir test
cd test
echo "misspelledword" > README.md
echo '{ "words": ["misspelledword"] }' > cspell.json
npx cspell README.md # Results in 0 errors, as expected.
echo "{}" > cspell.temp.json
npx cspell README.md --config cspell.temp.json # Results in 0 errors, even though "misspelledword" should be an illegal word.

Here, CSpell seems to ignore the --config flag and instead use the config at the default path. So maybe we need to turn off the "find default config" logic when the --config flag is specified?

@Zamiell,

Thank you for the excellent example.

CSpell will search for the nearest CSpell config file for every file checked.

Please try:

echo '{"noConfigSearch": true}' > cspell.temp.json
commented

Ah, that does work, thank you.

I propose that the noConfigSearch option should be automatically enabled when the CLI is invoked with the --config flag. What do you think about that?

@Jason3S any update on this?

@Zamiell,

I don't think it is a good idea to change the behavior. Although I see how its current behavior was unexpected.

The original idea, was the local config has more knowledge of the files being checked than a global config.

This allows for things like specifying the language.

For example:

cspell.config.yaml - language: en
i18n/de/cspell.config.yaml - language: de
i18n/de/README.md

At the root:

  • cspell "**/*.md", would use German when spellchecking i18n/de/README.md.

But by automatically turning on noConfigSearch, the following would break:

  • cspell --config cspell.config.yaml "**/*.md" would use English instead of German.

Even though both invocations of cspell use cspell.config.yaml, the behavior would be different.

I propose added two new options: --no-config-search and --config-root.

  • --no-config-search would just enabled adding the behavior to the command line.
  • --stop-config-search-at <dir> would tell the spellchecker to not look further up the hierarchy than the specified <dir>. It also makes sense that more than one stop could be wanted.

Sounds good, thank you!

I'm going to close this, since #4836 will take care of the remaining issue.

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.