Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-3723

Trailing commas should be used

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Add a trailing comma to this item of the list.
    • Highlighting:
      Hide

      foo: "bar"

      Show
      foo: "bar"
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Targeted languages:
      Python
    • Covered Languages:
      JavaScript
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      2min
    • Analysis Scope:
      Main Sources, Test Sources
    • ESLint:
      comma-dangle

      Description

      Modern browsers ignore unneeded, trailing commas, so there are no negatives to having them unless you're supporting an IE 8 application. Since they make adding new properties simpler, their use is preferred. This rule raises an issue when the last item in an object declaration or array declaration does not end with a trailing comma and does not lie on the same line as the closing curly brace or bracket.

      Noncompliant Code Example

      var joe = { 
        fname: "Joe",  
        lname: "Smith"      // Noncompliant
      };
      

      Compliant Solution

      var joe = {  
        fname: "Joe",
        lname: "Smith",    // OK
      };
      
      var joe = {  
        fname: "Joe",
        lname: "Smith"};   // OK
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ann.campbell.2 Ann Campbell
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: