diff --git a/packages/cspell/src/lint/lint.test.ts b/packages/cspell/src/lint/lint.test.ts index 21bee11c3c16..6551cd9745d9 100644 --- a/packages/cspell/src/lint/lint.test.ts +++ b/packages/cspell/src/lint/lint.test.ts @@ -2,6 +2,7 @@ import * as path from 'path'; import { LintRequest } from './LintRequest'; import { InMemoryReporter } from '../util/InMemoryReporter'; import { runLint } from './lint'; +import { CheckFailed } from '../app'; const root = path.resolve(__dirname, '../..'); const samples = path.resolve(root, 'samples'); @@ -49,6 +50,7 @@ describe('Linter Validation Tests', () => { ${[]} | ${{ root, config: j(root, 'cspell.json'), fileLists: ['missing-file.txt'] }} | ${oc({ errors: 1, files: 0 })} | ${oc({ errorCount: 1, errors: [expect.any(Error)], issues: [] })} ${['**']} | ${{ root, config: j(root, 'cspell.json'), fileLists: [filesToCheckWithMissing] }} | ${oc({ errors: 0, files: 3 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} ${['**']} | ${{ root, config: j(root, 'cspell.json'), fileLists: [filesToCheckWithMissing], mustFindFiles: true }} | ${oc({ errors: 1, files: 3 })} | ${oc({ errorCount: 1, errors: [expect.anything()], issues: [] })} + ${["'**'"]} | ${{ root, config: j(root, 'cspell.json'), mustFindFiles: true }} | ${oc({ errors: 0, files: 0 })} | ${oc({ errorCount: 1, errors: [expect.any(CheckFailed)], issues: [] })} `('runLint $files $options', async ({ files, options, expectedRunResult, expectedReport }) => { const reporter = new InMemoryReporter(); const runResult = await runLint(new LintRequest(files, options, reporter)); diff --git a/packages/cspell/src/lint/lint.ts b/packages/cspell/src/lint/lint.ts index 866c89c04c77..7728cd1e4f91 100644 --- a/packages/cspell/src/lint/lint.ts +++ b/packages/cspell/src/lint/lint.ts @@ -8,6 +8,10 @@ import * as cspell from 'cspell-lib'; import * as path from 'path'; import { format } from 'util'; import { URI } from 'vscode-uri'; +import { filter, isAsyncIterable, pipeAsync, pipeSync } from '../util/async'; +import type { CSpellLintResultCache } from '../util/cache'; +import { calcCacheSettings, createCache, CreateCacheSettings } from '../util/cache'; +import { CheckFailed, toApplicationError, toError } from '../util/errors'; import { ConfigInfo, fileInfoToDocument, @@ -17,16 +21,13 @@ import { readFileInfo, readFileListFiles, } from '../util/fileHelper'; -import type { CSpellLintResultCache } from '../util/cache'; -import { calcCacheSettings, createCache, CreateCacheSettings } from '../util/cache'; -import { toApplicationError, toError } from '../util/errors'; import type { GlobOptions } from '../util/glob'; import { buildGlobMatcher, extractGlobsFromMatcher, extractPatterns, normalizeGlobsToRoot } from '../util/glob'; import { loadReporters, mergeReporters } from '../util/reporters'; import { getTimeMeasurer } from '../util/timer'; import * as util from '../util/util'; -import { pipeAsync, isAsyncIterable, filter, pipeSync } from '../util/async'; import { LintRequest } from './LintRequest'; +import chalk = require('chalk'); export async function runLint(cfg: LintRequest): Promise { let { reporter } = cfg; @@ -232,6 +233,8 @@ export async function runLint(cfg: LintRequest): Promise { } header(fileGlobs, excludeGlobs); + checkGlobs(cfg.fileGlobs, reporter); + reporter.info(`Config Files Found:\n ${configInfo.source}\n`, MessageTypes.Info); const configErrors = await countConfigErrors(configInfo); @@ -285,6 +288,20 @@ interface AppGlobInfo { normalizedExcludes: string[]; } +function checkGlobs(globs: string[], reporter: CSpellReporter) { + globs + .filter((g) => g.startsWith("'") || g.endsWith("'")) + .map((glob) => chalk.yellow(glob)) + .forEach((glob) => + reporter.error( + 'Linter', + new CheckFailed( + `Glob starting or ending with ' (single quote) is not likely to match any files: ${glob}.` + ) + ) + ); +} + async function determineGlobs(configInfo: ConfigInfo, cfg: LintRequest): Promise { const useGitignore = cfg.options.gitignore ?? configInfo.config.useGitignore ?? false; const gitignoreRoots = cfg.options.gitignoreRoot ?? configInfo.config.gitignoreRoot;