Skip to content

Commit c7638a4

Browse files
committed
Update --ignore for directories so it ignores all files within rather than just those with .md or .markdown (case-sensitive) extensions (fixes #459).
1 parent ca05bed commit c7638a4

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

markdownlint.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ function prepareFileList(files, fileExtensions, previousResults) {
9191
nodir: true
9292
};
9393
let extensionGlobPart = '*.';
94-
if (fileExtensions.length === 1) {
94+
if (!fileExtensions) {
95+
// Match everything
96+
extensionGlobPart = '';
97+
} else if (fileExtensions.length === 1) {
9598
// Glob seems not to match patterns like 'foo.{js}'
9699
extensionGlobPart += fileExtensions[0];
97100
} else {
@@ -267,7 +270,7 @@ if (existsSync(ignorePath)) {
267270
}
268271

269272
const files = prepareFileList(program.args, ['md', 'markdown']).filter(value => ignoreFilter(value));
270-
const ignores = prepareFileList(options.ignore, ['md', 'markdown'], files);
273+
const ignores = prepareFileList(options.ignore, null, files);
271274
const customRules = loadCustomRules(options.rules);
272275
const diff = files.filter(file => !ignores.some(ignore => ignore.absolute === file.absolute)).map(paths => paths.original);
273276

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/subdir-incorrect/UPPER.MD

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## header 2
2+
# header
3+
4+
```fence
5+
$ code
6+
```
7+
8+
text
9+
10+
```fence
11+
$ code
12+
```
13+
14+
text
15+
16+
```fence
17+
$ code
18+
```
19+
20+
text
21+
22+
```fence
23+
$ code
24+
```
25+
26+
text

test/test.js

+7
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,13 @@ test('glob linting with failing files passes when ignored by multiple globs', as
262262
t.is(result.exitCode, 0);
263263
});
264264

265+
test('glob linting with directory ignore applies to all files within', async t => {
266+
const result = await execa('../markdownlint.js', ['subdir-incorrect/**', '--ignore', 'subdir-incorrect'], {stripFinalNewline: false});
267+
t.is(result.stdout, '');
268+
t.is(result.stderr, '');
269+
t.is(result.exitCode, 0);
270+
});
271+
265272
test('linting results are sorted by file/line/names/description', async t => {
266273
try {
267274
await execa('../markdownlint.js', ['--config', 'test-config.json', 'incorrect.md'], {stripFinalNewline: false});

0 commit comments

Comments
 (0)