Skip to content

Commit

Permalink
Merge pull request #30 from mochajs/globs
Browse files Browse the repository at this point in the history
fixes globbing issues; add support for *.markdown in dirs; closes #20
  • Loading branch information
DavidAnson committed Dec 31, 2017
2 parents 6a5dfa3 + b04b6a3 commit e11fd24
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -65,4 +65,4 @@ MIT © Igor Shubovych
[config]: https://github.com/DavidAnson/markdownlint#optionsconfig
[style-folder]: https://github.com/DavidAnson/markdownlint/tree/master/style
[test-config]: https://github.com/igorshubovych/markdownlint-cli/blob/master/test/test-config.json
[rc-standards]: https://www.npmjs.com/package/rc#standards
[rc-standards]: https://www.npmjs.com/package/rc#standards
11 changes: 7 additions & 4 deletions markdownlint.js
Expand Up @@ -41,10 +41,13 @@ function readConfiguration(args) {

function prepareFileList(files) {
files = files.map(function (file) {
var isDir = fs.lstatSync(file).isDirectory();
if (isDir) {
var markdownFiles = path.join(file, '**', '*.md');
return glob.sync(markdownFiles);
try {
if (fs.lstatSync(file).isDirectory()) {
return glob.sync(path.join(file, '**', '*.{md,markdown}'));
}
} catch (err) {
// Not a directory, not a file, may be a glob
return glob.sync(file);
}
return file;
});
Expand Down
26 changes: 26 additions & 0 deletions test/subdir-correct/correct.markdown
@@ -0,0 +1,26 @@
# header

## header 2

text

```fence
code
```

text

```fence
$ code
output
```

text

```fence
code
code
```

text
26 changes: 26 additions & 0 deletions test/subdir-correct/correct.md
@@ -0,0 +1,26 @@
# header

## header 2

text

```fence
code
```

text

```fence
$ code
output
```

text

```fence
code
code
```

text
28 changes: 28 additions & 0 deletions test/subdir-incorrect/incorrect.markdown
@@ -0,0 +1,28 @@
## header 2
# header

```fence
$ code
```

text

```fence
$ code
```

text

```fence
$ code
$ code
```

text

```fence
$ code
$ code
```

text
28 changes: 28 additions & 0 deletions test/subdir-incorrect/incorrect.md
@@ -0,0 +1,28 @@
## header 2
# header

```fence
$ code
```

text

```fence
$ code
```

text

```fence
$ code
$ code
```

text

```fence
$ code
$ code
```

text
30 changes: 30 additions & 0 deletions test/test.js
Expand Up @@ -51,3 +51,33 @@ test('linting of incorrect Markdown via npm run file fails with eol', async t =>
t.true(/\nnpm ERR! code ELIFECYCLE/.test(err.stderr));
}
});

test('glob linting works with passing files', async t => {
const result = await execa('../markdownlint.js',
['--config', 'test-config.json', '**/correct.md']);
t.true(result.stdout.length === 0);
});

test('glob linting works with failing files', async t => {
try {
await execa('../markdownlint.js',
['--config', 'test-config.json', '**/.md']);
} catch (err) {
t.true(err.stderr.length > 0);
}
});

test('dir linting works with passing .markdown files', async t => {
const result = await execa('../markdownlint.js',
['--config', 'test-config.json', 'subdir-correct']);
t.true(result.stdout.length === 0);
});

test('dir linting works with failing .markdown files', async t => {
try {
await execa('../markdownlint.js',
['--config', 'test-config.json', 'subdir-incorrect']);
} catch (err) {
t.true(err.stderr.length > 0);
}
});

0 comments on commit e11fd24

Please sign in to comment.