Skip to content

Commit 4881cf1

Browse files
committed
Merge pull request #20 from csscomb/tg/19-get-config
Stop searching config if we reach root directory
2 parents abe38bc + fefb8a9 commit 4881cf1

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

tasks/csscomb.js

Lines changed: 16 additions & 7 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

22-
configPath = configPath || process.cwd() + '/.csscomb.json';
23+
configPath = configPath || path.join(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 = path.join(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)