Repository: prettier/prettier (JavaScript)
Date: 2019-06-07 12:25:56+00:00
Task type: Bug Fix

Issue:
Overrides not applied to dotfiles
<!--

BEFORE SUBMITTING AN ISSUE:

1.  Search for your issue on GitHub: https://github.com/prettier/prettier/issues
    A large number of opened issues are duplicates of existing issues.
    If someone has already opened an issue for what you are experiencing,
    you do not need to open a new issue — please add a 👍 reaction to the
    existing issue instead.

2.  If your issue is with a prettier editor extension or add-on, please open the
    issue in the repo for that extension or add-on, instead of this repo.

-->

**Environments:**
- Prettier Version: 1.18.0
- Running Prettier via: CLI <!-- CLI, Node.js API, Browser API, etc. -->
- Runtime: <!-- Node.js v6, Chrome v67, etc. -->
- Operating System: macOS <!-- Windows, Linux, macOS, etc. -->

**Steps to reproduce:**
<!-- shell script, js code, or a link to the minimal reproducible repository -->

.prettierrc.json
```json
{
    "tabWidth": 4,
    "printWidth": 120,
    "semi": false,
    "trailingComma": "es5",
    "singleQuote": true,
    "overrides": [
        {
            "files": "*.json",
            "options": {
                "tabWidth": 2
            }
        }
    ]
}
```

I also tried with `**/*.json`, `**.json`, `**/*.*.json`, `*.*.json`.

**Expected behavior:**
`prettier .prettierrc.json --write` should format the file with 2 spaces. 

**Actual behavior:**
It formats the filee with 4 spaces.

Logs:
```
> npx prettier ./.prettierrc.json --write --config ./.prettierrc.json --loglevel=debug
[debug] normalized argv: {"_":["./.prettierrc.json"],"color":true,"editorconfig":true,"write":true,"config":"./.prettierrc.json","loglevel":"debug","plugin-search-dir":[],"plugin":[],"ignore-path":".prettierignore","debug-repeat":0,"config-precedence":"cli-override"}
[debug] load config file from './.prettierrc.json'
[debug] loaded options `{"tabWidth":4,"printWidth":120,"semi":false,"trailingComma":"es5","singleQuote":true}`
[debug] applied config-precedence (cli-override): {"printWidth":120,"semi":false,"singleQuote":true,"tabWidth":4,"trailingComma":"es5"}
.prettierrc.json 25ms
```

Note how `tabWidth: 4` is used.


Issue discussion:

Solution patch:
diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md
index df2af2751f2a..d16b0cf35766 100644
--- a/CHANGELOG.unreleased.md
+++ b/CHANGELOG.unreleased.md
@@ -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
diff --git a/src/config/resolve-config.js b/src/config/resolve-config.js
index 2f175a79f357..0c27eed0594b 100644
--- a/src/config/resolve-config.js
+++ b/src/config/resolve-config.js
@@ -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)) &&


Test patch:
diff --git a/tests_integration/__tests__/config-resolution.js b/tests_integration/__tests__/config-resolution.js
index e2f20d42884a..841c9f3ceb94 100644
--- a/tests_integration/__tests__/config-resolution.js
+++ b/tests_integration/__tests__/config-resolution.js
@@ -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");
diff --git a/tests_integration/cli/config/dot-overrides/.prettierrc b/tests_integration/cli/config/dot-overrides/.prettierrc
new file mode 100644
index 000000000000..10dbdb5a12b7
--- /dev/null
+++ b/tests_integration/cli/config/dot-overrides/.prettierrc
@@ -0,0 +1,11 @@
+{
+  "tabWidth": 2,
+  overrides: [
+    {
+      "files": "*.json",
+      "options": {
+        "tabWidth": 4
+      }
+    }
+  ]
+}