Skip to content

Commit

Permalink
feat: Add support for .gitignore (#1823)
Browse files Browse the repository at this point in the history
* dev: Move cspell definitions out of nested directory
* dev: enable publishing of cspell-gitignore
* dev: wire-up `.gitignore`
   Refactor each command into its own file.
  • Loading branch information
Jason3S committed Oct 4, 2021
1 parent df6275c commit 9b0dfe4
Show file tree
Hide file tree
Showing 20 changed files with 370 additions and 249 deletions.
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"test-fixtures/**",
"test-packages/test-cspell-tools/src/*.txt"
],
"useGitignore": true,
"ignoreWords": [
"commitcomment"
],
Expand Down
19 changes: 19 additions & 0 deletions cspell.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,20 @@
},
"type": "array"
},
"gitignoreRoot": {
"anyOf": [
{
"$ref": "#/definitions/FsPath"
},
{
"items": {
"$ref": "#/definitions/FsPath"
},
"type": "array"
}
],
"description": "Tells the spell checker to searching for `.gitignore` files when it reaches a matching root."
},
"globRoot": {
"$ref": "#/definitions/FsPath",
"description": "The root to use for glop patterns found in this configuration. Default: location of the configuration file. For compatibility reasons, config files with version 0.1, the glob root will default to be `${cwd}`.\n\nUse `globRoot` to define a different location. `globRoot` can be relative to the location of this configuration file. Defining globRoot, does not impact imported configurations.\n\nSpecial Values:\n- `${cwd}` - will be replaced with the current working directory.\n- `.` - will be the location of the containing configuration file."
Expand Down Expand Up @@ -921,6 +935,11 @@
"description": "The maximum amount of time in milliseconds to generate suggestions for a word.",
"type": "number"
},
"useGitignore": {
"default": false,
"description": "Tells the spell checker to load `.gitignore` files and skip files that match the globs in the `.gitignore` files found.",
"type": "boolean"
},
"usePnP": {
"default": false,
"description": "Packages managers like Yarn 2 use a `.pnp.cjs` file to assist in loading packages stored in the repository.\n\nWhen true, the spell checker will search up the directory structure for the existence of a PnP file and load it.",
Expand Down
1 change: 0 additions & 1 deletion packages/cspell-gitignore/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "cspell-gitignore",
"private": true,
"version": "5.11.1",
"description": "Gitignore Glob matcher for cspell",
"keywords": [
Expand Down
19 changes: 19 additions & 0 deletions packages/cspell-types/cspell.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,20 @@
},
"type": "array"
},
"gitignoreRoot": {
"anyOf": [
{
"$ref": "#/definitions/FsPath"
},
{
"items": {
"$ref": "#/definitions/FsPath"
},
"type": "array"
}
],
"description": "Tells the spell checker to searching for `.gitignore` files when it reaches a matching root."
},
"globRoot": {
"$ref": "#/definitions/FsPath",
"description": "The root to use for glop patterns found in this configuration. Default: location of the configuration file. For compatibility reasons, config files with version 0.1, the glob root will default to be `${cwd}`.\n\nUse `globRoot` to define a different location. `globRoot` can be relative to the location of this configuration file. Defining globRoot, does not impact imported configurations.\n\nSpecial Values:\n- `${cwd}` - will be replaced with the current working directory.\n- `.` - will be the location of the containing configuration file."
Expand Down Expand Up @@ -921,6 +935,11 @@
"description": "The maximum amount of time in milliseconds to generate suggestions for a word.",
"type": "number"
},
"useGitignore": {
"default": false,
"description": "Tells the spell checker to load `.gitignore` files and skip files that match the globs in the `.gitignore` files found.",
"type": "boolean"
},
"usePnP": {
"default": false,
"description": "Packages managers like Yarn 2 use a `.pnp.cjs` file to assist in loading packages stored in the repository.\n\nWhen true, the spell checker will search up the directory structure for the existence of a PnP file and load it.",
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"clean": "rimraf dist coverage .tsbuildinfo",
"build": "npm run compile && npm run build-schema",
"build-dev": "tsc -p tsconfig.dev.json",
"build-schema": "ts-json-schema-generator --no-top-ref --path src/settings/CSpellSettingsDef.ts --type CSpellSettings --validation-keywords markdownDescription --validation-keywords scope --validation-keywords deprecated --validation-keywords deprecationMessage -o ./cspell.schema.json && cp ./cspell.schema.json ../..",
"build-schema": "ts-json-schema-generator --no-top-ref --path src/CSpellSettingsDef.ts --type CSpellSettings --validation-keywords markdownDescription --validation-keywords scope --validation-keywords deprecated --validation-keywords deprecationMessage -o ./cspell.schema.json && cp ./cspell.schema.json ../..",
"build-docs": "typedoc --out ../../docs/types/cspell-types src/index.ts",
"clean-build": "npm run clean && npm run build",
"compile": "tsc -p .",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ export interface FileSettings extends ExtendableSettings {
* Custom reporters configuration
*/
reporters?: ReporterSettings[];

/**
* Tells the spell checker to load `.gitignore` files and skip files that match the globs in the `.gitignore` files found.
* @default false
*/
useGitignore?: boolean;

/**
* Tells the spell checker to searching for `.gitignore` files when it reaches a matching root.
*/
gitignoreRoot?: FsPath | FsPath[];
}

export interface ExtendableSettings extends Settings {
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './settings';
export * from './CSpellSettingsDef';
export * from './CSpellReporter';
export * from './TextOffset';
1 change: 0 additions & 1 deletion packages/cspell-types/src/settings/index.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/cspell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"comment-json": "^4.1.1",
"cspell-glob": "^5.11.1",
"cspell-lib": "^5.11.1",
"cspell-gitignore": "^5.11.1",
"fast-json-stable-stringify": "^2.1.0",
"file-entry-cache": "^6.0.1",
"fs-extra": "^10.0.0",
Expand Down
7 changes: 1 addition & 6 deletions packages/cspell/samples/.cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@
],
"maxNumberOfProblems": 10000,
"ignorePaths": [
"forbidden-words.txt",
"dictionaries/**",
"node_modules/**",
"vscode-extension/**",
".git/**",
".vscode/**"
"forbidden-words.txt"
],
// flagWords - list of words to be always considered incorrect
// This is useful for offensive words and common spelling errors.
Expand Down
9 changes: 9 additions & 0 deletions packages/cspell/samples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Local globs to ignore

ignore/**
!ignore/keepme.md
dictionaries/**
node_modules/**
vscode-extension/**
.git/**
.vscode/**
Empty file.
10 changes: 6 additions & 4 deletions packages/cspell/src/__snapshots__/app.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,6 @@ Array [
" 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",
Expand All @@ -296,15 +294,19 @@ Array [
" --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\\")",
" --gitignore Ignore files matching glob patterns found in",
" .gitignore files.",
" --gitignore-root <path> Prevent searching for .gitignore files past",
" root.",
" --no-color Turn off color.",
" --color Force color",
" -h, --help display help for command",
"",
"",
Expand Down
Loading

0 comments on commit 9b0dfe4

Please sign in to comment.