Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indentation/alignment within ternary branches (consequent/alternate) #927

Open
josephfrazier opened this issue Jun 21, 2017 · 3 comments

Comments

@josephfrazier
Copy link
Contributor

commented Jun 21, 2017

(extracted from #811 (comment))

Currently (commit 05595b5), standard formats the following code:

let options
const events = typeof options.trigger === 'string'
  ? options.trigger.split(' ').filter(trigger => {
      return ['click', 'hover', 'focus'].indexOf(trigger) !== -1
    })
  : []
console.log(events)

as:

let options
const events = typeof options.trigger === 'string'
  ? options.trigger.split(' ').filter(trigger => {
    return ['click', 'hover', 'focus'].indexOf(trigger) !== -1
  })
  : []
console.log(events)

That is, it unindents the function body and closing brace. Here's the diff:

diff --git a/p.js b/s.js
index c778a36e..0ccb242f 100644
--- a/p.js
+++ b/s.js
@@ -1,7 +1,7 @@
 let options
 const events = typeof options.trigger === 'string'
   ? options.trigger.split(' ').filter(trigger => {
-      return ['click', 'hover', 'focus'].indexOf(trigger) !== -1
-    })
+    return ['click', 'hover', 'focus'].indexOf(trigger) !== -1
+  })
   : []
 console.log(events)

If ESLint makes it possible (see eslint/eslint#6606 and eslint/eslint#7698), would it be acceptable to have standard use the original indentation in this case?

I might be able to hack together a way to test breakage by postprocessing standard's output with prettier-miscellaneous, which produces standard-formatted code with prettier --no-semi --single-quote --jsx-single-quote --space-before-function-paren (with the exception of this issue, as far as I know).

EDIT: This is similar to #521

@stale

This comment has been minimized.

Copy link

commented May 10, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale label May 10, 2018

@stale stale bot closed this May 17, 2018

@feross

This comment has been minimized.

Copy link
Member

commented May 20, 2018

I agree that we should auto-format to the former example. Re-opening and setting this as a goal for standard v12.

@feross feross added the bug label May 20, 2018

@feross feross reopened this May 20, 2018

@stale stale bot removed the stale label May 20, 2018

@feross feross added this to the standard v12 milestone May 20, 2018

@brodybits

This comment has been minimized.

Copy link
Contributor

commented Jan 22, 2019

This would definitely resolve an unfortunate consistency with Prettier (#811 (comment)).

Unfortunately both eslint/eslint#6606 and eslint/eslint#7698 reports are now "archived due to age".

I suspect the best solution would be for someone to make an eslint plugin, similar to the following:

@feross feross modified the milestones: standard v12, standard v14 Jul 5, 2019

@feross feross removed this from the standard v14 milestone Jul 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.