Skip to content
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
1 change: 1 addition & 0 deletions packages/cspell/fixtures/features/force-check/checked.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Checked: mispeled.
4 changes: 4 additions & 0 deletions packages/cspell/fixtures/features/force-check/cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"files": ["**/*.txt"],
"ignorePaths": ["ignored/**"]
}
2 changes: 2 additions & 0 deletions packages/cspell/fixtures/features/force-check/file-list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
not-in-files.md
checked.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In ignorePaths: mispeled.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Not in files: mispeled.
9 changes: 9 additions & 0 deletions packages/cspell/src/__snapshots__/app.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9475,6 +9475,15 @@ exports[`Validate cli > app --force-check 'lint README.md --file package.json' E
"
`;

exports[`Validate cli > app --force-check 'lint README.md --file-list files.txt --force-check' Expect Error: 'error: mixing globs and --force-check is not supported' 1`] = `[]`;

exports[`Validate cli > app --force-check 'lint README.md --file-list files.txt --force-check' Expect Error: 'error: mixing globs and --force-check is not supported' 2`] = `""`;

exports[`Validate cli > app --force-check 'lint README.md --file-list files.txt --force-check' Expect Error: 'error: mixing globs and --force-check is not supported' 3`] = `
"error: mixing globs and --force-check is not supported
"
`;

exports[`Validate cli > app --force-check 'lint README.md --force-check' Expect Error: 'error: --force-check requires --file, --files, or --file-list to be specified' 1`] = `[]`;

exports[`Validate cli > app --force-check 'lint README.md --force-check' Expect Error: 'error: --force-check requires --file, --files, or --file-list to be specified' 2`] = `""`;
Expand Down
9 changes: 5 additions & 4 deletions packages/cspell/src/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,11 @@ describe('Validate cli', () => {
});

test.each`
args | errorCheck | eError | eLog | eInfo
${'lint --file package.json --force-check'} | ${undefined} | ${true} | ${false} | ${false}
${'lint README.md --file package.json'} | ${'error: mixing globs and --file is not supported'} | ${false} | ${false} | ${false}
${'lint README.md --force-check'} | ${'error: --force-check requires --file, --files, or --file-list to be specified'} | ${false} | ${false} | ${false}
args | errorCheck | eError | eLog | eInfo
${'lint --file package.json --force-check'} | ${undefined} | ${true} | ${false} | ${false}
${'lint README.md --file package.json'} | ${'error: mixing globs and --file is not supported'} | ${false} | ${false} | ${false}
${'lint README.md --force-check'} | ${'error: --force-check requires --file, --files, or --file-list to be specified'} | ${false} | ${false} | ${false}
${'lint README.md --file-list files.txt --force-check'} | ${'error: mixing globs and --force-check is not supported'} | ${false} | ${false} | ${false}
`(
'app --force-check $args Expect Error: $errorCheck',
async ({ args: testArgs, errorCheck, eError, eLog, eInfo }: ArgsTestCase) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/cspell/src/commandLint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ async function action(this: Command, fileGlobs: string[], cliOptions: LinterCliC
if (fileGlobs.length && (file?.length || files?.length)) {
this.error('error: mixing globs and --file is not supported');
}
if (fileGlobs.length && forceCheck) {
this.error('error: mixing globs and --force-check is not supported');
}
const result = await App.lint(fileGlobs, options);
if (!fileGlobs.length && !result.files && !result.errors && !fileList && !files?.length && !file?.length) {
this.outputHelp();
Expand Down
8 changes: 8 additions & 0 deletions packages/cspell/src/lint/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const filesToCheck = path.resolve(features, 'file-list/files-to-check.txt');
const pUnknownWords = path.resolve(features, 'unknown-words');
const filesToCheckWithMissing = path.resolve(root, 'fixtures/features/file-list/files-to-check-missing.txt');
const configSamples = path.resolve(samples, 'config');
const forceCheck = path.resolve(features, 'force-check');

// cspell:ignore mispeled

const oc = (...params: Parameters<typeof expect.objectContaining>) => expect.objectContaining(...params);
const j = path.join;
Expand Down Expand Up @@ -112,6 +115,11 @@ describe('Linter Validation Tests', () => {
${[]} | ${{ files: ['../../README.md'], dot: true, ...optionsRootCSpellJson }} | ${oc({ errors: 0, files: 1, skippedFiles: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [] })}
${[]} | ${{ files: ['../../resources/patreon.png' /* skip binary */], dot: true, ...optionsRootCSpellJson }} | ${oc({ errors: 0, files: 1, skippedFiles: 1 })} | ${oc({ errorCount: 0, errors: [], issues: [] })}
${['**/*.md']} | ${{ root: './fixtures/issue-6025', config: './fixtures/issue-6025/nested/cspell.config.yaml' }} | ${oc({ errors: 0, files: 2, skippedFiles: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [] })}
${[]} | ${{ root: forceCheck, files: ['not-in-files.md'] }} | ${oc({ errors: 0, files: 1, skippedFiles: 1 })} | ${oc({ errorCount: 0, errors: [], issues: [] })}
${[]} | ${{ root: forceCheck, files: ['not-in-files.md'], forceCheck: true }} | ${oc({ errors: 0, files: 1, skippedFiles: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [oc({ text: 'mispeled' })] })}
${[]} | ${{ root: forceCheck, files: ['ignored/ignored.txt'] }} | ${oc({ errors: 0, files: 1, skippedFiles: 1 })} | ${oc({ errorCount: 0, errors: [], issues: [] })}
${[]} | ${{ root: forceCheck, files: ['ignored/ignored.txt'], forceCheck: true }} | ${oc({ errors: 0, files: 1, skippedFiles: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [oc({ text: 'mispeled' })] })}
${['**/*.txt']} | ${{ root: forceCheck, fileLists: [j(forceCheck, 'file-list.txt')], forceCheck: true }} | ${oc({ errors: 0, files: 2, skippedFiles: 1 })} | ${oc({ errorCount: 0, errors: [], issues: [oc({ text: 'mispeled' })] })}
`('runLint $files $options', async ({ files, options, expectedRunResult, expectedReport }) => {
const reporter = new InMemoryReporter();
const runResult = await runLint(new LintRequest(files, options, reporter));
Expand Down
6 changes: 5 additions & 1 deletion packages/cspell/src/lint/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,11 @@ async function determineFilesToCheck(
globOptions.dot = enableGlobDot;
}

const includeFilter = createIncludeFileFilterFn(allGlobs, root, enableGlobDot);
// `--force-check` wins over the `files` setting, but not over globs on the command line.
const includeFilter =
cfg.options.forceCheck && !cfg.fileGlobs.length
? () => true
: createIncludeFileFilterFn(allGlobs, root, enableGlobDot);
const includeFilterCountSkipped = countFiles(includeFilter);
const rawCliFiles = cfg.files?.map((file) => resolveFilename(file, root)).filter(includeFilterCountSkipped);
const cliFiles = cfg.options.mustFindFiles
Expand Down
9 changes: 2 additions & 7 deletions packages/cspell/src/lint/processFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,14 @@ export async function processFile(

let spellResult: Partial<SpellCheckFileResult> = {};
try {
const {
showSuggestions: generateSuggestions,
validateDirectives,
skipValidation,
forceCheck: force,
} = cfg.options;
const { showSuggestions: generateSuggestions, validateDirectives, skipValidation, forceCheck } = cfg.options;
const numSuggestions = configInfo.config.numSuggestions ?? 5;
const validateOptions = util.clean({
generateSuggestions,
numSuggestions,
validateDirectives,
skipValidation,
force,
forceCheck,
});
const r = await spellCheckDocument(doc, validateOptions, userSettings);
// console.warn('filename: %o %o', path.relative(process.cwd(), filename), r.perf);
Expand Down
4 changes: 3 additions & 1 deletion packages/cspell/src/lint/processFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const BATCH_PROCESS_SIZE = 1;
interface PrefetchConfig {
readonly root: LintRequest['root'];
readonly maxFileSize: LintRequest['maxFileSize'];
readonly forceCheck: boolean | undefined;
readonly config: CSpellSettings;
readonly cache: CSpellLintResultCache;
}
Expand All @@ -56,7 +57,7 @@ function prefetch(fileToProcess: FileToProcess, cfg: PrefetchConfig): PrefetchFi
}
const uri = filenameToUri(filename, cfg.root).href;
const checkResult = await shouldCheckDocument({ uri }, {}, cfg.config);
if (!checkResult.shouldCheck) {
if (!checkResult.shouldCheck && !cfg.forceCheck) {
return { skip: true, skipReason: checkResult.reason || 'Ignored by configuration.' } as const;
}
const maxFileSize = processMaxFileSize(cfg.maxFileSize ?? checkResult.settings.maxFileSize);
Expand Down Expand Up @@ -100,6 +101,7 @@ export async function processFiles(
const prefetchConfig: PrefetchConfig = {
root: options.cfg.root,
maxFileSize: options.cfg.maxFileSize,
forceCheck: options.cfg.options.forceCheck,
config: options.configInfo.config,
cache,
};
Expand Down
Loading