Repository: prettier/prettier-atom (js)

Issue:
Using editor preferences
Updating to `prettier-atom@0.50.0` I've noticed my editor preference for single quotes isn't being respected. It's formatting everything to be double quotes.

I'm only using `prettier`, and have the `eslint` integration disabled. I do have an eslint config, but that also is set to use single quotes.

I'm guessing this may be a result of #374?

```
Atom version: 1.23.3
prettier-atom version: 0.50.0
prettier version: 1.10.2
prettier-eslint version: 8.8.1
prettier-atom configuration: {
  "formatOnSaveOptions": {
    "enabled": true,
    "excludedGlobs": [
      "package.json"
    ],
    "respectEslintignore": true,
    "showInStatusBar": false,
    "javascriptScopes": [
      "source.js",
      "source.jsx",
      "source.js.jsx",
      "source.babel",
      "source.js-semantic",
      "text.html.basic",
      "text.html.vue"
    ],
    "typescriptScopes": [
      "source.ts",
      "source.tsx",
      "source.ts.tsx"
    ],
    "cssScopes": [
      "source.css",
      "source.less",
      "source.css.less",
      "source.scss",
      "source.css.scss",
      "source.css.postcss"
    ],
    "jsonScopes": [
      "source.json"
    ],
    "graphQlScopes": [
      "source.graphql"
    ],
    "markdownScopes": [
      "source.md",
      "source.gfm",
      "text.md"
    ],
    "vueScopes": [
      "text.html.vue"
    ],
    "whitelistedGlobs": [],
    "isDisabledIfNotInPackageJson": false,
    "isDisabledIfNoConfigFile": false
  },
  "prettierOptions": {
    "arrowParens": "always",
    "singleQuote": true,
    "trailingComma": "all",
    "bracketSpacing": true,
    "semi": true,
    "useTabs": false,
    "jsxBracketSameLine": false,
    "printWidth": 80,
    "tabWidth": "auto",
    "parser": "babylon"
  },
  "silenceErrors": false,
  "useEslint": false,
  "useStylelint": false,
  "useEditorConfig": true,
  "prettierEslintOptions": {
    "prettierLast": false
  }
}
```


Pull request description:
fix(buildPrettierOptions.js): Allow EditorConfig with prettier-atom s…
…ettings

- Only resolve with editorconfig if a prettier config was found

fix #377

Patch:
diff --git a/dist/executePrettier/buildPrettierOptions.js b/dist/executePrettier/buildPrettierOptions.js
index e0f9026..6d1b472 100644
--- a/dist/executePrettier/buildPrettierOptions.js
+++ b/dist/executePrettier/buildPrettierOptions.js
@@ -36,9 +36,23 @@ var isAppropriateToBuildEditorConfigOptions = _.overEvery([isDefined, shouldUseE
 var buildEditorConfigOptionsIfAppropriate = _.flow(getCurrentFilePath, _.cond([[isAppropriateToBuildEditorConfigOptions, buildEditorConfigOptions]]));
 
 var getPrettierConfigOptions = _.cond([[_.flow(getCurrentFilePath, isDefined), function (editor) {
-  return isDefined(getPrettierInstance(editor).resolveConfig.sync) ? getPrettierInstance(editor).resolveConfig.sync(getCurrentFilePath(editor), {
-    editorconfig: shouldUseEditorConfig()
-  }) : null;
+  var hasResolveConfigSync = isDefined(getPrettierInstance(editor).resolveConfig.sync);
+  if (!hasResolveConfigSync) return null;
+
+  var resolveConfigSync = getPrettierInstance(editor).resolveConfig.sync;
+  var filePath = getCurrentFilePath(editor);
+
+  // TODO: when davidtheclark/cosmiconfig#107 is merged, this logic should
+  //   be modified to treat an empty file as an empty object.
+  var prettierConfig = resolveConfigSync(filePath);
+
+  // We only want to resolve with editorconfig when a prettier configuration
+  //   is found in the first place.
+  if (prettierConfig && shouldUseEditorConfig()) {
+    prettierConfig = resolveConfigSync(filePath, { editorconfig: true });
+  }
+
+  return prettierConfig || null;
 }]]);
 
 var getScopeSpecificSettings = function getScopeSpecificSettings(editor) {
diff --git a/src/executePrettier/buildPrettierOptions.js b/src/executePrettier/buildPrettierOptions.js
index 4d314df..c564653 100644
--- a/src/executePrettier/buildPrettierOptions.js
+++ b/src/executePrettier/buildPrettierOptions.js
@@ -40,12 +40,25 @@ const buildEditorConfigOptionsIfAppropriate: (editor: TextEditor) => ?{} = _.flo
 const getPrettierConfigOptions: (editor: TextEditor) => ?{} = _.cond([
   [
     _.flow(getCurrentFilePath, isDefined),
-    editor =>
-      isDefined(getPrettierInstance(editor).resolveConfig.sync)
-        ? getPrettierInstance(editor).resolveConfig.sync(getCurrentFilePath(editor), {
-            editorconfig: shouldUseEditorConfig(),
-          })
-        : null,
+    editor => {
+      const hasResolveConfigSync = isDefined(getPrettierInstance(editor).resolveConfig.sync);
+      if (!hasResolveConfigSync) return null;
+
+      const resolveConfigSync = getPrettierInstance(editor).resolveConfig.sync;
+      const filePath = getCurrentFilePath(editor);
+
+      // TODO: when davidtheclark/cosmiconfig#107 is merged, this logic should
+      //   be modified to treat an empty file as an empty object.
+      let prettierConfig = resolveConfigSync(filePath);
+
+      // We only want to resolve with editorconfig when a prettier configuration
+      //   is found in the first place.
+      if (prettierConfig && shouldUseEditorConfig()) {
+        prettierConfig = resolveConfigSync(filePath, { editorconfig: true });
+      }
+
+      return prettierConfig || null;
+    },
   ],
 ]);
 


Test patch:
diff --git a/src/executePrettier/buildPrettierOptions.test.js b/src/executePrettier/buildPrettierOptions.test.js
index 01a22b4..82fd2cd 100644
--- a/src/executePrettier/buildPrettierOptions.test.js
+++ b/src/executePrettier/buildPrettierOptions.test.js
@@ -133,7 +133,9 @@ describe('when a prettier config is found', () => {
 
     buildPrettierOptions(editor);
 
-    expect(mockPrettierInstance.resolveConfig.sync.mock.calls[0][1]).toEqual({ editorconfig: true });
+    expect(mockPrettierInstance.resolveConfig.sync).toHaveBeenCalledTimes(2);
+    expect(mockPrettierInstance.resolveConfig.sync.mock.calls[0][1]).toBeUndefined();
+    expect(mockPrettierInstance.resolveConfig.sync.mock.calls[1][1]).toEqual({ editorconfig: true });
   });
 });