Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/config-array/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@
"dependencies": {
"@eslint/object-schema": "^2.1.7",
"debug": "^4.3.1",
"minimatch": "^3.1.2"
"minimatch": "^10.1.1"
},
"devDependencies": {
"@jsr/std__path": "^1.0.4",
"@types/minimatch": "^3.0.5",
"rollup-plugin-copy": "^3.5.0"
},
"engines": {
Expand Down
12 changes: 6 additions & 6 deletions packages/config-array/src/config-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import * as posixPath from "@jsr/std__path/posix";
import * as windowsPath from "@jsr/std__path/windows";
import minimatch from "minimatch";
import { minimatch } from "minimatch";
import createDebug from "debug";

import { ObjectSchema } from "@eslint/object-schema";
Expand All @@ -21,8 +21,8 @@ import { filesAndIgnoresSchema } from "./files-and-ignores-schema.js";
//------------------------------------------------------------------------------

/** @typedef {import("./types.ts").ConfigObject} ConfigObject */
/** @typedef {import("minimatch").IMinimatchStatic} IMinimatchStatic */
/** @typedef {import("minimatch").IMinimatch} IMinimatch */
/** @typedef {import("minimatch").Minimatch} Minimatch */
/** @typedef {import("minimatch").MinimatchOptions} MinimatchOptions */
/** @import * as PathImpl from "@jsr/std__path" */

/*
Expand All @@ -43,19 +43,19 @@ const debug = createDebug("@eslint/config-array");

/**
* A cache for minimatch instances.
* @type {Map<string, IMinimatch>}
* @type {Map<string, Minimatch>}
*/
const minimatchCache = new Map();

/**
* A cache for negated minimatch instances.
* @type {Map<string, IMinimatch>}
* @type {Map<string, Minimatch>}
*/
const negatedMinimatchCache = new Map();

/**
* Options to use with minimatch.
* @type {Object}
* @type {MinimatchOptions}
*/
const MINIMATCH_OPTIONS = {
// matchBase: true,
Expand Down
195 changes: 195 additions & 0 deletions packages/config-array/tests/config-array.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,136 @@ describe("ConfigArray", () => {
});
});

describe("POSIX character classes", () => {
it("should match `files` patterns using [[:digit:]]", () => {
configs = new ConfigArray(
[
{
files: ["src/file[[:digit:]].js"],
defs: { severity: "error" },
},
],
{ basePath, schema },
);

configs.normalizeSync();

assert.strictEqual(
configs.getConfig("src/file1.js").defs.severity,
"error",
);
assert.strictEqual(
configs.getConfig("src/file9.js").defs.severity,
"error",
);
assert.strictEqual(
configs.getConfig("src/filea.js"),
undefined,
);
assert.strictEqual(
configs.getConfig("src/file10.js"),
undefined,
);
});

it("should match `files` patterns using [[:alpha:]], [[:lower:]], and [[:upper:]]", () => {
configs = new ConfigArray(
[
{
files: ["alpha_[[:alpha:]].js"],
defs: { kind: "alpha" },
},
{
files: ["lower_[[:lower:]].js"],
defs: { kind: "lower" },
},
{
files: ["upper_[[:upper:]].js"],
defs: { kind: "upper" },
},
],
{ basePath, schema },
);

configs.normalizeSync();

assert.strictEqual(
configs.getConfig("alpha_a.js").defs.kind,
"alpha",
);
assert.strictEqual(
configs.getConfig("alpha_Z.js").defs.kind,
"alpha",
);
assert.strictEqual(
configs.getConfig("lower_a.js").defs.kind,
"lower",
);
assert.strictEqual(
configs.getConfig("lower_Z.js"),
undefined,
);
assert.strictEqual(
configs.getConfig("upper_Z.js").defs.kind,
"upper",
);
assert.strictEqual(
configs.getConfig("upper_a.js"),
undefined,
);
});

it("should honor POSIX classes inside `ignores` patterns", () => {
configs = new ConfigArray(
[
{
files: ["**/*.js"],
ignores: ["src/[[:digit:]]/**"],
defs: { severity: "error" },
},
],
{ basePath, schema },
);

configs.normalizeSync();

assert.strictEqual(
configs.getConfig("src/3/file.js"),
undefined,
);
assert.strictEqual(
configs.getConfig("src/a/file.js").defs.severity,
"error",
);
});

it("should honor POSIX classes in global `ignores` patterns", () => {
configs = new ConfigArray(
[
{
ignores: ["[[:upper:]]"],
},
{
files: ["**/*.js"],
defs: { severity: "error" },
},
],
{ basePath, schema },
);

configs.normalizeSync();

assert.strictEqual(
configs.getConfig("A/file.js"),
undefined,
);
assert.strictEqual(
configs.getConfig("a/file.js").defs.severity,
"error",
);
});
});

describe("config objects with `basePath` property", () => {
it("should apply config object without `files` or `ignores` to the `basePath` directory and its subdirectories only (relative paths)", () => {
configs = new ConfigArray(
Expand Down Expand Up @@ -3010,6 +3140,71 @@ describe("ConfigArray", () => {
});
});

describe("POSIX character classes", () => {
it("should return statuses for [[:digit:]] in `files` patterns", () => {
configs = new ConfigArray(
[{ files: ["src/file[[:digit:]].js"] }],
{ basePath },
);

configs.normalizeSync();

assert.strictEqual(
configs.getConfigStatus("src/file1.js"),
"matched",
);
assert.strictEqual(
configs.getConfigStatus("src/filea.js"),
"unconfigured",
);
assert.strictEqual(
configs.getConfigStatus("src/file10.js"),
"unconfigured",
);
});

it("should return 'unconfigured' for `ignores` using POSIX classes", () => {
configs = new ConfigArray(
[
{
files: ["**/*.js"],
ignores: ["src/[[:digit:]]/**"],
},
],
{ basePath },
);

configs.normalizeSync();

assert.strictEqual(
configs.getConfigStatus("src/3/file.js"),
"unconfigured",
);
assert.strictEqual(
configs.getConfigStatus("src/a/file.js"),
"matched",
);
});

it("should return 'ignored' for global `ignores` using POSIX classes", () => {
configs = new ConfigArray(
[{ ignores: ["[[:upper:]]"] }, { files: ["**/*.js"] }],
{ basePath },
);

configs.normalizeSync();

assert.strictEqual(
configs.getConfigStatus("A/file.js"),
"ignored",
);
assert.strictEqual(
configs.getConfigStatus("a/file.js"),
"matched",
);
});
});

describe("Windows paths", () => {
it('should return "matched" for a file in the base directory with different capitalization', () => {
configs = new ConfigArray([{ files: ["**/*.js"] }], {
Expand Down