Skip to content

Commit

Permalink
Support overrides for dotfiles (#6194)
Browse files Browse the repository at this point in the history
  • Loading branch information
duailibe committed Jun 7, 2019
1 parent 8812792 commit 4483282
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
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", () => {
const folder = path.join(__dirname, "../cli/config/dot-overrides");
return expect(
prettier.resolveConfig(path.join(folder, ".foo.json"))
).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
}
}
]
}

0 comments on commit 4483282

Please sign in to comment.