Skip to content

Commit

Permalink
Fix bug in reverse
Browse files Browse the repository at this point in the history
yangshun committed May 22, 2018
1 parent a3a57a1 commit 10f3489
Showing 2 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions __tests__/__snapshots__/tree.test.js.snap
Original file line number Diff line number Diff line change
@@ -480,14 +480,14 @@ exports[`tree reverse 5`] = `
│ ├── charlie.txt
│ ├── beta
│ │ └── alpha.txt
── alpha.txt
── alpha.txt
├── beta
│ ├── charlie
│ │ └── alpha.txt
│ ├── beta.txt
│ └── alpha
│ ├── beta
│ │ ── alpha.txt
│ │ ── alpha.txt
│ └── alpha.txt
└── alpha.txt"
`;
15 changes: 6 additions & 9 deletions tree.js
Original file line number Diff line number Diff line change
@@ -58,11 +58,6 @@ function print(
}
}

// Handle showing of all files.
if (!options.allFiles && isHiddenFile(filename)) {
return lines;
}

// Handle max depth.
if (currentDepth > options.maxDepth) {
return lines;
@@ -85,11 +80,15 @@ function print(

// Contents of a directory.
let contents = fs.readdirSync(path);

if (options.reverse) {
contents.reverse();
}

// Handle showing of all files.
if (!options.allFiles) {
contents = contents.filter(content => !isHiddenFile(content));
}

if (options.dirsOnly) {
// We have to filter here instead of at the start of the function
// because we need to know how many non-directories there are before
@@ -118,9 +117,7 @@ function print(
currentDepth + 1,
precedingSymbols +
(currentDepth >= 1
? isLast
? SYMBOLS.INDENT
: SYMBOLS.VERTICAL
? isLast ? SYMBOLS.INDENT : SYMBOLS.VERTICAL
: SYMBOLS.EMPTY),
options,
isCurrentLast,

0 comments on commit 10f3489

Please sign in to comment.