From 8ebda75fec49123e9578691d935f431aadfa8fda Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 21 May 2020 19:04:06 +0800 Subject: [PATCH] Fix unstable yaml print (#8355) --- changelog_unreleased/yaml/pr-8355.md | 34 ++++++++++++++++++++++++++++ src/language-yaml/printer-yaml.js | 7 +++--- tests_config/run_spec.js | 1 - 3 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 changelog_unreleased/yaml/pr-8355.md diff --git a/changelog_unreleased/yaml/pr-8355.md b/changelog_unreleased/yaml/pr-8355.md new file mode 100644 index 000000000..215b7d69d --- /dev/null +++ b/changelog_unreleased/yaml/pr-8355.md @@ -0,0 +1,34 @@ +#### Fix unstable format with `prettier-ignore` ([#8355](https://github.com/prettier/prettier/pull/8355) by [@fisker](https://github.com/fisker)) + + +```yaml +# Input +# prettier-ignore +--- +prettier: true +... +hello: world + +# Prettier stable +# prettier-ignore +--- +prettier: true +--- +hello: world + +# Prettier stable (Second format) +# prettier-ignore +--- +prettier: true + +--- +hello: world + +# Prettier master +# prettier-ignore +--- +prettier: true +--- +hello: world + +``` diff --git a/src/language-yaml/printer-yaml.js b/src/language-yaml/printer-yaml.js index 52f711a91..70f7ff43f 100644 --- a/src/language-yaml/printer-yaml.js +++ b/src/language-yaml/printer-yaml.js @@ -107,10 +107,9 @@ function genericPrint(path, options, print) { hasPrettierIgnore(path) ? concat( replaceEndOfLineWith( - options.originalText.slice( - node.position.start.offset, - node.position.end.offset - ), + options.originalText + .slice(node.position.start.offset, node.position.end.offset) + .trimEnd(), literalline ) ) diff --git a/tests_config/run_spec.js b/tests_config/run_spec.js index 2adb15aad..c2ac0cc7a 100644 --- a/tests_config/run_spec.js +++ b/tests_config/run_spec.js @@ -39,7 +39,6 @@ const unstableTests = new Map( (options) => options.proseWrap === "always", ], ["js/no-semi/comments.js", (options) => options.semi === false], - "yaml/prettier-ignore/document.yml", ].map((fixture) => { const [file, isUnstable = () => true] = Array.isArray(fixture) ? fixture