-
-
Notifications
You must be signed in to change notification settings - Fork 103
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
Check spelling of filenames #3063
Comments
Help me understand your use case. What are you trying to do by spell checking file names? Please note, this can already be done using ls -1a | cspell stdin |
@Jason3S In some projects at work, I've noticed some filenames are misspelled and I'd like a way to auto detect them in a reliable manner. We're using I'm using When trying to get a list of all files in a directory, including sub-folders, sometimes |
There are a few workarounds: git diff --name-only --cached | cspell stdin or lint-staged.config.cjs export default {
'*': (absolutePaths) => {
return `echo "${absolutePaths.join('\n')}" | cspell stdin`
},
} |
@Jason3S The first suggestion does detect changed files, but the output is not very helpful. To illustrate this, I intentionally created two files with spelling issues (one in my project root and the other in a deeper sub folder), staged them in 1/1 ./stdin 349.37ms X
/:1:5 - Unknown word (spling)
/:2:22 - Unknown word (speling)
CSpell: Files checked: 1, Issues found: 2 in 1 files This output does not tell me what file needs to be fixed. The second suggestion just doesn't work. I was trying that method this morning and |
I found a workaround for the Example: export default {
'*': (absolutePaths) => {
return `sh -c 'echo "${absolutePaths.join('\n')}" | cspell stdin'`
},
} |
To get around the git diff --name-only --cached | npx --no cspell -- --show-context stdin The Working import { relative } from 'node:path';
import { cwd } from 'node:process';
/**
* @type {(filenames: string[]) => string[]>}
*/
const relativeFilenames = (filenames) => {
const root = cwd();
return filenames.map((file) => relative(root, file));
};
/**
* @type {Record<string, (filenames: string[]) => string | string[] | Promise<string | string[]>}
*/
export default {
'*.{js,ts,tsx}': (filenames) => `eslint --fix ${relativeFilenames(filenames).join(' ')}`,
'*.{js,ts,tsx,json,md,css,yml,yaml}': (filenames) => {
const files = relativeFilenames(filenames);
return [
`cspell lint --no-progress --no-summary --no-must-find-files ${files.join(' ')}`,
`sh -c 'echo "${files.join('\n')}" | cspell --show-context stdin'`,
`prettier --write ${files.join(' ')}`,
];
},
}; |
Thank you for the working example. I'm ok with an option to spell check the file name. But a few things need to be worked out: What should be checked
When to check
How to report
|
Here's my 2 cents:
I think it would be nice if the relative path to the file from the I've used https://nodejs.org/api/path.html#pathextnamepath to get the extension, but that doesn't account for common multi-extensions, like I don't think extensions should be checked, unless there is a dictionary of all file extensions.
If the functionality is going to be added to the Some people might not need or care if their file are spelled correctly so having it as a separate command would be OK too. I'd go with whatever is easiest and most efficient.
I've not been able to click on output from cspell so perhaps I should try a different terminal 🤷 |
Is your feature request related to a problem? Please describe.
It would be nice to have an additional cli flag or command that spell checks the filename.
Describe the solution you'd like
Create an additional flag in
lint
(something like--check-filenames
).If it is
true
then whenever the file is being checked, it should also spell check the filename and report any issues.Describe alternatives you've considered
Maybe this should be its own command instead of a
lint
flag?Additional context
NA
The text was updated successfully, but these errors were encountered: