From b04b6a3d7d70471bed3fd0b8cc5ff3c39e452388 Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Thu, 21 Dec 2017 14:13:55 -0800 Subject: [PATCH] fixes globbing issues; add support for *.markdown in dirs - globbing should work in cross-platform manner in `package.json`; e.g. `markdownlint "docs/**.md"` - add tests + fixtures --- README.md | 2 +- markdownlint.js | 11 +++++---- test/subdir-correct/correct.markdown | 26 ++++++++++++++++++++ test/subdir-correct/correct.md | 26 ++++++++++++++++++++ test/subdir-incorrect/incorrect.markdown | 28 ++++++++++++++++++++++ test/subdir-incorrect/incorrect.md | 28 ++++++++++++++++++++++ test/test.js | 30 ++++++++++++++++++++++++ 7 files changed, 146 insertions(+), 5 deletions(-) create mode 100644 test/subdir-correct/correct.markdown create mode 100644 test/subdir-correct/correct.md create mode 100644 test/subdir-incorrect/incorrect.markdown create mode 100644 test/subdir-incorrect/incorrect.md diff --git a/README.md b/README.md index 87df6b9b..3b3db3ce 100644 --- a/README.md +++ b/README.md @@ -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 \ No newline at end of file +[rc-standards]: https://www.npmjs.com/package/rc#standards diff --git a/markdownlint.js b/markdownlint.js index 388ff177..cfb63890 100755 --- a/markdownlint.js +++ b/markdownlint.js @@ -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; }); diff --git a/test/subdir-correct/correct.markdown b/test/subdir-correct/correct.markdown new file mode 100644 index 00000000..f35fe597 --- /dev/null +++ b/test/subdir-correct/correct.markdown @@ -0,0 +1,26 @@ +# header + +## header 2 + +text + +```fence +code +``` + +text + +```fence +$ code + +output +``` + +text + +```fence +code +code +``` + +text \ No newline at end of file diff --git a/test/subdir-correct/correct.md b/test/subdir-correct/correct.md new file mode 100644 index 00000000..f35fe597 --- /dev/null +++ b/test/subdir-correct/correct.md @@ -0,0 +1,26 @@ +# header + +## header 2 + +text + +```fence +code +``` + +text + +```fence +$ code + +output +``` + +text + +```fence +code +code +``` + +text \ No newline at end of file diff --git a/test/subdir-incorrect/incorrect.markdown b/test/subdir-incorrect/incorrect.markdown new file mode 100644 index 00000000..cc602dad --- /dev/null +++ b/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 \ No newline at end of file diff --git a/test/subdir-incorrect/incorrect.md b/test/subdir-incorrect/incorrect.md new file mode 100644 index 00000000..cc602dad --- /dev/null +++ b/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 \ No newline at end of file diff --git a/test/test.js b/test/test.js index 2c779a0d..e515a1fa 100644 --- a/test/test.js +++ b/test/test.js @@ -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); + } +});