From ea4ec7f2778f12404745c4f2e2ebdba0820647b7 Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Mon, 8 Mar 2021 13:42:24 -0500 Subject: [PATCH 1/6] prettierx: fix balanced ternary formatting, with a simpler solultion --- src/language-js/printer-estree.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index 072c293982..a4277a91a7 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -433,7 +433,7 @@ function printTernaryOperator(path, options, print, operatorOptions) { ? ifBreak("", concat(["(", parenSpace])) : "", // [prettierx] offsetTernaryExpressions option support: - !options.offsetTernaryExpressions + true // !options.offsetTernaryExpressions ? align(2, path.call(print, operatorOptions.consequentNodePropertyName)) : path.call(print, operatorOptions.consequentNodePropertyName), // [prettierx] spaceInParens option support (...) @@ -443,7 +443,8 @@ function printTernaryOperator(path, options, print, operatorOptions) { line, ": ", // [prettierx] offsetTernaryExpressions option support: - options.offsetTernaryExpressions || + // options.offsetTernaryExpressions || + !options.offsetTernaryExpressions && alternateNode.type === operatorOptions.conditionalNodeType ? path.call(print, operatorOptions.alternateNodePropertyName) : align(2, path.call(print, operatorOptions.alternateNodePropertyName)), @@ -454,7 +455,7 @@ function printTernaryOperator(path, options, print, operatorOptions) { parent[operatorOptions.alternateNodePropertyName] === node || isParentTest ? part - : options.useTabs || options.offsetTernaryExpressions // [prettierx] offsetTernaryExpressions option support (...) + : options.useTabs //|| options.offsetTernaryExpressions // [prettierx] offsetTernaryExpressions option support (...) ? dedent(indent(part)) : align(Math.max(0, options.tabWidth - 2), part) ); @@ -463,7 +464,7 @@ function printTernaryOperator(path, options, print, operatorOptions) { // Indent the whole ternary if offsetTernaryExpressions is enabled // (like ESLint). if (options.offsetTernaryExpressions) { - forceNoIndent = false; + // forceNoIndent = false; } } From a141e49c7824ffac2713e545038b54615287ae8a Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Wed, 23 Jun 2021 13:30:25 -0400 Subject: [PATCH 2/6] update existing docs with reference to brodybits/prettierx issue 552 in ternary formatting with objects & tabs ref: - https://github.com/brodybits/prettierx/issues/552 --- README.md | 2 +- docs/options.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 60d216cd89..b31e10bd1d 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ prettierx ## Additional prettierX options - `--align-object-properties` (`alignObjectProperties: true`): Align colons in multiline object literals (not applied with any of the JSON parsers). -- `--offset-ternary-expressions` (`offsetTernaryExpressions: true`): Indent and align ternary expression branches more consistently with "Standard JS" (similar to the corresponding eslint option). +- `--offset-ternary-expressions` (`offsetTernaryExpressions: true`): Indent and align ternary expression branches more consistently with "Standard JS" (similar to the corresponding eslint option). NOT recommended together with `--use-tabs` due to KNOWN ISSUE: [`brodybits/prettierx#552`](https://github.com/brodybits/prettierx/issues/552) - `--space-before-function-paren` (`spaceBeforeFunctionParen: true`): Put a space before function parenthesis in all declarations (similar to the corresponding eslint option). (Default is to put a space before function parenthesis for untyped anonymous functions only.) - `--generator-star-spacing` (`generatorStarSpacing: true`): Put spaces around the star (`*`) in generator functions (before and after - similar to the corresponding eslint option). (Default is after only.) - `--yield-star-spacing` (`yieldStarSpacing: true`): Put spaces around the star (`*`) in `yield*` expressions (before and after - similar to the corresponding eslint option). (Default is after only.) diff --git a/docs/options.md b/docs/options.md index 098654d8d9..53db3b5fe3 100644 --- a/docs/options.md +++ b/docs/options.md @@ -298,7 +298,7 @@ Put spaces between computed property brackets (similar to the corresponding esli ## Offset ternary expressions -Indent and align ternary expression branches more consistently with "Standard JS" (similar to the corresponding eslint option). +Indent and align ternary expression branches more consistently with "Standard JS" (similar to the corresponding eslint option). NOT recommended together with `--use-tabs` due to KNOWN ISSUE: [`brodybits/prettierx#552`](https://github.com/brodybits/prettierx/issues/552) | Default | CLI Override | API Override | | ------- | ------------------------------ | ---------------------------------- | From 8fef2ec55d970918e78eb25c63e20cd602bc34ce Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Wed, 23 Jun 2021 13:39:30 -0400 Subject: [PATCH 3/6] update test snapshots in tests/ternaries/with-balanced-formatting (...) add commit notes: The changes from these updates close #492 (brodybits/prettierx PR #492). add footer: BREAKING CHANGE --- .../__snapshots__/jsfmt.spec.js.snap | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/tests/ternary-object-expressions/with-balanced-formatting/__snapshots__/jsfmt.spec.js.snap b/tests/ternary-object-expressions/with-balanced-formatting/__snapshots__/jsfmt.spec.js.snap index 4946dbcd70..852e80b6dd 100644 --- a/tests/ternary-object-expressions/with-balanced-formatting/__snapshots__/jsfmt.spec.js.snap +++ b/tests/ternary-object-expressions/with-balanced-formatting/__snapshots__/jsfmt.spec.js.snap @@ -24,13 +24,13 @@ let isSpace = false; const dress = isSpace ? { - spaceSuit: 3, - oxygenCylinders: 6 - } + spaceSuit: 3, + oxygenCylinders: 6 + } : { - shirts: 3, - paints: 3 - }; + shirts: 3, + paints: 3 + }; ================================================================================ `; @@ -60,13 +60,13 @@ let isSpace = false; const dress = isSpace ? { - spaceSuit: 3, - oxygenCylinders: 6 - } + spaceSuit: 3, + oxygenCylinders: 6 + } : { - shirts: 3, - paints: 3 - }; + shirts: 3, + paints: 3 + }; ================================================================================ `; @@ -96,13 +96,13 @@ let isSpace = false; const dress = isSpace ? { - spaceSuit: 3, - oxygenCylinders: 6 - } + spaceSuit: 3, + oxygenCylinders: 6 + } : { - shirts: 3, - paints: 3 - }; + shirts: 3, + paints: 3 + }; ================================================================================ `; @@ -133,13 +133,13 @@ let isSpace = false; const dress = isSpace ? { - spaceSuit: 3, - oxygenCylinders: 6 - } + spaceSuit: 3, + oxygenCylinders: 6 + } : { - shirts: 3, - paints: 3 - }; + shirts: 3, + paints: 3 + }; ================================================================================ `; @@ -224,8 +224,8 @@ function test1() { ? Promise(1) : Promise(2) : condition3 - ? Promise(3) - : Promise(4); + ? Promise(3) + : Promise(4); } ================================================================================ @@ -268,8 +268,8 @@ function test1() { ? Promise(1) : Promise(2) : condition3 - ? Promise(3) - : Promise(4); + ? Promise(3) + : Promise(4); } ================================================================================ @@ -313,8 +313,8 @@ function test1() { ? Promise(1) : Promise(2) : condition3 - ? Promise(3) - : Promise(4); + ? Promise(3) + : Promise(4); } ================================================================================ From 9c88a286f76cffe6fa21dbf42e2e9f1c663ca997 Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Wed, 23 Jun 2021 13:44:34 -0400 Subject: [PATCH 4/6] add note: resolved #468 (brodybits/prettierx issue #468) From d00e6b5fe514edc5b4c8ce916062415f863d598d Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Wed, 23 Jun 2021 20:12:25 -0400 Subject: [PATCH 5/6] prettierx chore: set version to 0.19.0-dev --- CHANGELOG.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dba827485..d4288348f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ To get recent changes on prettier (TBD prettier/prettier) in a nice format: $ git log --pretty=format:"- %s" rev1..rev2 | sed 's/#\([0-9]*\)/\[prettier\/prettier#\1\]\(https:\/\/github.com\/prettier\/prettier\/pull\/\1\)/' -- --> -## prettierx 0.18.3-dev +## prettierx 0.19.0-dev [compare prettierx-0.18.2...dev](https://github.com/brodybits/prettierx/compare/prettierx-0.18.2...dev) diff --git a/package.json b/package.json index aab66c541a..06dacde757 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "prettierx", - "version": "0.18.3-dev", + "version": "0.19.0-dev", "description": "prettierx - less opinionated code formatter fork of prettier", "bin": "./bin/prettierx.js", "repository": "brodybits/prettierx", From 03a79c68d134ba33f7dd2223df0c9514dd49ff74 Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Wed, 23 Jun 2021 20:38:17 -0400 Subject: [PATCH 6/6] revert simpler solution & test updates for now, at least, with some commit notes below (...) * Revert "prettierx: fix balanced ternary formatting, with a simpler solultion" This reverts commit ea4ec7f2778f12404745c4f2e2ebdba0820647b7. * Revert "update test snapshots in tests/ternaries/with-balanced-formatting (...)" This reverts commit 8fef2ec55d970918e78eb25c63e20cd602bc34ce. ADDING COMMIT NOTES: The following statements for GitHub should not be considered valid at this point: > The changes from these updates close [issue number] 492 (brodybits/prettierx PR [number] 492). > resolved [sic] [issue number] 468 (brodybits/prettierx issue [number] 468) Some more testing & consideration is needed before moving forward with a solution in this or another PR. --- src/language-js/printer-estree.js | 9 ++- .../__snapshots__/jsfmt.spec.js.snap | 60 +++++++++---------- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index a4277a91a7..072c293982 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -433,7 +433,7 @@ function printTernaryOperator(path, options, print, operatorOptions) { ? ifBreak("", concat(["(", parenSpace])) : "", // [prettierx] offsetTernaryExpressions option support: - true // !options.offsetTernaryExpressions + !options.offsetTernaryExpressions ? align(2, path.call(print, operatorOptions.consequentNodePropertyName)) : path.call(print, operatorOptions.consequentNodePropertyName), // [prettierx] spaceInParens option support (...) @@ -443,8 +443,7 @@ function printTernaryOperator(path, options, print, operatorOptions) { line, ": ", // [prettierx] offsetTernaryExpressions option support: - // options.offsetTernaryExpressions || - !options.offsetTernaryExpressions && + options.offsetTernaryExpressions || alternateNode.type === operatorOptions.conditionalNodeType ? path.call(print, operatorOptions.alternateNodePropertyName) : align(2, path.call(print, operatorOptions.alternateNodePropertyName)), @@ -455,7 +454,7 @@ function printTernaryOperator(path, options, print, operatorOptions) { parent[operatorOptions.alternateNodePropertyName] === node || isParentTest ? part - : options.useTabs //|| options.offsetTernaryExpressions // [prettierx] offsetTernaryExpressions option support (...) + : options.useTabs || options.offsetTernaryExpressions // [prettierx] offsetTernaryExpressions option support (...) ? dedent(indent(part)) : align(Math.max(0, options.tabWidth - 2), part) ); @@ -464,7 +463,7 @@ function printTernaryOperator(path, options, print, operatorOptions) { // Indent the whole ternary if offsetTernaryExpressions is enabled // (like ESLint). if (options.offsetTernaryExpressions) { - // forceNoIndent = false; + forceNoIndent = false; } } diff --git a/tests/ternary-object-expressions/with-balanced-formatting/__snapshots__/jsfmt.spec.js.snap b/tests/ternary-object-expressions/with-balanced-formatting/__snapshots__/jsfmt.spec.js.snap index a365a29949..11392b813b 100644 --- a/tests/ternary-object-expressions/with-balanced-formatting/__snapshots__/jsfmt.spec.js.snap +++ b/tests/ternary-object-expressions/with-balanced-formatting/__snapshots__/jsfmt.spec.js.snap @@ -24,13 +24,13 @@ let isSpace = false; const dress = isSpace ? { - spaceSuit: 3, - oxygenCylinders: 6 - } + spaceSuit: 3, + oxygenCylinders: 6 + } : { - shirts: 3, - paints: 3 - }; + shirts: 3, + paints: 3 + }; ================================================================================ `; @@ -60,13 +60,13 @@ let isSpace = false; const dress = isSpace ? { - spaceSuit: 3, - oxygenCylinders: 6 - } + spaceSuit: 3, + oxygenCylinders: 6 + } : { - shirts: 3, - paints: 3 - }; + shirts: 3, + paints: 3 + }; ================================================================================ `; @@ -96,13 +96,13 @@ let isSpace = false; const dress = isSpace ? { - spaceSuit: 3, - oxygenCylinders: 6 - } + spaceSuit: 3, + oxygenCylinders: 6 + } : { - shirts: 3, - paints: 3 - }; + shirts: 3, + paints: 3 + }; ================================================================================ `; @@ -133,13 +133,13 @@ let isSpace = false; const dress = isSpace ? { - spaceSuit: 3, - oxygenCylinders: 6 - } + spaceSuit: 3, + oxygenCylinders: 6 + } : { - shirts: 3, - paints: 3 - }; + shirts: 3, + paints: 3 + }; ================================================================================ `; @@ -224,8 +224,8 @@ function test1() { ? Promise(1) : Promise(2) : condition3 - ? Promise(3) - : Promise(4); + ? Promise(3) + : Promise(4); } ================================================================================ @@ -268,8 +268,8 @@ function test1() { ? Promise(1) : Promise(2) : condition3 - ? Promise(3) - : Promise(4); + ? Promise(3) + : Promise(4); } ================================================================================ @@ -313,8 +313,8 @@ function test1() { ? Promise(1) : Promise(2) : condition3 - ? Promise(3) - : Promise(4); + ? Promise(3) + : Promise(4); } ================================================================================