Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: newBasePath should be an absolute path (fixes #12850) #13078

Merged
merged 3 commits into from Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/cli-engine/config-array/ignore-pattern.js
Expand Up @@ -71,7 +71,13 @@ function getCommonAncestorPath(sourcePaths) {
}
}

return result || path.sep;
let resolvedResult = result || path.sep;

// if Windows common ancestor is root of drive must have trailing slash to be absolute.
if (resolvedResult && resolvedResult.endsWith(":") && process.platform === "win32") {
resolvedResult += path.sep;
}
return resolvedResult;
}

/**
Expand Down
131 changes: 68 additions & 63 deletions tests/lib/cli-engine/config-array/ignore-pattern.js
Expand Up @@ -52,74 +52,79 @@ describe("IgnorePattern", () => {

describe("static createIgnore(ignorePatterns)", () => {
describe("with two patterns should return a function, and the function", () => {
const cwd = process.cwd();
const basePath1 = path.join(cwd, "foo/bar");
const basePath2 = path.join(cwd, "abc/");
const ignores = IgnorePattern.createIgnore([
new IgnorePattern(["*.js", "/*.ts", "!a.*", "!/b.*"], basePath1),
new IgnorePattern(["*.js", "/*.ts", "!a.*", "!/b.*"], basePath2)
]);
const patterns = [
["a.js", false],
["a.ts", false],
["b.js", false],
["b.ts", false],
["c.js", false],
["c.ts", false],
["dir/a.js", false],
["dir/a.ts", false],
["dir/b.js", false],
["dir/b.ts", false],
["dir/c.js", false],
["dir/c.ts", false],
["foo/bar/a.js", false],
["foo/bar/a.ts", false],
["foo/bar/b.js", false],
["foo/bar/b.ts", false],
["foo/bar/c.js", true],
["foo/bar/c.ts", true],
["foo/bar/dir/a.js", false],
["foo/bar/dir/a.ts", false],
["foo/bar/dir/b.js", true],
["foo/bar/dir/b.ts", false],
["foo/bar/dir/c.js", true],
["foo/bar/dir/c.ts", false],
["abc/a.js", false],
["abc/a.ts", false],
["abc/b.js", false],
["abc/b.ts", false],
["abc/c.js", true],
["abc/c.ts", true],
["abc/dir/a.js", false],
["abc/dir/a.ts", false],
["abc/dir/b.js", true],
["abc/dir/b.ts", false],
["abc/dir/c.js", true],
["abc/dir/c.ts", false]
];

for (const [filename, expected] of patterns) {
it(`should return ${expected} if '${filename}' was given.`, () => {
assert.strictEqual(ignores(path.join(cwd, filename)), expected);
// eslint-disable-next-line func-style
nickharris marked this conversation as resolved.
Show resolved Hide resolved
const assertions = cwd => {
const basePath1 = path.join(cwd, "foo/bar");
const basePath2 = path.join(cwd, "abc/");
const ignores = IgnorePattern.createIgnore([
new IgnorePattern(["*.js", "/*.ts", "!a.*", "!/b.*"], basePath1),
new IgnorePattern(["*.js", "/*.ts", "!a.*", "!/b.*"], basePath2)
]);
const patterns = [
["a.js", false],
["a.ts", false],
["b.js", false],
["b.ts", false],
["c.js", false],
["c.ts", false],
["dir/a.js", false],
["dir/a.ts", false],
["dir/b.js", false],
["dir/b.ts", false],
["dir/c.js", false],
["dir/c.ts", false],
["foo/bar/a.js", false],
["foo/bar/a.ts", false],
["foo/bar/b.js", false],
["foo/bar/b.ts", false],
["foo/bar/c.js", true],
["foo/bar/c.ts", true],
["foo/bar/dir/a.js", false],
["foo/bar/dir/a.ts", false],
["foo/bar/dir/b.js", true],
["foo/bar/dir/b.ts", false],
["foo/bar/dir/c.js", true],
["foo/bar/dir/c.ts", false],
["abc/a.js", false],
["abc/a.ts", false],
["abc/b.js", false],
["abc/b.ts", false],
["abc/c.js", true],
["abc/c.ts", true],
["abc/dir/a.js", false],
["abc/dir/a.ts", false],
["abc/dir/b.js", true],
["abc/dir/b.ts", false],
["abc/dir/c.js", true],
["abc/dir/c.ts", false]
];

for (const [filename, expected] of patterns) {
it(`should return ${expected} if '${filename}' was given.`, () => {
assert.strictEqual(ignores(path.join(cwd, filename)), expected);
});
}

it("should return false if '.dot.js' and false was given.", () => {
assert.strictEqual(ignores(path.join(cwd, ".dot.js"), false), true);
});
}

it("should return false if '.dot.js' and false was given.", () => {
assert.strictEqual(ignores(path.join(cwd, ".dot.js"), false), true);
});

it("should return true if '.dot.js' and true were given.", () => {
assert.strictEqual(ignores(path.join(cwd, ".dot.js"), true), false);
});
it("should return true if '.dot.js' and true were given.", () => {
assert.strictEqual(ignores(path.join(cwd, ".dot.js"), true), false);
});

it("should return false if '.dot/foo.js' and false was given.", () => {
assert.strictEqual(ignores(path.join(cwd, ".dot/foo.js"), false), true);
});

it("should return false if '.dot/foo.js' and false was given.", () => {
assert.strictEqual(ignores(path.join(cwd, ".dot/foo.js"), false), true);
});
it("should return true if '.dot/foo.js' and true were given.", () => {
assert.strictEqual(ignores(path.join(cwd, ".dot/foo.js"), true), false);
});
};

it("should return true if '.dot/foo.js' and true were given.", () => {
assert.strictEqual(ignores(path.join(cwd, ".dot/foo.js"), true), false);
});
assertions(process.cwd());
nickharris marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line no-restricted-syntax
nickharris marked this conversation as resolved.
Show resolved Hide resolved
assert.doesNotThrow(() => assertions(path.parse(process.cwd()).root), "with two patterns the common ancestor is the root of the drive should not throw exception \"'newBasePath' should be an absolute path\"");
});
});
});