Repository: prettier/prettier-atom (js)

Issue:
Request: remove merging of explicit configurations with atom-prettier settings
I just spent some time looking into why my prettier settings in package.json weren't being respected, and it's due to [them being assigned over atom-prettier settings](https://github.com/prettier/prettier-atom/blob/master/src/executePrettier/buildPrettierOptions.js#L70-L74).  I'm wondering what the use-case is for

1. allowing users to `only format if a prettier config is found` and
2. assigning the prettier config over those in atom-prettier.

i.e. why would I want to require an explicit configuration while also using the one local to my editor?  I assume the use-case for allowing users to require both an explicit prettier instance and settings would be to ensure consistent formatting should they move to a different editor or machine.

Even if I set atom-prettier's settings to the defaults, this could become problematic should the defaults in the local prettier instance be different.

Another less breaking solution would be to add an option to ignore atom-prettier's configuration settings.

I'm willing to create a PR if either solution is agreeable.

Pull request:
refactor(buildPrettierOptions.js): Exclusively use local config or pl…
…ugin settings

Stop the current behavior of merging a local prettier config with
  those found in the plugin settings.  The reason being a project
  should be formatted according to its own rules, and per Prettier
  convention, omitted rules should fallback to defaults.

Remove the plugin's integration with editorconfig in favor of relying
  on prettier's via its editorconfig option.

BREAKING CHANGE: The formatting configuration is now built according to different rules

fix #370

Patch:
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 22b2eac..1f32bc7 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -275,6 +275,15 @@
         "code",
         "test"
       ]
+    },
+    {
+      "login": "olsonpm",
+      "name": "olsonpm",
+      "avatar_url": "https://avatars2.githubusercontent.com/u/5957709?v=4",
+      "profile": "https://github.com/olsonpm",
+      "contributions": [
+        "code"
+      ]
     }
   ]
 }
diff --git a/README.md b/README.md
index 875dd7c..beac3f8 100644
--- a/README.md
+++ b/README.md
@@ -62,14 +62,13 @@ This repository was created by [James Long][james-long] to go along with his Pre
 Thanks goes to these people ([emoji key][emojis]):
 
 <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
-
 <!-- prettier-ignore -->
 | [<img src="https://avatars.githubusercontent.com/u/17031?v=3" width="100px;"/><br /><sub><b>James Long</b></sub>](http://jlongster.com)<br />[💬](#question-jlongster "Answering Questions") [💻](https://github.com/prettier/prettier-atom/commits?author=jlongster "Code") [📖](https://github.com/prettier/prettier-atom/commits?author=jlongster "Documentation") [🔌](#plugin-jlongster "Plugin/utility libraries") [👀](#review-jlongster "Reviewed Pull Requests") | [<img src="https://avatars.githubusercontent.com/u/6173488?v=3" width="100px;"/><br /><sub><b>Rob Wise</b></sub>](https://robwise.github.io)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=robwise "Code") [📖](https://github.com/prettier/prettier-atom/commits?author=robwise "Documentation") [💬](#question-robwise "Answering Questions") [💡](#example-robwise "Examples") [👀](#review-robwise "Reviewed Pull Requests") [⚠️](https://github.com/prettier/prettier-atom/commits?author=robwise "Tests") | [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub><b>Kent C. Dodds</b></sub>](https://kentcdodds.com)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=kentcdodds "Code") [📖](https://github.com/prettier/prettier-atom/commits?author=kentcdodds "Documentation") [🚇](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") | [<img src="https://avatars.githubusercontent.com/u/1144075?v=3" width="100px;"/><br /><sub><b>Luca Barone</b></sub>](https://github.com/cloud-walker)<br /> | [<img src="https://avatars.githubusercontent.com/u/4514159?v=3" width="100px;"/><br /><sub><b>Arnar Þór Sveinsson</b></sub>](https://github.com/arnarthor)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=arnarthor "Code") | [<img src="https://avatars.githubusercontent.com/u/131916?v=3" width="100px;"/><br /><sub><b>Adam Miskiewicz</b></sub>](http://www.adammiskiewicz.com/)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=skevy "Code") | [<img src="https://avatars.githubusercontent.com/u/2685242?v=3" width="100px;"/><br /><sub><b>Ori Livni</b></sub>](http://www.orilivni.com)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=oriSomething "Code") |
 | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
 | [<img src="https://avatars.githubusercontent.com/u/6182852?v=3" width="100px;"/><br /><sub><b>Leon Chen</b></sub>](https://transcranial.github.io)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=transcranial "Code") | [<img src="https://avatars.githubusercontent.com/u/197597?v=3" width="100px;"/><br /><sub><b>Christopher Chedeau</b></sub>](http://blog.vjeux.com/)<br />[💬](#question-vjeux "Answering Questions") [💻](https://github.com/prettier/prettier-atom/commits?author=vjeux "Code") [🔌](#plugin-vjeux "Plugin/utility libraries") | [<img src="https://avatars.githubusercontent.com/u/646693?v=3" width="100px;"/><br /><sub><b>Christoph Geschwind</b></sub>](http://christoph-geschwind.de)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=1st8 "Code") | [<img src="https://avatars.githubusercontent.com/u/35026?v=3" width="100px;"/><br /><sub><b>Andrew Hutchings</b></sub>](https://andrewhutchings.com)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=ahutchings "Code") | [<img src="https://avatars.githubusercontent.com/u/875591?v=3" width="100px;"/><br /><sub><b>David Schnurr</b></sub>](http://davidschnurr.com)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=schnerd "Code") | [<img src="https://avatars.githubusercontent.com/u/484801?v=3" width="100px;"/><br /><sub><b>Ryan Cole</b></sub>](http://rycole.com/)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=ryancole "Code") | [<img src="https://avatars0.githubusercontent.com/u/11488612?v=3" width="100px;"/><br /><sub><b>Dara Hak</b></sub>](https://github.com/darahak)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=darahak "Code") [📖](https://github.com/prettier/prettier-atom/commits?author=darahak "Documentation") |
 | [<img src="https://avatars3.githubusercontent.com/u/487068?v=3" width="100px;"/><br /><sub><b>Stephen John Sorensen</b></sub>](http://www.stephenjohnsorensen.com/)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=spudly "Code") | [<img src="https://avatars2.githubusercontent.com/u/13285808?v=3" width="100px;"/><br /><sub><b>Lukas Geiger</b></sub>](https://github.com/lgeiger)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=lgeiger "Code") [⚠️](https://github.com/prettier/prettier-atom/commits?author=lgeiger "Tests") | [<img src="https://avatars2.githubusercontent.com/u/1517854?v=3" width="100px;"/><br /><sub><b>Viktor Charypar</b></sub>](https://github.com/charypar)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=charypar "Code") [⚠️](https://github.com/prettier/prettier-atom/commits?author=charypar "Tests") | [<img src="https://avatars0.githubusercontent.com/u/1007436?v=3" width="100px;"/><br /><sub><b>Mats Högberg</b></sub>](http://mats.hgbrg.se)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=mhgbrg "Code") | [<img src="https://avatars0.githubusercontent.com/u/2602767?v=3" width="100px;"/><br /><sub><b>Roman</b></sub>](https://github.com/RoM4iK)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=RoM4iK "Code") | [<img src="https://avatars2.githubusercontent.com/u/1468518?v=3" width="100px;"/><br /><sub><b>vaibhav</b></sub>](https://vaibhavchatarkar.com)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=da-vaibhav "Code") | [<img src="https://avatars1.githubusercontent.com/u/1935696?v=3" width="100px;"/><br /><sub><b>Karl Horky</b></sub>](https://work.karlhorky.com)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=karlhorky "Code") |
 | [<img src="https://avatars3.githubusercontent.com/u/810438?v=3" width="100px;"/><br /><sub><b>Dan Abramov</b></sub>](http://twitter.com/dan_abramov)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=gaearon "Code") | [<img src="https://avatars3.githubusercontent.com/u/1227109?v=3" width="100px;"/><br /><sub><b>Murphy Randle</b></sub>](https://sploding.rocks)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=splodingsocks "Code") [🐛](https://github.com/prettier/prettier-atom/issues?q=author%3Asplodingsocks "Bug reports") | [<img src="https://avatars3.githubusercontent.com/u/8517072?v=3" width="100px;"/><br /><sub><b>Matthieu Lemoine</b></sub>](https://matthieulemoine.com)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=MatthieuLemoine "Code") | [<img src="https://avatars1.githubusercontent.com/u/37242?v=4" width="100px;"/><br /><sub><b>Ron Green</b></sub>](https://github.com/rgreenjr)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=rgreenjr "Code") | [<img src="https://avatars2.githubusercontent.com/u/1745854?v=4" width="100px;"/><br /><sub><b>Harold Treen</b></sub>](https://haroldtreen.com)<br />[🐛](https://github.com/prettier/prettier-atom/issues?q=author%3Aharoldtreen "Bug reports") [💻](https://github.com/prettier/prettier-atom/commits?author=haroldtreen "Code") | [<img src="https://avatars1.githubusercontent.com/u/3447641?v=4" width="100px;"/><br /><sub><b>Nikita Mashukov</b></sub>](https://github.com/ferdibiflator)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=ferdibiflator "Code") | [<img src="https://avatars0.githubusercontent.com/u/8203211?v=4" width="100px;"/><br /><sub><b>Sam Horton</b></sub>](https://github.com/SavePointSam)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=SavePointSam "Code") [⚠️](https://github.com/prettier/prettier-atom/commits?author=SavePointSam "Tests") |
-
+| [<img src="https://avatars2.githubusercontent.com/u/5957709?v=4" width="100px;"/><br /><sub><b>olsonpm</b></sub>](https://github.com/olsonpm)<br />[💻](https://github.com/prettier/prettier-atom/commits?author=olsonpm "Code") |
 <!-- ALL-CONTRIBUTORS-LIST:END -->
 
 This project follows the [all-contributors][all-contributors] specification. Contributions of any kind are welcome!
diff --git a/dist/config-schema.json b/dist/config-schema.json
index 93139a4..42abd1c 100644
--- a/dist/config-schema.json
+++ b/dist/config-schema.json
@@ -168,7 +168,7 @@
       },
       "isDisabledIfNoConfigFile": {
         "title": "Only format if a Prettier config is found",
-        "description": "Only format on save if we find a `.prettierrc` file (written in YAML or JSON), a `prettier.config.js` file that exports an object, or a 'prettier' key in your `package.json` file. <br><br>**Note:** You must have at least one valid rule in order for your config to be considered present.",
+        "description": "Only format on save if we find a `.prettierrc` file (written in YAML or JSON), a `prettier.config.js` file that exports an object, or a 'prettier' key in your `package.json` file.",
         "type": "boolean",
         "default": false,
         "order": 14
diff --git a/dist/executePrettier/buildPrettierOptions.js b/dist/executePrettier/buildPrettierOptions.js
index 63986ea..aea4a2c 100644
--- a/dist/executePrettier/buildPrettierOptions.js
+++ b/dist/executePrettier/buildPrettierOptions.js
@@ -34,42 +34,61 @@ 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)) : null;
+  return isDefined(getPrettierInstance(editor).resolveConfig.sync) ? getPrettierInstance(editor).resolveConfig.sync(getCurrentFilePath(editor), {
+    editorconfig: shouldUseEditorConfig()
+  }) : null;
 }]]);
 
-var buildPrettierOptions = function buildPrettierOptions(editor) {
-  var optionsFromSettings = getPrettierOptions();
-
-  if (optionsFromSettings.tabWidth === 'auto') {
-    optionsFromSettings.tabWidth = getAtomTabLength(editor);
-  }
+var getScopeSpecificSettings = function getScopeSpecificSettings(editor) {
+  var scopeSpecificSettings = {};
 
   if (isCurrentScopeTypescriptScope(editor)) {
-    optionsFromSettings.parser = 'typescript';
+    scopeSpecificSettings.parser = 'typescript';
   }
 
   if (isCurrentScopeCssScope(editor)) {
-    optionsFromSettings.parser = 'postcss';
+    scopeSpecificSettings.parser = 'postcss';
   }
 
   if (isCurrentScopeJsonScope(editor)) {
-    optionsFromSettings.parser = 'json';
-    optionsFromSettings.trailingComma = 'none';
+    scopeSpecificSettings.parser = 'json';
+    scopeSpecificSettings.trailingComma = 'none';
   }
 
   if (isCurrentScopeGraphQlScope(editor)) {
-    optionsFromSettings.parser = 'graphql';
+    scopeSpecificSettings.parser = 'graphql';
   }
 
   if (isCurrentScopeMarkdownScope(editor)) {
-    optionsFromSettings.parser = 'markdown';
+    scopeSpecificSettings.parser = 'markdown';
   }
 
   if (isCurrentScopeVueScope(editor)) {
-    optionsFromSettings.parser = 'vue';
+    scopeSpecificSettings.parser = 'vue';
+  }
+
+  return scopeSpecificSettings;
+};
+
+var getOptionsFromSettings = function getOptionsFromSettings(editor, scopeSpecificSettings) {
+  var optionsFromSettings = getPrettierOptions();
+
+  if (optionsFromSettings.tabWidth === 'auto') {
+    optionsFromSettings.tabWidth = getAtomTabLength(editor);
+  }
+
+  return (0, _extends3.default)({}, optionsFromSettings, scopeSpecificSettings, buildEditorConfigOptionsIfAppropriate(editor));
+};
+
+var buildPrettierOptions = function buildPrettierOptions(editor) {
+  var prettierConfigOptions = getPrettierConfigOptions(editor);
+  var scopeSpecificSettings = getScopeSpecificSettings(editor);
+
+  if (prettierConfigOptions) {
+    return (0, _extends3.default)({}, scopeSpecificSettings, prettierConfigOptions);
   }
 
-  return (0, _extends3.default)({}, optionsFromSettings, buildEditorConfigOptionsIfAppropriate(editor), getPrettierConfigOptions(editor));
+  return getOptionsFromSettings(editor, scopeSpecificSettings);
 };
 
 module.exports = buildPrettierOptions;
\ No newline at end of file
diff --git a/src/config-schema.json b/src/config-schema.json
index 93139a4..42abd1c 100644
--- a/src/config-schema.json
+++ b/src/config-schema.json
@@ -168,7 +168,7 @@
       },
       "isDisabledIfNoConfigFile": {
         "title": "Only format if a Prettier config is found",
-        "description": "Only format on save if we find a `.prettierrc` file (written in YAML or JSON), a `prettier.config.js` file that exports an object, or a 'prettier' key in your `package.json` file. <br><br>**Note:** You must have at least one valid rule in order for your config to be considered present.",
+        "description": "Only format on save if we find a `.prettierrc` file (written in YAML or JSON), a `prettier.config.js` file that exports an object, or a 'prettier' key in your `package.json` file.",
         "type": "boolean",
         "default": false,
         "order": 14
diff --git a/src/executePrettier/buildPrettierOptions.js b/src/executePrettier/buildPrettierOptions.js
index 831c85e..aaba4d0 100644
--- a/src/executePrettier/buildPrettierOptions.js
+++ b/src/executePrettier/buildPrettierOptions.js
@@ -30,48 +30,70 @@ const getPrettierConfigOptions: (editor: TextEditor) => ?{} = _.cond([
     _.flow(getCurrentFilePath, isDefined),
     editor =>
       isDefined(getPrettierInstance(editor).resolveConfig.sync)
-        ? getPrettierInstance(editor).resolveConfig.sync(getCurrentFilePath(editor))
+        ? getPrettierInstance(editor).resolveConfig.sync(getCurrentFilePath(editor), {
+            editorconfig: shouldUseEditorConfig(),
+          })
         : null,
   ],
 ]);
 
-const buildPrettierOptions = (editor: TextEditor) => {
-  const optionsFromSettings = getPrettierOptions();
-
-  if (optionsFromSettings.tabWidth === 'auto') {
-    optionsFromSettings.tabWidth = getAtomTabLength(editor);
-  }
+const getScopeSpecificSettings = (editor: TextEditor) => {
+  const scopeSpecificSettings = {};
 
   if (isCurrentScopeTypescriptScope(editor)) {
-    optionsFromSettings.parser = 'typescript';
+    scopeSpecificSettings.parser = 'typescript';
   }
 
   if (isCurrentScopeCssScope(editor)) {
-    optionsFromSettings.parser = 'postcss';
+    scopeSpecificSettings.parser = 'postcss';
   }
 
   if (isCurrentScopeJsonScope(editor)) {
-    optionsFromSettings.parser = 'json';
-    optionsFromSettings.trailingComma = 'none';
+    scopeSpecificSettings.parser = 'json';
+    scopeSpecificSettings.trailingComma = 'none';
   }
 
   if (isCurrentScopeGraphQlScope(editor)) {
-    optionsFromSettings.parser = 'graphql';
+    scopeSpecificSettings.parser = 'graphql';
   }
 
   if (isCurrentScopeMarkdownScope(editor)) {
-    optionsFromSettings.parser = 'markdown';
+    scopeSpecificSettings.parser = 'markdown';
   }
 
   if (isCurrentScopeVueScope(editor)) {
-    optionsFromSettings.parser = 'vue';
+    scopeSpecificSettings.parser = 'vue';
+  }
+
+  return scopeSpecificSettings;
+};
+
+const getOptionsFromSettings = (editor: TextEditor, scopeSpecificSettings: Object) => {
+  const optionsFromSettings = getPrettierOptions();
+
+  if (optionsFromSettings.tabWidth === 'auto') {
+    optionsFromSettings.tabWidth = getAtomTabLength(editor);
   }
 
   return {
     ...optionsFromSettings,
+    ...scopeSpecificSettings,
     ...buildEditorConfigOptionsIfAppropriate(editor),
-    ...getPrettierConfigOptions(editor),
   };
 };
 
+const buildPrettierOptions = (editor: TextEditor) => {
+  const prettierConfigOptions = getPrettierConfigOptions(editor);
+  const scopeSpecificSettings = getScopeSpecificSettings(editor);
+
+  if (prettierConfigOptions) {
+    return {
+      ...scopeSpecificSettings,
+      ...prettierConfigOptions,
+    };
+  }
+
+  return getOptionsFromSettings(editor, scopeSpecificSettings);
+};
+
 module.exports = buildPrettierOptions;


Test patch:
diff --git a/src/executePrettier/buildPrettierOptions.test.js b/src/executePrettier/buildPrettierOptions.test.js
index 6d6d0ef..285ec89 100644
--- a/src/executePrettier/buildPrettierOptions.test.js
+++ b/src/executePrettier/buildPrettierOptions.test.js
@@ -109,40 +109,61 @@ it('uses vue as the parser if current scope is listed as a Vue SFC scope in sett
   expect(actual).toEqual({ parser: 'vue' });
 });
 
-it('does not use editorconfig options if that setting is not enabled', () => {
-  const editor = buildMockEditor();
-  getPrettierOptions.mockImplementation(() => ({}));
-  shouldUseEditorConfig.mockImplementation(() => false);
-
-  buildPrettierOptions(editor);
-
-  expect(buildEditorConfigOptions).not.toHaveBeenCalled();
+describe('when a prettier config is found', () => {
+  it('returns settings from the prettier config', () => {
+    const editor = buildMockEditor();
+    const fakePrettierConfigOptions = { tabWidth: 4, printWidth: 100, useTabs: true };
+    const mockPrettierInstance = { resolveConfig: { sync: jest.fn(() => fakePrettierConfigOptions) } };
+    getPrettierInstance.mockImplementation(() => mockPrettierInstance);
+    getCurrentFilePath.mockImplementation(() => 'parent-dir/foo.js');
+
+    const actual = buildPrettierOptions(editor);
+
+    expect(actual).toEqual(fakePrettierConfigOptions);
+  });
+
+  it('tells prettier whether to use editorconfig when resolving options', () => {
+    const editorconfig = true;
+    const editor = buildMockEditor();
+    const mockPrettierInstance = { resolveConfig: { sync: jest.fn(() => ({})) } };
+    getPrettierInstance.mockImplementation(() => mockPrettierInstance);
+    shouldUseEditorConfig.mockImplementation(() => editorconfig);
+    getCurrentFilePath.mockImplementation(() => 'parent-dir/foo.js');
+
+    buildPrettierOptions(editor);
+
+    expect(mockPrettierInstance.resolveConfig.sync.mock.calls[0][1]).toEqual({ editorconfig });
+  });
 });
 
-it('overrides values with editorconfig values if editor config is enabled', () => {
-  const editor = buildMockEditor();
-  const fakePrettierOptions = { tabWidth: 2, printWidth: 80, useTabs: false };
-  const fakeEditorConfigOptions = { tabWidth: 4, printWidth: 100, useTabs: true };
-  getPrettierOptions.mockImplementation(() => fakePrettierOptions);
-  buildEditorConfigOptions.mockImplementation(() => fakeEditorConfigOptions);
-  shouldUseEditorConfig.mockImplementation(() => true);
-  getCurrentFilePath.mockImplementation(() => 'parent-dir/foo.js');
-
-  const actual = buildPrettierOptions(editor);
-
-  expect(actual).toEqual(fakeEditorConfigOptions);
-});
-
-it('overrides values with prettier config values if one exists', () => {
-  const editor = buildMockEditor();
-  const fakePrettierOptions = { tabWidth: 2, printWidth: 80, useTabs: false };
-  const fakePrettierConfigOptions = { tabWidth: 4, printWidth: 100, useTabs: true };
-  const mockPrettierInstance = { resolveConfig: { sync: jest.fn(() => fakePrettierConfigOptions) } };
-  getPrettierInstance.mockImplementation(() => mockPrettierInstance);
-  getCurrentFilePath.mockImplementation(() => 'parent-dir/foo.js');
-  getPrettierOptions.mockImplementation(() => fakePrettierOptions);
-
-  const actual = buildPrettierOptions(editor);
-
-  expect(actual).toEqual(fakePrettierConfigOptions);
+describe('when a prettier config is not found', () => {
+  it('returns settings from prettier-atom', () => {
+    const editor = buildMockEditor();
+    const fakePrettierOptions = { singleQuote: true, tabWidth: 2 };
+    const mockPrettierInstance = { resolveConfig: { sync: jest.fn(() => null) } };
+    getPrettierInstance.mockImplementation(() => mockPrettierInstance);
+    shouldUseEditorConfig.mockImplementation(() => false);
+    getCurrentFilePath.mockImplementation(() => 'parent-dir/foo.js');
+    getPrettierOptions.mockImplementation(() => fakePrettierOptions);
+
+    const actual = buildPrettierOptions(editor);
+
+    expect(actual).toEqual(fakePrettierOptions);
+  });
+
+  it('overrides prettier-atom settings with editorconfig values if editor config is enabled', () => {
+    const editor = buildMockEditor();
+    const fakePrettierOptions = { singleQuote: true, tabWidth: 2 };
+    const fakeEditorConfigOptions = { tabWidth: 4 };
+    const mockPrettierInstance = { resolveConfig: { sync: jest.fn(() => null) } };
+    getPrettierInstance.mockImplementation(() => mockPrettierInstance);
+    buildEditorConfigOptions.mockImplementation(() => fakeEditorConfigOptions);
+    shouldUseEditorConfig.mockImplementation(() => true);
+    getCurrentFilePath.mockImplementation(() => 'parent-dir/foo.js');
+    getPrettierOptions.mockImplementation(() => fakePrettierOptions);
+
+    const actual = buildPrettierOptions(editor);
+
+    expect(actual).toEqual({ ...fakePrettierOptions, ...fakeEditorConfigOptions });
+  });
 });