streetsidesoftware / cspell

A Spell Checker for Code!
https://cspell.org
MIT License
1.24k stars 94 forks source link

Document "files" options (and all other missing options) in CSpell configuration #2738

Open Zamiell opened 2 years ago

Zamiell commented 2 years ago

Hello again,

CSpell is a fantastic tool, and many projects use CSpell to spell-check their entire repository. However, you don't want to use the tool on the entire repository, because e.g. you don't care about the node_modules directory. So, you would spell-check a subset of it, like so:

perform_spell_check.sh

npx cspell --no-progress --no-summary "src/**/*.ts"
npx cspell --no-progress --no-summary "docs/**/*.md"

But these two globs are hard coded, which is bad. It would be better if users could instead specify the glob patterns that correspond to their respective projects in the CSpell configuration file, like this:

.cspell.json

{
    "version": "0.2",
    "words": [
        "foo"
    ],
    "includePaths": [
      "src/**/*.ts",
      "docs/**/*.md"
    ]
}

Then, one could simply do a npx cspell, and since no glob patterns were specified on the command-line, CSpell would assume that the user wants to spell check the project itself, and it would automatically use the globs found in the "includePaths" option.

Furthermore, this feature could also be tied in to the VSCode extension. If I open a project in VSCode, the extension can read the "includePaths" option in order to know whether or not it should show the blue squiggly lines for the particular file that I have open. (I guess that once the feature is in place, this would happen automatically? Not 100% sure.)

This is related to issue #2536, because I want to ensure that there are no orphaned words in the CSpell configuration file, and perform this check in CI. But since there is no central location for "which files to spell check", I have to repeat the globs in multiple places, violating the DRY principle, and potentially causing bugs if any of the globs change later on.

Jason3S commented 2 years ago

@Zamiell,

Please try files. It is better documented in the Spell Checker Extension: Configuration Settings - Spell Checker.

{
    "version": "0.2",
    "words": [
        "foo"
    ],
    "files": [
      "src/**/*.ts",
      "docs/**/*.md"
    ]
}
Zamiell commented 2 years ago

Thanks Jason, that works great. Shouldn't all of the configuration options be documented on this page?

Jason3S commented 2 years ago

Thanks Jason, that works great. Shouldn't all of the configuration options be documented on this page?

It should be. It just hasn't happened yet.

The intent is to generate the documentation from the cspell/cspell.schema.json file. That is how it is generated for the Extension website.

Jason3S commented 2 years ago

Related to #571

Zamiell commented 2 years ago

Ok, thank you.

Related question: In Prettier, it is possible to check my entire repository (recursively) with:

$ npx prettier . --check

ESlint works in the same way, i.e. you can just specify a dot and it will recursively check everything.

With CSpell, that does not seem to be possible:

$ npx cspell .
CSpell: Files checked: 0, Issues found: 0 in 0 files

Is it possible to specify some sequence of characters to search for all files? And should CSpell be changed to work like ESLint/Prettier in this regard?

Jason3S commented 2 years ago

Please try:

$ npx cspell "**"

I had not realize prettier and ESLint had that. I think they are matching git's behavior: git add .

Zamiell commented 2 years ago

That works, thank you! Should I open a separate issue for npx cspell .?

Jason3S commented 2 years ago

That works, thank you! Should I open a separate issue for npx cspell .?

Yes.