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

feat: add --cache option to lint only changed files #1763

Merged
merged 26 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from 16 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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,7 @@ typings/

.tsbuildinfo

# cspell:ignore pids jscoverage wscript jspm dotenv eslintcache
# cspell cache
.cspellcache

# cspell:ignore pids jscoverage wscript jspm dotenv eslintcache cspellcache
42 changes: 37 additions & 5 deletions packages/cspell/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions packages/cspell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,19 @@
},
"homepage": "https://streetsidesoftware.github.io/cspell/",
"dependencies": {
"@types/file-entry-cache": "^5.0.2",
"@types/imurmurhash": "^0.1.1",
"chalk": "^4.1.2",
"commander": "^8.2.0",
"comment-json": "^4.1.1",
"cspell-glob": "^5.10.0",
"cspell-lib": "^5.10.1",
"fast-json-stable-stringify": "^2.1.0",
"file-entry-cache": "^6.0.1",
"fs-extra": "^10.0.0",
"get-stdin": "^8.0.0",
"glob": "^7.2.0",
"imurmurhash": "^0.1.4",
"strip-ansi": "^6.0.1",
"vscode-uri": "^3.0.2"
},
Expand Down
69 changes: 37 additions & 32 deletions packages/cspell/src/__snapshots__/app.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -269,38 +269,43 @@ Array [
"Check spelling",
"",
"Options:",
" -c, --config <cspell.json> Configuration file to use. By default cspell",
" looks for cspell.json in the current directory.",
" -v, --verbose display more information about the files being",
" checked and the configuration",
" --locale <locale> Set language locales. i.e. \\"en,fr\\" for English",
" and French, or \\"en-GB\\" for British English.",
" --language-id <language> Force programming language for unknown",
" extensions. i.e. \\"php\\" or \\"scala\\"",
" --languageId <language> Force programming language for unknown",
" extensions. i.e. \\"php\\" or \\"scala\\"",
" --wordsOnly Only output the words not found in the",
" dictionaries.",
" -u, --unique Only output the first instance of a word not",
" found in the dictionaries.",
" --debug Output information useful for debugging",
" cspell.json files.",
" -e, --exclude <glob> Exclude files matching the glob pattern. This",
" option can be used multiple times to add multiple",
" globs.",
" --no-issues Do not show the spelling errors.",
" --no-progress Turn off progress messages",
" --no-summary Turn off summary message in console",
" -s, --silent Silent mode, suppress error messages",
" -r, --root <root folder> Root directory, defaults to current directory.",
" --relative Issues are displayed relative to root.",
" --show-context Show the surrounding text around an issue.",
" --show-suggestions Show spelling suggestions.",
" --must-find-files Error if no files are found (default: true)",
" --no-must-find-files Do not error if no files are found",
" --legacy Legacy output",
" --local <local> Deprecated -- Use: --locale",
" -h, --help display help for command",
" -c, --config <cspell.json> Configuration file to use. By default cspell",
" looks for cspell.json in the current directory.",
" -v, --verbose display more information about the files being",
" checked and the configuration",
" --locale <locale> Set language locales. i.e. \\"en,fr\\" for English",
" and French, or \\"en-GB\\" for British English.",
" --language-id <language> Force programming language for unknown",
" extensions. i.e. \\"php\\" or \\"scala\\"",
" --languageId <language> Force programming language for unknown",
" extensions. i.e. \\"php\\" or \\"scala\\"",
" --wordsOnly Only output the words not found in the",
" dictionaries.",
" -u, --unique Only output the first instance of a word not",
" found in the dictionaries.",
" --debug Output information useful for debugging",
" cspell.json files.",
" -e, --exclude <glob> Exclude files matching the glob pattern. This",
" option can be used multiple times to add",
" multiple globs.",
" --no-issues Do not show the spelling errors.",
" --no-progress Turn off progress messages",
" --no-summary Turn off summary message in console",
" -s, --silent Silent mode, suppress error messages",
" -r, --root <root folder> Root directory, defaults to current directory.",
" --relative Issues are displayed relative to root.",
" --show-context Show the surrounding text around an issue.",
" --show-suggestions Show spelling suggestions.",
" --must-find-files Error if no files are found (default: true)",
" --no-must-find-files Do not error if no files are found",
" --legacy Legacy output",
" --local <local> Deprecated -- Use: --locale",
" --cache Only check changed files (default: false)",
" --cache-strategy <strategy> Strategy to use for detecting changed files",
" (choices: \\"metadata\\", \\"content\\")",
" --cache-location <path> Path to the cache file or directory (default:",
" \\".cspellcache\\")",
" -h, --help display help for command",
"",
"",
"Examples:",
Expand Down
9 changes: 9 additions & 0 deletions packages/cspell/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { tableToLines } from './util/table';
import { emitTraceResults } from './traceEmitter';
import { getReporter } from './cli-reporter';
import { CheckFailed } from './util/errors';
import { DEFAULT_CACHE_LOCATION } from './util/cache';

export { CheckFailed } from './util/errors';

Expand Down Expand Up @@ -84,6 +85,14 @@ export async function run(program?: commander.Command, argv?: string[]): Promise
// .option('--force', 'Force the exit value to always be 0')
.option('--legacy', 'Legacy output')
.option('--local <local>', 'Deprecated -- Use: --locale')
.option('--cache', 'Only check changed files', false)
.addOption(
new commander.Option('--cache-strategy <strategy>', 'Strategy to use for detecting changed files').choices([
'metadata',
'content',
])
)
.option('--cache-location <path>', `Path to the cache file or directory`, DEFAULT_CACHE_LOCATION)
.addHelpText('after', usage)
.arguments('[files...]')
.action((files: string[], options: Options) => {
Expand Down
14 changes: 11 additions & 3 deletions packages/cspell/src/fileHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fsp from 'fs-extra';
import getStdin from 'get-stdin';
import { GlobOptions, globP } from './util/glob';
import * as path from 'path';
import { CSpellUserSettings, Document, fileToDocument } from 'cspell-lib';
import { CSpellUserSettings, Document, fileToDocument, Issue } from 'cspell-lib';

const UTF8: BufferEncoding = 'utf8';
const STDIN = 'stdin';
Expand Down Expand Up @@ -31,7 +31,15 @@ export async function readConfig(configFile: string | undefined, root: string |

export interface FileInfo {
filename: string;
text: string;
text?: string;
}
export interface FileResult {
fileInfo: FileInfo;
processed: boolean;
issues: Issue[];
mad-gooze marked this conversation as resolved.
Show resolved Hide resolved
errors: number;
configErrors: number;
elapsedTimeMs: number;
}

export function fileInfoToDocument(
Expand All @@ -54,7 +62,7 @@ export function fileInfoToDocument(
return fileToDocument(filename, text, languageId, locale);
}

export function readFileInfo(filename: string, encoding: string = UTF8): Promise<FileInfo> {
export function readFileInfo(filename: string, encoding: string = UTF8): Promise<Required<FileInfo>> {
const pText = filename === STDIN ? getStdin() : fsp.readFile(filename, encoding);
return pText.then(
(text) => ({ text, filename }),
Expand Down
Loading