From 37ac48ea2c03f1e20474ef82efc39be335566de9 Mon Sep 17 00:00:00 2001 From: Divlo Date: Fri, 26 Feb 2021 08:01:01 +0100 Subject: [PATCH] feat: add dot option to treat dots as normal characters (#167) --- README.md | 7 ++++--- markdownlint.js | 10 ++++++---- test/.folder/.file-with-dot.md | 8 ++++++++ test/.folder/incorrect-dot.md | 26 ++++++++++++++++++++++++++ test/test.js | 20 ++++++++++++++++++++ 5 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 test/.folder/.file-with-dot.md create mode 100644 test/.folder/incorrect-dot.md diff --git a/README.md b/README.md index c58b4b17..7f22513f 100644 --- a/README.md +++ b/README.md @@ -29,13 +29,14 @@ markdownlint --help -h, --help output usage information -V, --version output the version number - -f, --fix fix basic errors (does not work with STDIN) - -s, --stdin read from STDIN (does not work with files) - -o, --output [outputFile] write issues to file (no console) -c, --config [configFile] configuration file (JSON, JSONC, JS, or YAML) + -d, --dot include files/folders with a dot (for example `.github`) + -f, --fix fix basic errors (does not work with STDIN) -i, --ignore [file|directory|glob] file(s) to ignore/exclude + -o, --output [outputFile] write issues to file (no console) -p, --ignore-path [file] path to file with ignore pattern(s) -r, --rules [file|directory|glob|package] custom rule files + -s, --stdin read from STDIN (does not work with files) ``` ### Globbing diff --git a/markdownlint.js b/markdownlint.js index cf6abf66..9ffb018f 100755 --- a/markdownlint.js +++ b/markdownlint.js @@ -78,6 +78,7 @@ function readConfiguration(args) { function prepareFileList(files, fileExtensions, previousResults) { const globOptions = { + dot: !!options.dot, nodir: true }; let extensionGlobPart = '*.'; @@ -187,13 +188,14 @@ program .version(pkg.version) .description(pkg.description) .usage('[options] ') - .option('-f, --fix', 'fix basic errors (does not work with STDIN)') - .option('-s, --stdin', 'read from STDIN (does not work with files)') - .option('-o, --output [outputFile]', 'write issues to file (no console)') .option('-c, --config [configFile]', 'configuration file (JSON, JSONC, JS, or YAML)') + .option('-d, --dot', 'include files/folders with a dot (for example `.github`)') + .option('-f, --fix', 'fix basic errors (does not work with STDIN)') .option('-i, --ignore [file|directory|glob]', 'file(s) to ignore/exclude', concatArray, []) + .option('-o, --output [outputFile]', 'write issues to file (no console)') .option('-p, --ignore-path [file]', 'path to file with ignore pattern(s)') - .option('-r, --rules [file|directory|glob|package]', 'custom rule files', concatArray, []); + .option('-r, --rules [file|directory|glob|package]', 'custom rule files', concatArray, []) + .option('-s, --stdin', 'read from STDIN (does not work with files)'); program.parse(process.argv); diff --git a/test/.folder/.file-with-dot.md b/test/.folder/.file-with-dot.md new file mode 100644 index 00000000..326b4190 --- /dev/null +++ b/test/.folder/.file-with-dot.md @@ -0,0 +1,8 @@ +## header 2 +# header + +```fence +$ code +``` + +text diff --git a/test/.folder/incorrect-dot.md b/test/.folder/incorrect-dot.md new file mode 100644 index 00000000..551b1b3f --- /dev/null +++ b/test/.folder/incorrect-dot.md @@ -0,0 +1,26 @@ +## header 2 +# header + +```fence +$ code +``` + +text + +```fence +$ code +``` + +text + +```fence +$ code +``` + +text + +```fence +$ code +``` + +text diff --git a/test/test.js b/test/test.js index 5def230d..66a9a018 100644 --- a/test/test.js +++ b/test/test.js @@ -740,3 +740,23 @@ test('Linter text file --output must end with EOF newline', async t => { fs.unlinkSync(output); } }); + +test('--dot option to include folders/files with a dot', async (t) => { + try { + await execa('../markdownlint.js', + ['--config', 'test-config.json', '--dot', '**/incorrect-dot.md', '**/.file-with-dot.md', '**/correct.md'], + {stripFinalNewline: false}); + t.fail(); + } catch (error) { + t.is(error.stdout, ''); + t.is(error.stderr.match(errorPattern).length, 13); + } +}); + +test('without --dot option exclude folders/files with a dot', async (t) => { + const result = await execa('../markdownlint.js', + ['--config', 'test-config.json', '**/incorrect-dot.md', '**/.file-with-dot.md', '**/correct.md'], + {stripFinalNewline: false}); + t.is(result.stdout, ''); + t.is(result.stderr, ''); +});