Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Can we autosort object keys by length when order DOES NOT matter? #27

Open
brian-mann opened this issue Aug 21, 2019 · 2 comments
Open

Comments

@brian-mann
Copy link
Member

Given an object looking like this...

Screenshot 2019-08-21 13 30 08

When order does not matter

Could we autosort the keys to be grouped into two groups...

  1. shorthand properties
  2. regular key/value properties

And then subsequently short by the length of the key for both groups?

So it would subsequently restructure the object to look like...

cy
.task('record:fast_visit_spec', {
  url,
  percentiles,
  browser: Cypress.config('browser').name
})

If an object has both the key/value then we'd also ignore the length of the value and only use key.length.

Example:

cy
.task('record:fast_visit_spec', {
  url,
  percentiles,
  foo: 'a really long string that's longer than the following value',
  browser: Cypress.config('browser').name
})

When order matters

If order matters, such as when using the spread operator syntax, then avoid sorting...

Example:

const obj = {
  ...veryLongObject,
  ...shortObj,
  foo, // this does not get sorted above the others...
  quux, // but this gets sorted
  lorem, // and this gets sorted
}
@jennifer-shehane
Copy link
Member

I have strong feelings about this. I would prefer alphabetical

cy
.task('record:fast_visit_spec', {
  browser: Cypress.config('browser').name,
  foo: 'a really long string that's longer than the following value',
  percentiles,
  url
})

@kuceb
Copy link
Contributor

kuceb commented Oct 16, 2019

and you say prettier is too opinionated?

Lets say I have the following code:

const myfuncs = {
  baz: () => {
	...
	...
	...
	...
	...
	...
  },
  
  foo: () => {
   ...
   ...
   ...
   ...
   ...
   ...
  }
}

and I rename baz to getBaz

the diff would go from 1 line to possibly hundreds

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants