Skip to content

Commit

Permalink
feat!: Remove ConfigArray#isExplicitMatch()
Browse files Browse the repository at this point in the history
Fixes #51
  • Loading branch information
mdjermanovic committed Jun 7, 2024
1 parent 2edc0f0 commit b546686
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 118 deletions.
48 changes: 0 additions & 48 deletions packages/config-array/src/config-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,54 +783,6 @@ export class ConfigArray extends Array {

/* eslint-enable class-methods-use-this -- Desired as instance methods */

/**
* Determines if a given file path explicitly matches a `files` entry
* and also doesn't match an `ignores` entry. Configs that don't have
* a `files` property are not considered an explicit match.
* @param {string} filePath The complete path of a file to check.
* @returns {boolean} True if the file path matches a `files` entry
* or false if not.
*/
isExplicitMatch(filePath) {
assertNormalized(this);

const cache = dataCache.get(this);

// first check the cache to avoid duplicate work
const result = cache.explicitMatches.get(filePath);

if (typeof result === "boolean") {
return result;
}

// TODO: Maybe move elsewhere? Maybe combine with getConfig() logic?
const relativeFilePath = path.relative(this.basePath, filePath);

if (shouldIgnorePath(this.ignores, filePath, relativeFilePath)) {
debug(`Ignoring ${filePath}`);

// cache and return result
cache.explicitMatches.set(filePath, false);
return false;
}

// filePath isn't automatically ignored, so try to find a match

for (const config of this) {
if (!config.files) {
continue;
}

if (pathMatches(filePath, this.basePath, config)) {
debug(`Matching config found for ${filePath}`);
cache.explicitMatches.set(filePath, true);
return true;
}
}

return false;
}

/**
* Returns the config object for a given file path and a status that can be used to determine why a file has no config.
* @param {string} filePath The complete path of a file to get a config for.
Expand Down
70 changes: 0 additions & 70 deletions packages/config-array/tests/config-array.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3107,76 +3107,6 @@ describe("ConfigArray", () => {
});
});

describe("isExplicitMatch()", () => {
it("should throw an error when not normalized", () => {
const filename = path.resolve(basePath, "foo.js");
assert.throws(() => {
unnormalizedConfigs.isExplicitMatch(filename);
}, /normalized/u);
});

it("should return true when passed JS filename", () => {
const filename = path.resolve(basePath, "foo.js");

assert.strictEqual(configs.isExplicitMatch(filename), true);
});

it("should return true when passed HTML filename", () => {
const filename = path.resolve(basePath, "foo.html");

assert.strictEqual(configs.isExplicitMatch(filename), true);
});

it("should return true when passed CSS filename", () => {
const filename = path.resolve(basePath, "foo.css");

assert.strictEqual(configs.isExplicitMatch(filename), true);
});

it("should return true when passed EXE filename because it matches !.css", () => {
const filename = path.resolve(basePath, "foo.exe");

assert.strictEqual(configs.isExplicitMatch(filename), true);
});

it("should return false when passed EXE filename because no explicit matches", () => {
const filename = path.resolve(basePath, "foo.exe");
configs = new ConfigArray(
[
{
files: ["*.js"],
},
],
{
basePath,
},
);
configs.normalizeSync();

assert.strictEqual(configs.isExplicitMatch(filename), false);
});

it("should return false when passed matching both files and ignores in a config", () => {
configs = new ConfigArray(
[
{
files: ["**/*.xsl"],
ignores: ["fixtures/test.xsl"],
defs: {
xsl: true,
},
},
],
{ basePath },
);

configs.normalizeSync();
const filename = path.resolve(basePath, "fixtures/test.xsl");

assert.strictEqual(configs.isExplicitMatch(filename), false);
});
});

describe("files", () => {
it("should throw an error when not normalized", () => {
assert.throws(() => {
Expand Down

0 comments on commit b546686

Please sign in to comment.