Conflict with standard in nested ternary expression
See original GitHub issuePrettier 1.16.4 Playground link
--parser babylon
Input:
export const foo = function (r, isSpace) {
const type = /work|trabajo|empresa|negocio/i.test(r.Type)
? 't'
: /home|hogar|Personal|Particular|casa/i.test(r.Type)
? ''
: null
return type
}
Output:
export const foo = function(r, isSpace) {
const type = /work|trabajo|empresa|negocio/i.test(r.Type)
? "t"
: /home|hogar|Personal|Particular|casa/i.test(r.Type)
? ""
: null;
return type;
};
Expected behavior:
The Input must be preserved.
The ESLint indent
rule for StandardJS has flatTernaryExpressions: true
, as seen in enforce consistent indentation (indent).
@brodybits , thanks for your awesome fork!
Issue Analytics
- State:
- Created 5 years ago
- Comments:14 (14 by maintainers)
Top Results From Across the Web
Inconsistent formatting of nested ternary expressions · Issue #41
The core of this issue is that it's possible to configure prettierx to add extra indents to nested ternary expressions, but it also...
Read more >Javascript nested ternary operator - Stack Overflow
A nested ternary operator looks like this: something = condition ? nested_condition ? value_if_both_conditions_are_true ...
Read more >Ternary operators should not be nested - SonarSource Rules
Repeated patterns in regular expressions should not match the empty string ... Nesting ternary operators results in the kind of code that may...
Read more >Are chain ternary operators an antipattern? : r/reactjs - Reddit
The ternary operator produces an expression, which can be immediately assigned to a variable. As long as you're familiar with the daisy-chained ...
Read more >How to Use the JavaScript Nested Ternary Operator
Nested Ternary Operator in JavaScript. We can nest a ternary operator as an expression inside another ternary operator. We can use this to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@brodybits hi, the plugin is ready for testing: eslint-plugin-prettierx.
I am using it since yesterday in my current project and it seems to work without problems. Right now I’m testing it with eslint-config-standardized that is my personal config.
Maybe when I have the time will try to use prettierx as a postproccesor or with a custom parser to solve some issues related to ASI, comment directives, and other things (or send a PR to Prettier to fix these).
I will add a pointer if you publish it.