From 2a5b391cc05e0ed8e00285c0a8afb71bb776147c Mon Sep 17 00:00:00 2001 From: Scotty Jamison Date: Fri, 17 Feb 2023 20:14:18 -0700 Subject: [PATCH] Explain ASI issues aren't always auto-fixed (#14174) Co-authored-by: fisker Cheung --- docs/rationale.md | 18 ++++++++++++++++++ .../versioned_docs/version-stable/rationale.md | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/docs/rationale.md b/docs/rationale.md index 4df64fa24..569f0de6c 100644 --- a/docs/rationale.md +++ b/docs/rationale.md @@ -187,6 +187,24 @@ With a semicolon in front of that `[` such issues never happen. It makes the lin This practice is also common in [standard] which uses a semicolon-free style. +Note that if your program currently has a semicolon-related bug in it, Prettier _will not_ auto-fix the bug for you. Remember, Prettier only reformats code, it does not change the behavior of the code. Take this buggy piece of code as an example, where the developer forgot to place a semicolon before the `(`: + + +```js +console.log('Running a background task') +(async () => { + await doBackgroundWork() +})() +``` + +If you feed this into Prettier, it will not alter the behavior of this code, instead, it will reformat it in a way that shows how this code will actually behave when ran. + +```js +console.log("Running a background task")(async () => { + await doBackgroundWork(); +})(); +``` + [standard]: https://standardjs.com/rules.html#semicolons ### Print width diff --git a/website/versioned_docs/version-stable/rationale.md b/website/versioned_docs/version-stable/rationale.md index d5c272669..83967597e 100644 --- a/website/versioned_docs/version-stable/rationale.md +++ b/website/versioned_docs/version-stable/rationale.md @@ -188,6 +188,24 @@ With a semicolon in front of that `[` such issues never happen. It makes the lin This practice is also common in [standard] which uses a semicolon-free style. +Note that if your program currently has a semicolon-related bug in it, Prettier _will not_ auto-fix the bug for you. Remember, Prettier only reformats code, it does not change the behavior of the code. Take this buggy piece of code as an example, where the developer forgot to place a semicolon before the `(`: + + +```js +console.log('Running a background task') +(async () => { + await doBackgroundWork() +})() +``` + +If you feed this into Prettier, it will not alter the behavior of this code, instead, it will reformat it in a way that shows how this code will actually behave when ran. + +```js +console.log("Running a background task")(async () => { + await doBackgroundWork(); +})(); +``` + [standard]: https://standardjs.com/rules.html#semicolons ### Print width