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: Show an error if a glob starts/ends with a single quote #2357

Merged
merged 1 commit into from
Jan 29, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/cspell/src/lint/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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));
Expand Down
25 changes: 21 additions & 4 deletions packages/cspell/src/lint/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<RunResult> {
let { reporter } = cfg;
Expand Down Expand Up @@ -232,6 +233,8 @@ export async function runLint(cfg: LintRequest): Promise<RunResult> {
}
header(fileGlobs, excludeGlobs);

checkGlobs(cfg.fileGlobs, reporter);

reporter.info(`Config Files Found:\n ${configInfo.source}\n`, MessageTypes.Info);

const configErrors = await countConfigErrors(configInfo);
Expand Down Expand Up @@ -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<AppGlobInfo> {
const useGitignore = cfg.options.gitignore ?? configInfo.config.useGitignore ?? false;
const gitignoreRoots = cfg.options.gitignoreRoot ?? configInfo.config.gitignoreRoot;
Expand Down