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

Do not mix up props before and after spread operator #15

Closed pahan35 closed 4 years ago

pahan35 commented 4 years ago

Relates to #3

Versions

eslint-plugin-sort-keys-fix: 1.1.0 Node.js: 13.7.0

Dependencies

npm i -D babel-eslint eslint eslint-plugin-sort-keys-fix

.eslintrc

{
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 8,
    "sourceType": "module",
  },
  "plugins": [
    "sort-keys-fix"
  ],
  "env": {
      "browser": true,
      "es6": true,
    },
  "rules": {
    "sort-keys-fix/sort-keys-fix": "error"
  }
}

Code to reproduce

var z = {}
var obj = {b:1, ...z, a:1}

Expected

No violations

Actual

ESLint: Expected object keys to be in ascending order. 'a' should be before 'b'.(sort-keys-fix/sort-keys-fix)

image

Motivation

It's problematic in cases where we want to allow overriding some in the target object

function foo(overridings) {
  const target = {b: 7, ...overridings, a: 5}
}

Also, current behavior causes bugs like described in https://github.com/leo-buneev/eslint-plugin-sort-keys-fix/issues/2#issuecomment-615877695

leo-buneev commented 4 years ago

Thx @pahan35 . Released in 1.1.1.