Skip to content

Commit

Permalink
Directories can not be linted; remove from glob results.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAnson committed Jan 30, 2018
1 parent 6722a92 commit 472a82c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions markdownlint.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ function readConfiguration(args) {
}

function prepareFileList(files) {
var globOptions = {
nodir: true
};
files = files.map(function (file) {
try {
if (fs.lstatSync(file).isDirectory()) {
return glob.sync(path.join(file, '**', '*.{md,markdown}'));
return glob.sync(path.join(file, '**', '*.{md,markdown}'), globOptions);
}
} catch (err) {
// Not a directory, not a file, may be a glob
return glob.sync(file);
return glob.sync(file, globOptions);
}
return file;
});
Expand Down
11 changes: 11 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,14 @@ test('linting results are sorted by file/line/names/description', async t => {
t.true(err.stderr === expected);
}
});

test('glob linting does not try to lint directories as files', async t => {
try {
await execa('../markdownlint.js',
['--config', 'test-config.json', '**/*']);
t.fail();
} catch (err) {
t.true(err.stdout === '');
t.true(err.stderr.match(errorPattern).length > 0);
}
});

0 comments on commit 472a82c

Please sign in to comment.