1

Because commas cannot be added to the last element of an object or an array in package.json, the line blame in not preserved; that is, if I have the following in package.json in commit A:

{
  "version": "0.0.1"
}

And then in commit B I add another field:

{
  "version": "0.0.1",
  "main": "index.js"
}

git blame package.json shows both lines being blamed by commit B. The blame would be preserved if I instead added a comma to the end of the first field definition in commit A:

{
  "version": "0.0.1",
}

But this isn't valid JSON, or at least it isn't allowed by npm. Doing this and then running npm install will raise this error:

npm ERR! install Couldn't read dependencies  
npm ERR! Failed to parse json 
npm ERR! Unexpected token } ...

Is there a way to get around the npm error? Or is there a clever way of using git blame to see that commit A should really be to blame for the first field?

Robz
  • 1,747
  • 5
  • 21
  • 35

1 Answers1

-1

In JS Object Notation (JSON) all object properties (name-value pair) are separated by ,.

So if you have only one property you don't need additional , at the end.

My point is that in commit B line "version": "0.0.1" was changed by adding ,. Blame is working fine. And in git this is a whole new different line that replaces previous one.

Rafał Warzycha
  • 561
  • 3
  • 18
  • Blame is NOT fine. It shows the version field having been modified by commit B, which is useless information – Robz Jan 20 '15 at 13:57