Skip to content

Commit

Permalink
chore: update dependency glob to v10 (#17917)
Browse files Browse the repository at this point in the history
* chore: update dependency glob to v10

* update tools/check-rule-examples.js for glob 10

* fix for removed `nonull` flag

* fix test on Windows

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Francesco Trotta <github@fasttime.org>
  • Loading branch information
renovate[bot] and fasttime committed Jan 2, 2024
1 parent c2bf27d commit 750b8df
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
41 changes: 19 additions & 22 deletions tests/tools/check-rule-examples.js
Expand Up @@ -51,20 +51,29 @@ 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" +
"\x1B[0m \x1B[2m23:7\x1B[22m \x1B[31merror\x1B[39m Syntax error: Identifier 'foo' has already been declared\x1B[0m\n" +
"\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;
}
);
});
Expand All @@ -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 <FILE>\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, "<FILE>");

assert.strictEqual(normalizedStderr, expectedStderr);
return true;
{
code: 1,
stdout: "",
stderr: "No files found that match the specified patterns.\n"
}
);
});
Expand Down
12 changes: 8 additions & 4 deletions tools/check-rule-examples.js
Expand Up @@ -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");
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 750b8df

Please sign in to comment.