Repository: prettier/prettier-atom
Pull request #442 (2018-08-21 19:27:33)

Hotfix


Patch:
diff --git a/dist/executePrettier/executePrettierOnBufferRange.js b/dist/executePrettier/executePrettierOnBufferRange.js
index 92ef8d9..08423b0 100644
--- a/dist/executePrettier/executePrettierOnBufferRange.js
+++ b/dist/executePrettier/executePrettierOnBufferRange.js
@@ -25,16 +25,22 @@ const { getCurrentFilePath, isCurrentScopeStyleLintScope } = require('../editorI
 const { getPrettierInstance } = require('../helpers');
 const handleError = require('./handleError');
 
+const getPrettierOptions = (editor
+// $FlowFixMe
+) => getPrettierInstance(editor).resolveConfig.sync(getCurrentFilePath(editor));
+
 const executePrettier = (editor, text
 // $FlowFixMe
-) => getPrettierInstance(editor).format(text, { filepath: getCurrentFilePath(editor) });
+) => getPrettierInstance(editor).format(text, (0, _extends3.default)({
+  filepath: getCurrentFilePath(editor)
+}, getPrettierOptions(editor)));
 
 const executePrettierWithCursor = (editor, text, cursorOffset
 // $FlowFixMe
-) => getPrettierInstance(editor).formatWithCursor(text, {
+) => getPrettierInstance(editor).formatWithCursor(text, (0, _extends3.default)({
   cursorOffset,
   filepath: getCurrentFilePath(editor)
-});
+}, getPrettierOptions(editor)));
 
 const buildPrettierEslintOptions = (editor, text) => (0, _extends3.default)({
   text
diff --git a/src/executePrettier/executePrettierOnBufferRange.js b/src/executePrettier/executePrettierOnBufferRange.js
index 0efbdc3..25bbac0 100644
--- a/src/executePrettier/executePrettierOnBufferRange.js
+++ b/src/executePrettier/executePrettierOnBufferRange.js
@@ -14,9 +14,16 @@ const { getCurrentFilePath, isCurrentScopeStyleLintScope } = require('../editorI
 const { getPrettierInstance } = require('../helpers');
 const handleError = require('./handleError');
 
+const getPrettierOptions = (editor: TextEditor) =>
+  // $FlowFixMe
+  getPrettierInstance(editor).resolveConfig.sync(getCurrentFilePath(editor));
+
 const executePrettier = (editor: TextEditor, text: string) =>
   // $FlowFixMe
-  getPrettierInstance(editor).format(text, { filepath: getCurrentFilePath(editor) });
+  getPrettierInstance(editor).format(text, {
+    filepath: getCurrentFilePath(editor),
+    ...getPrettierOptions(editor),
+  });
 
 const executePrettierWithCursor = (
   editor: TextEditor,
@@ -27,6 +34,7 @@ const executePrettierWithCursor = (
   getPrettierInstance(editor).formatWithCursor(text, {
     cursorOffset,
     filepath: getCurrentFilePath(editor),
+    ...getPrettierOptions(editor),
   });
 
 const buildPrettierEslintOptions = (editor: TextEditor, text: string) => ({


Test patch:
diff --git a/src/executePrettier/executePrettierOnBufferRange.test.js b/src/executePrettier/executePrettierOnBufferRange.test.js
index 70c4109..bb54abc 100644
--- a/src/executePrettier/executePrettierOnBufferRange.test.js
+++ b/src/executePrettier/executePrettierOnBufferRange.test.js
@@ -25,6 +25,7 @@ let editor;
 const bufferRangeFixture = { start: { column: 0, row: 0 }, end: { column: 20, row: 0 } };
 const sourceFixture = 'const foo = (2);';
 const formattedFixture = 'const foo = 2;';
+const optionsFixture = { tabWidth: 2, filepath: 'foo.js' };
 
 beforeEach(() => {
   editor = buildMockTextEditor();
@@ -33,6 +34,7 @@ beforeEach(() => {
   prettier.format.mockImplementation(() => formattedFixture);
   prettier.formatWithCursor.mockImplementation(() => formattedFixture);
   getPrettierInstance.mockImplementation(() => prettier);
+  prettier.resolveConfig.sync.mockImplementation(() => optionsFixture);
 });
 
 it('sets the transformed text in the buffer range', async () => {
@@ -55,7 +57,7 @@ it('uses Prettier#formatWithCursor', async () => {
   }));
   await executePrettierOnBufferRange(editor, bufferRangeFixture);
 
-  expect(prettier.formatWithCursor).toHaveBeenCalledWith(sourceFixture, { cursorOffset });
+  expect(prettier.formatWithCursor).toHaveBeenCalledWith(sourceFixture, { cursorOffset, ...optionsFixture });
 });
 
 it('sets the transformed text via diff when the option is passed', async () => {
@@ -69,7 +71,10 @@ it('sets the transformed text via diff when the option is passed', async () => {
 
   await executePrettierOnBufferRange(editor, bufferRangeFixture, { setTextViaDiff: true });
 
-  expect(prettier.formatWithCursor).toHaveBeenCalledWith(sourceFixture, { cursorOffset: 0 });
+  expect(prettier.formatWithCursor).toHaveBeenCalledWith(sourceFixture, {
+    cursorOffset: 0,
+    ...optionsFixture,
+  });
   expect(setTextViaDiffMock).toHaveBeenCalled();
 
   // NOTE: there is currently a bug in prettier that causes formatWithCursor to