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

💡: Ignore files not specified in files but passed to the argument. #5225

Closed
1 task done
fudom opened this issue Feb 5, 2024 · 7 comments · Fixed by #5328
Closed
1 task done

💡: Ignore files not specified in files but passed to the argument. #5225

fudom opened this issue Feb 5, 2024 · 7 comments · Fixed by #5328

Comments

@fudom
Copy link

fudom commented Feb 5, 2024

Problem

I use cspell.json to define files to be checked. For example the path src/**/*. This works great with the VSCode extension. But if I use the cspell cli to check a specific file, it ignores this include array files. It makes sense when scanning an individual file. But if Git hook (husky, lint-staged) is used for pre-commit, the individual files are also checked. Which also ignores the cspell.json files array.

Example:

root (snippet)
|- cspell.json
|- other.md
|- src/main.ts

cspell.json (snippet)

{
  "files": ["src/**/*"]
}
  • VSCode shows typos in src/**/* only. Not on root like other.md. (Correct/Expected)
  • CSpell CLI scanning repo also only shows the typos specified in files. (Correct/Expected)
  • CSpell CLI scanning specific file in the repo shows typos in the scanned file. Ignoring the files from cspell.json. I understand why. I think it's also correct. But maybe not what you expect. Especially when this is used in Git hook.
cspell -u --no-progress --relative --no-must-find-files ./other.md

Solution

I think we need a new option to respect the files array from cspell.json even when passing a file path to the arguments to scan.

cspell -u --no-progress --relative --no-must-find-files --strict ./other.md

I don't know how to name the new option. At this moment I call it strict. If the file you passed to check is not in the files array, it will ignore typos. Maybe only show a info, that the file is ignored by the configuration.

Alternatives

Currently I need to use ignorePaths for each individual file or path. Additional to the files array which is expected as the inverted logic "included files" (files), "excluded files" (ignorePaths). Or is it possible to ignore all (ignorePath) except files? But I would expect anything not specified in files to be ignored.

Additional Context

I would be great to setup all included and excluded files once. Which has also effect when checking individual files manually (Git hook). Maybe an option? Or does this already exist? Or is this finally a bug?

Code of Conduct

  • I agree to follow this project's Code of Conduct
@fudom fudom changed the title 💡: Ignores files not specified in files but passed to the argument. 💡: Ignore files not specified in files but passed to the argument. Feb 6, 2024
@Jason3S
Copy link
Collaborator

Jason3S commented Feb 6, 2024

@fudom,

Thank you for the feedback and suggestion.

The files setting is a bit confusing. It is used when no files are specified on the command-line. The logic was command-line wins over config.

The --file-list option was added to support commit hooks. Those files are filtered against the files setting.

git diff --name-only | cspell --no-must-find-files --file-list stdin

To only check *.md files:

git diff --name-only | cspell --no-must-find-files --file-list stdin "**/*.md"

This has come up before, so maybe it needs to be changed.

In the original logic, the glob on the command-line was the "include" glob and ignorePath was the "exclude" glob logic. The config files option was added later.

It would be a breaking change, but maybe it would avoid confusion:

  • always filter on files
  • add a new command-line option --include <glob> that will override the files glob filter. Note: --include is used instead of --files to avoid confusion around the meaning of "files".

@fudom
Copy link
Author

fudom commented Feb 12, 2024

Thanks for reply. Not sure if I understood you correctly, but file-list does not work for me. It hangs when using stdin and if I pass a file, it reads the file per line and expects paths for each. (I'm on Windows btw).

I think "always filter on files" (from config file) would fix the problem. And if I understand that correctly, when we want to check another file (outside the files), we have to add the option include? Yes, it sounds like a breaking change. The simple use of cspell ./my-file.txt will then only work if no config file with files is specified? Otherwise you have to use cspell --include ./my-file.txt? Hmm...

The other solution (inverted logic) would be adding a new option like we needed for git only no-must-find-files. Just to tell cspell to don't ingore the files from config file. Maybe confusing as well. I even have no idea how to name this option. --dont-ignore-files? ^^ But this is confusing as well. Does it mean the files array form config? or files in common? I would only add this to the git hook command. I don't think if someone would use it somewhere else. For manual use of the cli simpler is better. I'm sure you have the better ideas. :) Btw. I only want to configure files once in the config file and not again in the git hook. So please no option to do this again (eslint has similar issues). Anyway, I hope I could explain it well.

DL;TR: Always filter on files could fix the problem. But do we want to awlays use include in the cli? Or will this only required if we have a config file with files? idk

@Jason3S
Copy link
Collaborator

Jason3S commented Feb 20, 2024

@fudom,

Thanks for reply. Not sure if I understood you correctly, but file-list does not work for me. It hangs when using stdin and if I pass a file, it reads the file per line and expects paths for each. (I'm on Windows btw).

It should work on Windows. I'll double check. Can you give an example where it does not work? or show how you are using it?

DL;TR: Always filter on files could fix the problem. But do we want to always use include in the cli? Or will this only required if we have a config file with files? idk

--include (or maybe --include-only is clearer) would not be generally needed. It would be used when one wants to override the files config field or when the files to be checked are generated by another program, i.e. as part of the commit script. Something like this: cspell --include-only "*.md" $COMMIT_FILES.

@Jason3S
Copy link
Collaborator

Jason3S commented Feb 21, 2024

@fudom,

I have tried using the --file-list option on windows, it seems to work just fine.

PowerShell

ls -Name *.md | cspell --file-list=stdin

Command Prompt

dir *.md /B | cspell --file-list=stdin

image

@Jason3S
Copy link
Collaborator

Jason3S commented Feb 21, 2024

@fudom,

I you happened to type in just cspell --file-list stdin the it will wait for you to type in the files to check. It is a sort of a REPL.

@Jason3S
Copy link
Collaborator

Jason3S commented Mar 1, 2024

@fudom,

I went with a different approach. I added a new option --file[s].

In your case it would be:

cspell -u --no-progress --relative --no-must-find-files --file ./other.md

Copy link
Contributor

github-actions bot commented Apr 1, 2024

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 Apr 1, 2024
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.

2 participants