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

Support overrides for dotfiles #6194

Merged
merged 4 commits into from Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
6 changes: 6 additions & 0 deletions CHANGELOG.unreleased.md
Expand Up @@ -75,5 +75,11 @@ function function1<T>() {
}
```

#### Config: Match dotfiles in config overrides ([#6194] by [@duailibe])

When using [`overrides`](https://prettier.io/docs/en/configuration.html#configuration-overrides) in the config file, Prettier was not matching dotfiles (files that start with `.`). This was fixed in 1.18.1

[#6190]: https://github.com/prettier/prettier/pull/6190
[#6194]: https://github.com/prettier/prettier/pull/6194
[@duailibe]: https://github.com/duailibe
[@sosukesuzuki]: https://github.com/sosukesuzuki
2 changes: 1 addition & 1 deletion src/config/resolve-config.js
Expand Up @@ -158,7 +158,7 @@ function mergeOverrides(configResult, filePath) {
function pathMatchesGlobs(filePath, patterns, excludedPatterns) {
const patternList = [].concat(patterns);
const excludedPatternList = [].concat(excludedPatterns || []);
const opts = { matchBase: true };
const opts = { matchBase: true, dot: true };

return (
patternList.some(pattern => minimatch(filePath, pattern, opts)) &&
Expand Down
9 changes: 9 additions & 0 deletions tests_integration/__tests__/config-resolution.js
Expand Up @@ -232,6 +232,15 @@ test("API clearConfigCache", () => {
expect(() => prettier.clearConfigCache()).not.toThrowError();
});

test("API resolveConfig overrides work with dotfiles", async () => {
const folder = path.join(__dirname, "../cli/config/dot-overrides");
await expect(
prettier.resolveConfig(path.join(folder, "foo.json"))
duailibe marked this conversation as resolved.
Show resolved Hide resolved
).resolves.toMatchObject({
tabWidth: 4
});
});

test("API resolveConfig.sync overrides work with absolute paths", () => {
// Absolute path
const file = path.join(__dirname, "../cli/config/filepath/subfolder/file.js");
Expand Down
11 changes: 11 additions & 0 deletions tests_integration/cli/config/dot-overrides/.prettierrc
@@ -0,0 +1,11 @@
{
"tabWidth": 2,
overrides: [
{
"files": "*.json",
"options": {
"tabWidth": 4
}
}
]
}