leo-buneev / eslint-plugin-sort-keys-fix

Fork of https://eslint.org/docs/rules/sort-keys that allows automatic fixing
97 stars 23 forks source link

Preserve comment attachment to a given line #2

Open cjb opened 5 years ago

cjb commented 5 years ago

It's common to use eslint declarations that apply to the next line. Before:

{
  foo: 1,
  // eslint-disable-next-line some-rule
  bar: 2,
}

But sort-keys-fix will attach the comment to a different line. After:

{
  bar: 2,
  // eslint-disable-next-line some-rule
  foo: 1,
}

There's also another way that comments are detached from their target. Before:

{
  foo: 1, // foo should be 1
  bar: 2,
}

After:


{
  bar: 2, // foo should be 1
  foo: 1,
}
jpolo commented 5 years ago

IMHO the first case is not always explicit (is a comment attached to the next line or not ?) and therefore could be cause more harm than the problem. I was more impacted by the second which is pretty explicit : the action of sorting keys should actually sort lines attached to the keys.

entropitor commented 4 years ago

Is there any update on this? This is a super annoying bug.

pahan35 commented 4 years ago

I wasted nearly a day due to this bug.

I had next code

const babelJestTransformer = require('babel-jest')

module.exports = {
  shouldBabelize,
  ...babelJestTransformer,
  // otherwise we have some cache issues: files are not transpiled correctly
  createTransformer: undefined,
  process,
}

After applying the fix I got next

const babelJestTransformer = require('babel-jest')

module.exports = {
  createTransformer: undefined,
  ...babelJestTransformer,
  // otherwise we have some cache issues: files are not transpiled correctly
  process,
  shouldBabelize,
}

and I was wondering why it stopped working. Actually, this file was written by my teammate and I understood the reason only when I compared this file with source branch.

Please don't underestimate this bug.

Also, there is another problem: props, split by rest operator, shouldn't mix up. If there is no such issue, I'll prepare a new one

vikas-bansal-DisneyPH commented 4 years ago

this bug still exists https://github.com/leo-buneev/eslint-plugin-sort-keys-fix/issues/22

namnm commented 3 years ago

I fixed this in my fork and also some other critical bugs as well. Look like this repo is not in maintenance anymore, if anyone still interested in this sort keys plugin please try mine: https://github.com/namnm/eslint-plugin-sort-keys

Install: eslint-plugin-sort-keys Rule: sort-keys/sort-keys-fix