From 65acccab41590a3e5ef67204177b21f72d8ab677 Mon Sep 17 00:00:00 2001 From: divlo Date: Sun, 21 Feb 2021 16:17:27 +0100 Subject: [PATCH 1/4] fix(glob-options): treat dots as normal characters --- markdownlint.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/markdownlint.js b/markdownlint.js index cf6abf66..6645805f 100755 --- a/markdownlint.js +++ b/markdownlint.js @@ -78,7 +78,8 @@ function readConfiguration(args) { function prepareFileList(files, fileExtensions, previousResults) { const globOptions = { - nodir: true + nodir: true, + dot: true }; let extensionGlobPart = '*.'; if (fileExtensions.length === 1) { From 6e3af7fa20e00feff858cec930c90e8ee566a93b Mon Sep 17 00:00:00 2001 From: divlo Date: Sun, 21 Feb 2021 20:49:50 +0100 Subject: [PATCH 2/4] feat: add dot boolean option --- README.md | 1 + markdownlint.js | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c58b4b17..4cb104bc 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ markdownlint --help -i, --ignore [file|directory|glob] file(s) to ignore/exclude -p, --ignore-path [file] path to file with ignore pattern(s) -r, --rules [file|directory|glob|package] custom rule files + -d, --dot include files/folders with a dot (for example `.github`) ``` ### Globbing diff --git a/markdownlint.js b/markdownlint.js index 6645805f..576b464d 100755 --- a/markdownlint.js +++ b/markdownlint.js @@ -79,7 +79,7 @@ function readConfiguration(args) { function prepareFileList(files, fileExtensions, previousResults) { const globOptions = { nodir: true, - dot: true + dot: options.dot != null ? true : false }; let extensionGlobPart = '*.'; if (fileExtensions.length === 1) { @@ -194,7 +194,8 @@ program .option('-c, --config [configFile]', 'configuration file (JSON, JSONC, JS, or YAML)') .option('-i, --ignore [file|directory|glob]', 'file(s) to ignore/exclude', concatArray, []) .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('-d, --dot', 'include files/folders with a dot (for example `.github`)'); program.parse(process.argv); From 508dadd7e8a41b0fc5e28befcc125faca8e9d1ab Mon Sep 17 00:00:00 2001 From: divlo Date: Mon, 22 Feb 2021 12:03:01 +0100 Subject: [PATCH 3/4] test: add --dot option --- README.md | 8 ++++---- markdownlint.js | 12 ++++++------ test/.folder/incorrect-dot.md | 26 ++++++++++++++++++++++++++ test/test.js | 20 ++++++++++++++++++++ 4 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 test/.folder/incorrect-dot.md diff --git a/README.md b/README.md index 4cb104bc..7f22513f 100644 --- a/README.md +++ b/README.md @@ -29,14 +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 - -d, --dot include files/folders with a dot (for example `.github`) + -s, --stdin read from STDIN (does not work with files) ``` ### Globbing diff --git a/markdownlint.js b/markdownlint.js index 576b464d..9ffb018f 100755 --- a/markdownlint.js +++ b/markdownlint.js @@ -78,8 +78,8 @@ function readConfiguration(args) { function prepareFileList(files, fileExtensions, previousResults) { const globOptions = { - nodir: true, - dot: options.dot != null ? true : false + dot: !!options.dot, + nodir: true }; let extensionGlobPart = '*.'; if (fileExtensions.length === 1) { @@ -188,14 +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('-d, --dot', 'include files/folders with a dot (for example `.github`)'); + .option('-s, --stdin', 'read from STDIN (does not work with files)'); program.parse(process.argv); 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..467852b0 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', '**/correct.md'], + {stripFinalNewline: false}); + t.fail(); + } catch (error) { + t.is(error.stdout, ''); + t.is(error.stderr.match(errorPattern).length, 8); + } +}); + +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', '**/correct.md'], + {stripFinalNewline: false}); + t.is(result.stdout, ''); + t.is(result.stderr, ''); +}); From aa4442ce0069589c56ed4baab2157ec392cb6547 Mon Sep 17 00:00:00 2001 From: divlo Date: Mon, 22 Feb 2021 19:01:00 +0100 Subject: [PATCH 4/4] test: add .file-with-dot.md --- test/.folder/.file-with-dot.md | 8 ++++++++ test/test.js | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 test/.folder/.file-with-dot.md 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/test.js b/test/test.js index 467852b0..66a9a018 100644 --- a/test/test.js +++ b/test/test.js @@ -744,18 +744,18 @@ test('Linter text file --output must end with EOF newline', async t => { 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', '**/correct.md'], + ['--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, 8); + 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', '**/correct.md'], + ['--config', 'test-config.json', '**/incorrect-dot.md', '**/.file-with-dot.md', '**/correct.md'], {stripFinalNewline: false}); t.is(result.stdout, ''); t.is(result.stderr, '');