Skip to content

Commit

Permalink
Update --ignore for directories so it ignores all files within rather…
Browse files Browse the repository at this point in the history
… than just those with .md or .markdown (case-sensitive) extensions (fixes #459).
  • Loading branch information
DavidAnson committed Feb 24, 2024
1 parent ca05bed commit c7638a4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
7 changes: 5 additions & 2 deletions markdownlint.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ function prepareFileList(files, fileExtensions, previousResults) {
nodir: true
};
let extensionGlobPart = '*.';
if (fileExtensions.length === 1) {
if (!fileExtensions) {
// Match everything
extensionGlobPart = '';
} else if (fileExtensions.length === 1) {
// Glob seems not to match patterns like 'foo.{js}'
extensionGlobPart += fileExtensions[0];
} else {
Expand Down Expand Up @@ -267,7 +270,7 @@ if (existsSync(ignorePath)) {
}

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

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions test/subdir-incorrect/UPPER.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## header 2
# header

```fence
$ code
```

text

```fence
$ code
```

text

```fence
$ code
```

text

```fence
$ code
```

text
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ test('glob linting with failing files passes when ignored by multiple globs', as
t.is(result.exitCode, 0);
});

test('glob linting with directory ignore applies to all files within', async t => {
const result = await execa('../markdownlint.js', ['subdir-incorrect/**', '--ignore', 'subdir-incorrect'], {stripFinalNewline: false});
t.is(result.stdout, '');
t.is(result.stderr, '');
t.is(result.exitCode, 0);
});

test('linting results are sorted by file/line/names/description', async t => {
try {
await execa('../markdownlint.js', ['--config', 'test-config.json', 'incorrect.md'], {stripFinalNewline: false});
Expand Down

0 comments on commit c7638a4

Please sign in to comment.