Search code examples
javascriptconventionsjshintreact-native

React Native - What's the point of leaving trailing comma everywhere?


While working with React Native I noticed some strange convention by its' contributors and in examples - to leave trailing comma everywhere, as an example:

What's the point?


Solution

  • Then when you perform diff only one line is changed.

    If you don't do that - 2 lines will be marked as changed.

    Technically you can put comma in the beginning of the line and change your style but it's (WARNING: hardly opinionated) ugly.

    If I remember correctly, it's valid to specify it when you destructure JS objects, but it's invalid to do so when you use it as a JS object literal (please correct me if I'm wrong).

    So this:

    var { foo, } = obj;
    

    is a valid ES6 code.

    And this:

    var o = { foo: 42, };
    

    is not a valid JS code.