Skip to content

Commit 56d4a47

Browse files
jugglinmikerwaldron
authored andcommitted
[[CHORE]] Use consistent interface for fs ops
The CLI uses the build-in Node.js `fs` module to test for the presence of a directory in one case. In all other instances, the CLI used the "shelljs" package. Switch to using "shelljs" consistently to better facilitate a forthcoming removal of that package.
1 parent 33cfc87 commit 56d4a47

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/cli.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use strict";
22

33
var _ = require("lodash");
4-
var fs = require("fs");
54
var cli = require("cli");
65
var path = require("path");
76
var shjs = require("shelljs");
@@ -109,7 +108,7 @@ function getHomeDir() {
109108

110109
while (paths.length) {
111110
homePath = paths.shift();
112-
if (fs.existsSync(homePath)) {
111+
if (homePath && shjs.test("-e", homePath)) {
113112
return homePath;
114113
}
115114
}

tests/cli.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,14 @@ exports.group = {
560560
},
561561

562562
testHomeRcFile: function (test) {
563-
var homeRc = path.join(process.env.HOME || process.env.HOMEPATH, ".jshintrc");
563+
var home = process.env.HOME || process.env.HOMEPATH;
564+
var homeRc = path.join(home, ".jshintrc");
564565
var testStub = this.sinon.stub(shjs, "test");
565566
var catStub = this.sinon.stub(shjs, "cat");
566567

568+
// stub home directory
569+
testStub.withArgs("-e", home).returns(true);
570+
567571
// stub rc file
568572
testStub.withArgs("-e", homeRc).returns(true);
569573
catStub.withArgs(homeRc).returns('{"evil": true}');

0 commit comments

Comments
 (0)