check-dependency-version-consistency icon indicating copy to clipboard operation
check-dependency-version-consistency copied to clipboard

Autofix can lose package.json comments

Open bmish opened this issue 1 year ago • 0 comments

Values for duplicate object keys as seen in package.json comments are lost during autofix.

Before an autofix to package.json:

{
  "dependencies": {
    "//": "comment about foo",
    "foo": "^1.2.3",
    "//": "comment about bar",
    "bar": "^4.5.6",
    "//": "comment about baz",
    "baz": "^7.8.9",
  }
}

After an autofix to the file:

{
  "dependencies": {
    "//": "comment about baz",
    "foo": "^1.2.3",
    "bar": "^4.5.6",
    "baz": "^7.8.9",
  }
}

We use edit-json-file to actual edit the file. It likely serializes/deserializes the file into an object which doesn't support duplicate keys.

Until https://github.com/IonicaBizau/edit-json-file/issues/59 is fixed, we should disable autofix in places where comments will be lost.

bmish avatar Sep 26 '22 15:09 bmish