Skip to content

Commit

Permalink
refactor(settings): simplify the deep option
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmlnc committed Jun 9, 2019
1 parent 2b5bc54 commit 9b04800
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
4 changes: 2 additions & 2 deletions src/providers/filters/deep.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/providers/filters/deep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9b04800

Please sign in to comment.