From c7638a4b83000ad4363534d14b2eb98eb17654c7 Mon Sep 17 00:00:00 2001 From: David Anson Date: Sat, 24 Feb 2024 04:08:35 +0000 Subject: [PATCH] Update --ignore for directories so it ignores all files within rather than just those with .md or .markdown (case-sensitive) extensions (fixes #459). --- markdownlint.js | 7 +++++-- package-lock.json | 2 +- test/subdir-incorrect/UPPER.MD | 26 ++++++++++++++++++++++++++ test/test.js | 7 +++++++ 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 test/subdir-incorrect/UPPER.MD diff --git a/markdownlint.js b/markdownlint.js index c025abe8..8374ebc8 100755 --- a/markdownlint.js +++ b/markdownlint.js @@ -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 { @@ -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); diff --git a/package-lock.json b/package-lock.json index 57e22b02..1508f295 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,7 @@ "markdownlint": "~0.33.0", "minimatch": "~9.0.3", "run-con": "~1.3.2", - "toml": "^3.0.0" + "toml": "~3.0.0" }, "bin": { "markdownlint": "markdownlint.js" diff --git a/test/subdir-incorrect/UPPER.MD b/test/subdir-incorrect/UPPER.MD new file mode 100644 index 00000000..551b1b3f --- /dev/null +++ b/test/subdir-incorrect/UPPER.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 59a31c51..ff3517fd 100644 --- a/test/test.js +++ b/test/test.js @@ -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});