Skip to content

Commit

Permalink
[[CHORE]] Use consistent interface for fs ops
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jugglinmike authored and rwaldron committed Jan 24, 2022
1 parent 33cfc87 commit 56d4a47
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use strict";

var _ = require("lodash");
var fs = require("fs");
var cli = require("cli");
var path = require("path");
var shjs = require("shelljs");
Expand Down Expand Up @@ -109,7 +108,7 @@ function getHomeDir() {

while (paths.length) {
homePath = paths.shift();
if (fs.existsSync(homePath)) {
if (homePath && shjs.test("-e", homePath)) {
return homePath;
}
}
Expand Down
6 changes: 5 additions & 1 deletion tests/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,14 @@ exports.group = {
},

testHomeRcFile: function (test) {
var homeRc = path.join(process.env.HOME || process.env.HOMEPATH, ".jshintrc");
var home = process.env.HOME || process.env.HOMEPATH;
var homeRc = path.join(home, ".jshintrc");
var testStub = this.sinon.stub(shjs, "test");
var catStub = this.sinon.stub(shjs, "cat");

// stub home directory
testStub.withArgs("-e", home).returns(true);

// stub rc file
testStub.withArgs("-e", homeRc).returns(true);
catStub.withArgs(homeRc).returns('{"evil": true}');
Expand Down

0 comments on commit 56d4a47

Please sign in to comment.