Skip to content

Commit fb7502d

Browse files
committed
Stop searching config if we reach root directory
1 parent abe38bc commit fb7502d

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

tasks/csscomb.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,34 @@ module.exports = function (grunt) {
1414
grunt.registerMultiTask('csscomb', 'Sorting CSS properties in specific order.', function () {
1515

1616
var Comb = require('csscomb'),
17-
comb = new Comb();
17+
comb = new Comb(),
18+
HOME = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
1819

1920
function getConfigPath(configPath) {
20-
var HOME = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
21+
var dirname, parentDirname;
2122

2223
configPath = configPath || process.cwd() + '/.csscomb.json';
2324

2425
// If we've finally found a config, return its path:
2526
if (grunt.file.exists(configPath)) {
2627
return configPath;
2728
}
28-
// If we are in HOME dir already and yet no config file, quit:
29-
if (path.dirname(configPath) === HOME) {
29+
30+
dirname = path.dirname(configPath);
31+
parentDirname = path.dirname(dirname);
32+
33+
// If we are in HOME dir already and yet no config file, quit.
34+
// If project is located not under HOME, compare to root instead.
35+
// Since there appears to be no good way to get root path in
36+
// Windows, assume that if current dir has no parent dir, we're in
37+
// root.
38+
if (dirname === HOME || dirname === parentDirname) {
3039
return;
3140
}
3241

3342
// If there is no config in this directory, go one level up and look for
3443
// a config there:
35-
configPath = path.dirname(path.dirname(configPath)) + '/.csscomb.json';
44+
configPath = parentDirname + '/.csscomb.json';
3645
return getConfigPath(configPath);
3746
}
3847

@@ -74,4 +83,4 @@ module.exports = function (grunt) {
7483
});
7584
});
7685
});
77-
};
86+
};

0 commit comments

Comments
 (0)