diff --git a/package.json b/package.json index d7c8828544b..0605a2e69e2 100644 --- a/package.json +++ b/package.json @@ -127,7 +127,7 @@ "esprima": "^4.0.1", "fast-glob": "^3.2.11", "fs-teardown": "^0.1.3", - "glob": "^7.1.6", + "glob": "^10.0.0", "got": "^11.8.3", "gray-matter": "^4.0.3", "js-yaml": "^4.1.0", diff --git a/tests/tools/check-rule-examples.js b/tests/tools/check-rule-examples.js index df75cc9c135..1ee68168f9e 100644 --- a/tests/tools/check-rule-examples.js +++ b/tests/tools/check-rule-examples.js @@ -51,12 +51,18 @@ describe("check-rule-examples", () => { await assert.rejects( promise, - { - code: 1, - stdout: "", - stderr: + ({ code, stdout, stderr }) => { + assert.strictEqual(code, 1); + assert.strictEqual(stdout, ""); + + // Remove OS-dependent path except base name. + const normalizedStderr = + // eslint-disable-next-line no-control-regex -- escaping control character + stderr.replace(/(?<=\x1B\[4m).*(?=bad-examples\.md)/u, ""); + + const expectedStderr = "\x1B[0m\x1B[0m\n" + - "\x1B[0m\x1B[4mtests/fixtures/bad-examples.md\x1B[24m\x1B[0m\n" + + "\x1B[0m\x1B[4mbad-examples.md\x1B[24m\x1B[0m\n" + "\x1B[0m \x1B[2m11:4\x1B[22m \x1B[31merror\x1B[39m Missing language tag: use one of 'javascript', 'js' or 'jsx'\x1B[0m\n" + "\x1B[0m \x1B[2m12:1\x1B[22m \x1B[31merror\x1B[39m Syntax error: 'import' and 'export' may appear only with 'sourceType: module'\x1B[0m\n" + "\x1B[0m \x1B[2m20:5\x1B[22m \x1B[31merror\x1B[39m Nonstandard language tag 'ts': use one of 'javascript', 'js' or 'jsx'\x1B[0m\n" + @@ -64,7 +70,10 @@ describe("check-rule-examples", () => { "\x1B[0m \x1B[2m31:1\x1B[22m \x1B[31merror\x1B[39m Example code should contain a configuration comment like /* eslint no-restricted-syntax: \"error\" */\x1B[0m\n" + "\x1B[0m\x1B[0m\n" + "\x1B[0m\x1B[31m\x1B[1m✖ 5 problems (5 errors, 0 warnings)\x1B[22m\x1B[39m\x1B[0m\n" + - "\x1B[0m\x1B[31m\x1B[1m\x1B[22m\x1B[39m\x1B[0m\n" + "\x1B[0m\x1B[31m\x1B[1m\x1B[22m\x1B[39m\x1B[0m\n"; + + assert.strictEqual(normalizedStderr, expectedStderr); + return true; } ); }); @@ -74,22 +83,10 @@ describe("check-rule-examples", () => { await assert.rejects( promise, - ({ code, stdout, stderr }) => { - assert.strictEqual(code, 1); - assert.strictEqual(stdout, ""); - const expectedStderr = - "\x1B[0m\x1B[0m\n" + - "\x1B[0m\x1B[4mtests/fixtures/non-existing-examples.md\x1B[24m\x1B[0m\n" + - "\x1B[0m \x1B[2m0:0\x1B[22m \x1B[31merror\x1B[39m Error checking file: ENOENT: no such file or directory, open \x1B[0m\n" + - "\x1B[0m\x1B[0m\n" + - "\x1B[0m\x1B[31m\x1B[1m✖ 1 problem (1 error, 0 warnings)\x1B[22m\x1B[39m\x1B[0m\n" + - "\x1B[0m\x1B[31m\x1B[1m\x1B[22m\x1B[39m\x1B[0m\n"; - - // Replace filename as it's OS-dependent. - const normalizedStderr = stderr.replace(/'.+'/u, ""); - - assert.strictEqual(normalizedStderr, expectedStderr); - return true; + { + code: 1, + stdout: "", + stderr: "No files found that match the specified patterns.\n" } ); }); diff --git a/tools/check-rule-examples.js b/tools/check-rule-examples.js index a05af69a3bc..c1b995c9612 100644 --- a/tools/check-rule-examples.js +++ b/tools/check-rule-examples.js @@ -6,11 +6,10 @@ const { parse } = require("espree"); const { readFile } = require("fs").promises; -const glob = require("glob"); +const { glob } = require("glob"); const matter = require("gray-matter"); const markdownIt = require("markdown-it"); const markdownItContainer = require("markdown-it-container"); -const { promisify } = require("util"); const markdownItRuleExample = require("../docs/tools/markdown-it-rule-example"); const ConfigCommentParser = require("../lib/linter/config-comment-parser"); const rules = require("../lib/rules"); @@ -166,10 +165,15 @@ async function checkFile(filename) { const patterns = process.argv.slice(2); (async function() { - const globAsync = promisify(glob); // determine which files to check - const filenames = (await Promise.all(patterns.map(pattern => globAsync(pattern, { nonull: true })))).flat(); + const filenames = await glob(patterns); + + if (patterns.length && !filenames.length) { + console.error("No files found that match the specified patterns."); + process.exitCode = 1; + return; + } const results = await Promise.all(filenames.map(checkFile)); if (results.every(result => result.errorCount === 0)) {