Repository: prettier/prettier (JavaScript)

Issue:
Prettier formatting is inconsistent when using escaping in string
**Prettier 3.0.3**
[Playground link](https://prettier.io/playground/#N4Igxg9gdgLgprEAuEcAeAHCAnGACSKAZ3wFkBlAcQH1KBRAOToCUBJAYWoHkAFFgQQAqrLg2oAxfqwAyAVWZ1qAIS4ARAJp4AvAB0oeAwHMIEQwDpDcGKSKGAFAHJBACwCGMHTodE8rgDZ+eADucHgA1lAQQQ4AlADcIAA0IBAYMACW0ETIoK7Y2FE8eQjZKP5BrgCe2ckARtiuYGFW5K4AtnDS6VBwyABm-kRwdQ1NLRiN3YbIMNgArsMgQ23pM-OLRFN+cACKcxDw-YOLAFZEaORbu-uHSAN+Q8kAjjdwPAUYpSCuRAC0PXAACZApIgWaudJ+KbsCBtNquZDfAKgzZQQzbfgwWbpWpzeA8ODYLo9I4PRbOGBtPwAdWc6XgRAmYDg5BK9PSADd6ZVEWAiDUQByFqwoMDYOQwNh0ml+KLyDBKttSY8QBgCkNqQ0MIi1XAhtgOb1kt19TB3q5DPDlYsJth9Yjaq5anA-KC1d0YNT0oCYM5kAAOAAMyWwcBe6VD5stCLux2SMCdXp9fqQACZknMhoInaV7iq4G1nYDgYDpK40XMLXBxDh4VipojXHiICAAL6toA)
<!-- prettier-ignore -->
```sh
--parser babel
```

**Input:**
<!-- prettier-ignore -->
```jsx
export const MSG_GENERIC_OPERATION_FAILURE_BODY =
   goog.getMsg('That\'s all we know');
```

**Output:**
<!-- prettier-ignore -->
```jsx
export const MSG_GENERIC_OPERATION_FAILURE_BODY = goog.getMsg(
  "That's all we know",
);

```

**Second Output:**
<!-- prettier-ignore -->
```jsx
export const MSG_GENERIC_OPERATION_FAILURE_BODY =
  goog.getMsg("That's all we know");

```


Hints:
Note that the first snippet has a That's which contains a "\'" to escape the apostrophe
Please follow the issue template.
This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

Patch:
diff --git a/src/language-js/utils/index.js b/src/language-js/utils/index.js
--- a/src/language-js/utils/index.js
+++ b/src/language-js/utils/index.js
@@ -6,6 +6,7 @@ import isNextLineEmptyAfterIndex from "../../utils/is-next-line-empty.js";
 import getStringWidth from "../../utils/get-string-width.js";
 import { locStart, locEnd, hasSameLocStart } from "../loc.js";
 import getVisitorKeys from "../traverse/get-visitor-keys.js";
+import printString from "../../utils/print-string.js";
 import createTypeCheckFunction from "./create-type-check-function.js";
 import isBlockComment from "./is-block-comment.js";
 import isNodeMatches from "./is-node-matches.js";
@@ -544,7 +545,9 @@ function getExpressionInnerNodeCount(node, maxCount) {
 }
 
 const LONE_SHORT_ARGUMENT_THRESHOLD_RATE = 0.25;
-function isLoneShortArgument(node, { printWidth }) {
+function isLoneShortArgument(node, options) {
+  const { printWidth } = options;
+
   if (hasComment(node)) {
     return false;
   }
@@ -568,7 +571,7 @@ function isLoneShortArgument(node, { printWidth }) {
   }
 
   if (isStringLiteral(node)) {
-    return rawText(node).length <= threshold;
+    return printString(rawText(node), options).length <= threshold;
   }
 
   if (node.type === "TemplateLiteral") {


Test patch:
diff --git a/tests/format/js/strings/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/strings/__snapshots__/jsfmt.spec.js.snap
--- a/tests/format/js/strings/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/js/strings/__snapshots__/jsfmt.spec.js.snap
@@ -1,5 +1,51 @@
 // Jest Snapshot v1, https://goo.gl/fbAQLP
 
+exports[`escaped.js - {"trailingComma":"all"} format 1`] = `
+====================================options=====================================
+parsers: ["babel", "flow"]
+printWidth: 80
+trailingComma: "all"
+                                                                                | printWidth
+=====================================input======================================
+export const MSG_GENERIC_OPERATION_FAILURE_BODY_1 =
+  goog.getMsg("That's all we know");
+
+export const MSG_GENERIC_OPERATION_FAILURE_BODY_2 =
+  goog.getMsg("That\\'s all we know");
+
+=====================================output=====================================
+export const MSG_GENERIC_OPERATION_FAILURE_BODY_1 =
+  goog.getMsg("That's all we know");
+
+export const MSG_GENERIC_OPERATION_FAILURE_BODY_2 =
+  goog.getMsg("That's all we know");
+
+================================================================================
+`;
+
+exports[`escaped.js - {"trailingComma":"es5"} format 1`] = `
+====================================options=====================================
+parsers: ["babel", "flow"]
+printWidth: 80
+trailingComma: "es5"
+                                                                                | printWidth
+=====================================input======================================
+export const MSG_GENERIC_OPERATION_FAILURE_BODY_1 =
+  goog.getMsg("That's all we know");
+
+export const MSG_GENERIC_OPERATION_FAILURE_BODY_2 =
+  goog.getMsg("That\\'s all we know");
+
+=====================================output=====================================
+export const MSG_GENERIC_OPERATION_FAILURE_BODY_1 =
+  goog.getMsg("That's all we know");
+
+export const MSG_GENERIC_OPERATION_FAILURE_BODY_2 =
+  goog.getMsg("That's all we know");
+
+================================================================================
+`;
+
 exports[`multiline-literal.js - {"trailingComma":"all"} format 1`] = `
 ====================================options=====================================
 parsers: ["babel", "flow"]
diff --git a/tests/format/js/strings/escaped.js b/tests/format/js/strings/escaped.js
new file mode 100644
--- /dev/null
+++ b/tests/format/js/strings/escaped.js
@@ -0,0 +1,5 @@
+export const MSG_GENERIC_OPERATION_FAILURE_BODY_1 =
+  goog.getMsg("That's all we know");
+
+export const MSG_GENERIC_OPERATION_FAILURE_BODY_2 =
+  goog.getMsg("That\'s all we know");