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

fix: missing language-id #2999

Merged
merged 2 commits into from Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/cspell-lib/src/spellCheckFile.ts
Expand Up @@ -115,8 +115,8 @@ async function spellCheckFullDocument(
options: SpellCheckFileOptions,
settings: CSpellUserSettings
): Promise<SpellCheckFileResult> {
const { uri, text: content } = document;
const doc = createTextDocument({ uri, content });
const { uri, text: content, languageId, locale } = document;
const doc = createTextDocument({ uri, content, languageId, locale });
const docValOptions: DocumentValidatorOptions = options;
const docValidator = new DocumentValidator(doc, docValOptions, settings);
await docValidator.prepare();
Expand Down
14 changes: 14 additions & 0 deletions packages/cspell/fixtures/issue-2998/cspell.json
@@ -0,0 +1,14 @@
{
"dictionaryDefinitions": [
{
"name": "fixture",
"path": "./fix-words.txt"
}
],
"languageSettings": [
{
"languageId": "fix",
"dictionaries": ["fixture"]
}
]
}
7 changes: 7 additions & 0 deletions packages/cspell/fixtures/issue-2998/fix-words.txt
@@ -0,0 +1,7 @@
nameof
sbyte
stackalloc
struct
typeof
ulong
ushort
3 changes: 3 additions & 0 deletions packages/cspell/fixtures/issue-2998/run.sh
@@ -0,0 +1,3 @@
../../bin.js -v --language-id=fix fix-words.txt

cat fix-words.txt | ../../bin.js -v --language-id=fix "--locale=*" stdin
33 changes: 33 additions & 0 deletions packages/cspell/src/__snapshots__/app.test.ts.snap
Expand Up @@ -370,6 +370,39 @@ exports[`Validate cli app current_file languageId Expect Error: undefined 3`] =
1/1 ./src/app.test.ts"
`;

exports[`Validate cli app issue-2998 --language-id Expect Error: undefined 1`] = `Array []`;

exports[`Validate cli app issue-2998 --language-id Expect Error: undefined 2`] = `
"info
info cspell;
info Date: Sat, 03 Apr 2021 11:25:33 GMT
info Options:
info verbose: Yes
info config: default
info exclude: node_modules/**
info files: fix-words.txt
info wordsOnly: No
info unique: No
info
info Config Files Found:
info ./fixtures/issue-2998/cspell.json
info
info Exclusion Globs:
info Glob: node_modules/** from command line
info
info Checking: ./fixtures/issue-2998/fix-words.txt, File type: fix, Language: default
info Checked: ./fixtures/issue-2998/fix-words.txt, File type: fix, Language: en ... Issues: 0 0.00S
info Config file Used: ./fixtures/issue-2998/cspell.json
info Dictionaries Used: backwards-compatibility, companies, filetypes, public-licenses, softwareTerms, aws, cryptocurrencies, en_us, fixture
error 0.00ms
error CSpell: Files checked: 1, Issues found: 0 in 0 files"
`;

exports[`Validate cli app issue-2998 --language-id Expect Error: undefined 3`] = `
"
1/1 ./fixtures/issue-2998/fix-words.txt"
`;

exports[`Validate cli app link 1`] = `""`;

exports[`Validate cli app link add 1`] = `""`;
Expand Down
61 changes: 33 additions & 28 deletions packages/cspell/src/app.test.ts
Expand Up @@ -31,6 +31,10 @@ function pathSamples(...parts: string[]): string {
return pathRoot('samples', ...parts);
}

function pathFix(...parts: string[]): string {
return pathRoot('fixtures', ...parts);
}

// [message, args, resolve, error, log, info]
type ErrorCheck = undefined | jest.Constructable | string | RegExp;

Expand Down Expand Up @@ -130,34 +134,35 @@ describe('Validate cli', () => {
const failFastRoot = pathSamples('fail-fast');

test.each`
msg | testArgs | errorCheck | eError | eLog | eInfo
${'with errors and excludes'} | ${['-r', 'samples', '*', '-e', 'Dutch.txt', '-c', 'samples/.cspell.json']} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'no-args'} | ${[]} | ${'outputHelp'} | ${false} | ${false} | ${false}
${'--help'} | ${['--help']} | ${'outputHelp'} | ${false} | ${false} | ${false}
${'current_file'} | ${[__filename]} | ${undefined} | ${true} | ${false} | ${false}
${'with spelling errors Dutch.txt'} | ${[pathSamples('Dutch.txt')]} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'with spelling errors Dutch.txt words only'} | ${[pathSamples('Dutch.txt'), '--wordsOnly']} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'with spelling errors Dutch.txt --legacy'} | ${[pathSamples('Dutch.txt'), '--legacy']} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'with spelling errors --silent Dutch.txt'} | ${['--silent', pathSamples('Dutch.txt')]} | ${app.CheckFailed} | ${false} | ${false} | ${false}
${'current_file languageId'} | ${[__filename, '--languageId=typescript']} | ${undefined} | ${true} | ${false} | ${false}
${'check help'} | ${['check', '--help']} | ${'outputHelp'} | ${false} | ${false} | ${false}
${'check LICENSE'} | ${['check', pathRoot('LICENSE')]} | ${undefined} | ${false} | ${true} | ${false}
${'check missing'} | ${['check', pathRoot('missing-file.txt')]} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'check with spelling errors'} | ${['check', pathSamples('Dutch.txt')]} | ${app.CheckFailed} | ${false} | ${true} | ${false}
${'LICENSE'} | ${[pathRoot('LICENSE')]} | ${undefined} | ${true} | ${false} | ${false}
${'samples/Dutch.txt'} | ${[pathSamples('Dutch.txt')]} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'with forbidden words'} | ${[pathSamples('src/sample-with-forbidden-words.md')]} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'current_file --verbose'} | ${['--verbose', __filename]} | ${undefined} | ${true} | ${false} | ${true}
${'bad config'} | ${['-c', __filename, __filename]} | ${app.CheckFailed} | ${true} | ${false} | ${false}
${'not found error by default'} | ${['*.not']} | ${app.CheckFailed} | ${true} | ${false} | ${false}
${'must find with error'} | ${['*.not', '--must-find-files']} | ${app.CheckFailed} | ${true} | ${false} | ${false}
${'must find force no error'} | ${['*.not', '--no-must-find-files']} | ${undefined} | ${true} | ${false} | ${false}
${'cspell-bad.json'} | ${['-c', pathSamples('cspell-bad.json'), __filename]} | ${undefined} | ${true} | ${false} | ${false}
${'cspell-import-missing.json'} | ${['-c', pathSamples('linked/cspell-import-missing.json'), __filename]} | ${app.CheckFailed} | ${true} | ${false} | ${false}
${'--fail-fast no option'} | ${['-r', failFastRoot, '*.txt']} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'--fail-fast with option'} | ${['-r', failFastRoot, '--fail-fast', '*.txt']} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'--fail-fast with config'} | ${['-r', failFastRoot, '-c', failFastConfig, '*.txt']} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'--no-fail-fast with config'} | ${['-r', failFastRoot, '--no-fail-fast', '-c', failFastConfig, '*.txt']} | ${app.CheckFailed} | ${true} | ${true} | ${false}
msg | testArgs | errorCheck | eError | eLog | eInfo
${'with errors and excludes'} | ${['-r', 'samples', '*', '-e', 'Dutch.txt', '-c', 'samples/.cspell.json']} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'no-args'} | ${[]} | ${'outputHelp'} | ${false} | ${false} | ${false}
${'--help'} | ${['--help']} | ${'outputHelp'} | ${false} | ${false} | ${false}
${'current_file'} | ${[__filename]} | ${undefined} | ${true} | ${false} | ${false}
${'with spelling errors Dutch.txt'} | ${[pathSamples('Dutch.txt')]} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'with spelling errors Dutch.txt words only'} | ${[pathSamples('Dutch.txt'), '--wordsOnly']} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'with spelling errors Dutch.txt --legacy'} | ${[pathSamples('Dutch.txt'), '--legacy']} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'with spelling errors --silent Dutch.txt'} | ${['--silent', pathSamples('Dutch.txt')]} | ${app.CheckFailed} | ${false} | ${false} | ${false}
${'current_file languageId'} | ${[__filename, '--languageId=typescript']} | ${undefined} | ${true} | ${false} | ${false}
${'check help'} | ${['check', '--help']} | ${'outputHelp'} | ${false} | ${false} | ${false}
${'check LICENSE'} | ${['check', pathRoot('LICENSE')]} | ${undefined} | ${false} | ${true} | ${false}
${'check missing'} | ${['check', pathRoot('missing-file.txt')]} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'check with spelling errors'} | ${['check', pathSamples('Dutch.txt')]} | ${app.CheckFailed} | ${false} | ${true} | ${false}
${'LICENSE'} | ${[pathRoot('LICENSE')]} | ${undefined} | ${true} | ${false} | ${false}
${'samples/Dutch.txt'} | ${[pathSamples('Dutch.txt')]} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'with forbidden words'} | ${[pathSamples('src/sample-with-forbidden-words.md')]} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'current_file --verbose'} | ${['--verbose', __filename]} | ${undefined} | ${true} | ${false} | ${true}
${'bad config'} | ${['-c', __filename, __filename]} | ${app.CheckFailed} | ${true} | ${false} | ${false}
${'not found error by default'} | ${['*.not']} | ${app.CheckFailed} | ${true} | ${false} | ${false}
${'must find with error'} | ${['*.not', '--must-find-files']} | ${app.CheckFailed} | ${true} | ${false} | ${false}
${'must find force no error'} | ${['*.not', '--no-must-find-files']} | ${undefined} | ${true} | ${false} | ${false}
${'cspell-bad.json'} | ${['-c', pathSamples('cspell-bad.json'), __filename]} | ${undefined} | ${true} | ${false} | ${false}
${'cspell-import-missing.json'} | ${['-c', pathSamples('linked/cspell-import-missing.json'), __filename]} | ${app.CheckFailed} | ${true} | ${false} | ${false}
${'--fail-fast no option'} | ${['-r', failFastRoot, '*.txt']} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'--fail-fast with option'} | ${['-r', failFastRoot, '--fail-fast', '*.txt']} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'--fail-fast with config'} | ${['-r', failFastRoot, '-c', failFastConfig, '*.txt']} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'--no-fail-fast with config'} | ${['-r', failFastRoot, '--no-fail-fast', '-c', failFastConfig, '*.txt']} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'issue-2998 --language-id'} | ${['-r', pathFix('issue-2998'), '-v', '--language-id=fix', pathFix('issue-2998/fix-words.txt')]} | ${undefined} | ${true} | ${false} | ${true}
`('app $msg Expect Error: $errorCheck', async ({ testArgs, errorCheck, eError, eLog, eInfo }: TestCase) => {
chalk.level = 1;
const commander = getCommander();
Expand Down