From 9b048004652296157b9b5f29f4d927ea1b94764c Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Sat, 8 Jun 2019 13:50:10 +0300 Subject: [PATCH] refactor(settings): simplify the `deep` option --- README.md | 6 +++--- src/providers/filters/deep.spec.ts | 4 ++-- src/providers/filters/deep.ts | 2 +- src/settings.ts | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 31429d78..4023d50e 100644 --- a/README.md +++ b/README.md @@ -138,10 +138,10 @@ The current working directory in which to search. #### deep - * Type: `number|boolean` - * Default: `true` + * Type: `number` + * Default: `Infinity` -The deep option can be set to `true` to traverse the entire directory structure, or it can be set to a *number* to only traverse that many levels deep. The countdown begins with `1`. +The deep option can be set to `Infinity` to traverse the entire directory structure, or it can be set to a *number* to only traverse that many levels deep. The countdown begins with `1`. For example, you have the following tree: diff --git a/src/providers/filters/deep.spec.ts b/src/providers/filters/deep.spec.ts index ae4408a8..13ed495f 100644 --- a/src/providers/filters/deep.spec.ts +++ b/src/providers/filters/deep.spec.ts @@ -28,8 +28,8 @@ describe('Providers → Filters → Deep', () => { describe('.getFilter', () => { describe('options.deep', () => { - it('should return `false` when option is disabled', () => { - const filter = getFilter('.', ['**/*'], [], { deep: false }); + it('should return `false` when option has 0 as value', () => { + const filter = getFilter('.', ['**/*'], [], { deep: 0 }); const entry = tests.entry.builder().path('root/directory').directory().build(); const actual = filter(entry); diff --git a/src/providers/filters/deep.ts b/src/providers/filters/deep.ts index 57c7cc88..83cf867d 100644 --- a/src/providers/filters/deep.ts +++ b/src/providers/filters/deep.ts @@ -56,7 +56,7 @@ export default class DeepFilter { } private _isSkippedByDeep(entryDepth: number): boolean { - return !this._settings.deep || (typeof this._settings.deep === 'number' && entryDepth >= this._settings.deep); + return entryDepth >= this._settings.deep; } private _isSkippedByMaxPatternDepth(entryDepth: number, maxPatternDepth: number): boolean { diff --git a/src/settings.ts b/src/settings.ts index a2953d0f..e9b5275e 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -24,7 +24,7 @@ export interface Options { * The deep option can be set to true to traverse the entire directory structure, * or it can be set to a number to only traverse that many levels deep. */ - deep?: number | boolean; + deep?: number; /** * Add an array of glob patterns to exclude matches. */ @@ -109,7 +109,7 @@ export default class Settings { public readonly caseSensitiveMatch: boolean = this._getValue(this._options.caseSensitiveMatch, true); public readonly concurrency: number = this._getValue(this._options.concurrency, Infinity); public readonly cwd: string = this._getValue(this._options.cwd, process.cwd()); - public readonly deep: number | boolean = this._getValue(this._options.deep, true); + public readonly deep: number = this._getValue(this._options.deep, Infinity); public readonly dot: boolean = this._getValue(this._options.dot, false); public readonly extglob: boolean = this._getValue(this._options.extglob, true); public readonly followSymbolicLinks: boolean = this._getValue(this._options.followSymbolicLinks, true);