Support overrides for dotfiles (#6194)

master
Lucas Duailibe 2019-06-07 09:45:56 -03:00 committed by GitHub
parent 8812792e93
commit 448328270d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 1 deletions

View File

@ -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

View File

@ -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)) &&

View File

@ -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");

View File

@ -0,0 +1,11 @@
{
"tabWidth": 2,
overrides: [
{
"files": "*.json",
"options": {
"tabWidth": 4
}
}
]
}