Skip to content

Commit d643ff2

Browse files
committed
Merge pull request #42 from codeclimate/devon/prune-files-within-symlinks
Prune files within symlinked paths
2 parents 00cb188 + ce3d07b commit d643ff2

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

bin/eslint.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,23 @@ function isFileIgnoredByLibrary(file) {
7878
return ignored;
7979
}
8080

81+
function prunePathsWithinSymlinks(paths) {
82+
// Extracts symlinked paths and filters them out, including any child paths
83+
var symlinks = paths.filter(function(path) {
84+
return fs.lstatSync(path).isSymbolicLink();
85+
});
86+
87+
return paths.filter(function(path) {
88+
var withinSymlink = false;
89+
symlinks.forEach(function(symlink) {
90+
if (path.indexOf(symlink) == 0) {
91+
withinSymlink = true;
92+
}
93+
});
94+
return !withinSymlink;
95+
});
96+
}
97+
8198
function exclusionBasedFileListBuilder(excludePaths) {
8299
// Uses glob to traverse code directory and find files to analyze,
83100
// excluding files passed in with by CLI config, and including only
@@ -88,7 +105,7 @@ function exclusionBasedFileListBuilder(excludePaths) {
88105
var analysisFiles = [];
89106
var allFiles = glob.sync("/code/**/**", {});
90107

91-
allFiles.forEach(function(file, i, a){
108+
prunePathsWithinSymlinks(allFiles).forEach(function(file, i, a){
92109
if(excludePaths.indexOf(file.split("/code/")[1]) < 0) {
93110
if(fs.lstatSync(file).isFile()) {
94111
if (!isFileIgnoredByLibrary(file) && isFileWithMatchingExtension(file, extensions)) {
@@ -114,7 +131,7 @@ function inclusionBasedFileListBuilder(includePaths) {
114131
var filesInThisDirectory = glob.sync(
115132
"/code/" + fileOrDirectory + "/**/**"
116133
);
117-
filesInThisDirectory.forEach(function(file, j){
134+
prunePathsWithinSymlinks(filesInThisDirectory).forEach(function(file, j){
118135
if (!isFileIgnoredByLibrary(file) && isFileWithMatchingExtension(file, extensions)) {
119136
analysisFiles.push(file);
120137
}

0 commit comments

Comments
 (0)