Skip to content

Commit fe5b524

Browse files
Arvolearfvictorio
authored andcommitted
fix filtering
1 parent 64250ba commit fe5b524

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,19 @@ export class BasicConfigLoader implements ConfigLoader {
138138
};
139139

140140
for (const configObject of this.config) {
141+
const slicedFilePath = filePath.startsWith("./")
142+
? filePath.slice(2)
143+
: filePath;
144+
141145
if (
142146
configObject.ignores.length > 0 &&
143-
micromatch([filePath], configObject.ignores).length > 0
147+
micromatch([slicedFilePath], configObject.ignores).length > 0
144148
) {
145149
continue;
146150
}
147151

148152
if (configObject.files.length > 0) {
149-
if (micromatch([filePath], configObject.files).length === 0) {
153+
if (micromatch([slicedFilePath], configObject.files).length === 0) {
150154
continue;
151155
}
152156
}

test/config.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,20 @@ describe("config", function () {
211211
});
212212
});
213213

214+
it("should work with a local object with matching files", function () {
215+
const userConfig: UserConfig = {
216+
files: ["./path/**/*.js"],
217+
rules: { "some-rule": "off" },
218+
};
219+
const configLoader = BasicConfigLoader.create(userConfig);
220+
221+
const config = configLoader.loadConfig("./path/to/file.js");
222+
223+
expect(config).toEqual({
224+
rules: { "some-rule": ["off"] },
225+
});
226+
});
227+
214228
it("should work with an object with no matching files", function () {
215229
const userConfig: UserConfig = {
216230
files: ["/path/**/*.js"],
@@ -239,6 +253,20 @@ describe("config", function () {
239253
});
240254
});
241255

256+
it("should work with a local object with matching ignores", function () {
257+
const userConfig: UserConfig = {
258+
ignores: ["./path/**/*.js"],
259+
rules: { "some-rule": "off" },
260+
};
261+
const configLoader = BasicConfigLoader.create(userConfig);
262+
263+
const config = configLoader.loadConfig("./path/to/file.js");
264+
265+
expect(config).toEqual({
266+
rules: {},
267+
});
268+
});
269+
242270
it("should work with an object with no matching ignores", function () {
243271
const userConfig: UserConfig = {
244272
ignores: ["/path/**/*.js"],

0 commit comments

Comments
 (0)