question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Conflict with standard in nested ternary expression

See original GitHub issue

Prettier 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:closed
  • Created 5 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
aMarCruzcommented, Feb 22, 2019

@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).

1reaction
brodybitscommented, Feb 20, 2019

Today I will finish a plugin for eslint+prettierx (with presets for Standard and Prettierx) that can be used with the VS-Code ESLint extension.

I will add a pointer if you publish it.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found