diff --git a/packages/cspell-lib/src/spellCheckFile.ts b/packages/cspell-lib/src/spellCheckFile.ts index 88e88fb09a0..c81c67a7465 100644 --- a/packages/cspell-lib/src/spellCheckFile.ts +++ b/packages/cspell-lib/src/spellCheckFile.ts @@ -115,8 +115,8 @@ async function spellCheckFullDocument( options: SpellCheckFileOptions, settings: CSpellUserSettings ): Promise { - 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(); diff --git a/packages/cspell/fixtures/issue-2998/cspell.json b/packages/cspell/fixtures/issue-2998/cspell.json new file mode 100644 index 00000000000..6234a943539 --- /dev/null +++ b/packages/cspell/fixtures/issue-2998/cspell.json @@ -0,0 +1,14 @@ +{ + "dictionaryDefinitions": [ + { + "name": "fixture", + "path": "./fix-words.txt" + } + ], + "languageSettings": [ + { + "languageId": "fix", + "dictionaries": ["fixture"] + } + ] +} diff --git a/packages/cspell/fixtures/issue-2998/fix-words.txt b/packages/cspell/fixtures/issue-2998/fix-words.txt new file mode 100644 index 00000000000..1f10e38052e --- /dev/null +++ b/packages/cspell/fixtures/issue-2998/fix-words.txt @@ -0,0 +1,7 @@ +nameof +sbyte +stackalloc +struct +typeof +ulong +ushort diff --git a/packages/cspell/fixtures/issue-2998/run.sh b/packages/cspell/fixtures/issue-2998/run.sh new file mode 100755 index 00000000000..a5d19d02910 --- /dev/null +++ b/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 diff --git a/packages/cspell/src/__snapshots__/app.test.ts.snap b/packages/cspell/src/__snapshots__/app.test.ts.snap index 88aa13f2c11..507c3024463 100644 --- a/packages/cspell/src/__snapshots__/app.test.ts.snap +++ b/packages/cspell/src/__snapshots__/app.test.ts.snap @@ -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`] = `""`; diff --git a/packages/cspell/src/app.test.ts b/packages/cspell/src/app.test.ts index 29dc8500cfb..9e62521a253 100644 --- a/packages/cspell/src/app.test.ts +++ b/packages/cspell/src/app.test.ts @@ -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; @@ -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();