Rule: trailing-comma

Requires or disallows trailing commas in array and object literals, destructuring assignments, function typings, named imports and exports and function parameters.

Notes:
Has Fixer

Config

One argument which is an object with the keys multiline and singleline. Both can be set to a string ("always" or "never") or an object.

The object can contain any of the following keys: "arrays", "objects", "functions", "imports", "exports", and "typeLiterals"; each key can have one of the following values: "always", "never", and "ignore". Any missing keys will default to "ignore".

  • "multiline" checks multi-line object literals.
  • "singleline" checks single-line object literals.

An array is considered “multiline” if its closing bracket is on a line after the last array element. The same general logic is followed for object literals, function typings, named import statements and function parameters.

Examples
"trailing-comma": [true, {"multiline": "always", "singleline": "never"}]
"trailing-comma": [
  true,
  {
    "multiline": {
      "objects": "always",
      "arrays": "always",
      "functions": "never",
      "typeLiterals": "ignore"
    }
  }
]
Schema
{
  "type": "object",
  "properties": {
    "multiline": {
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "always",
            "never"
          ]
        },
        {
          "type": "object",
          "properties": {
            "arrays": {
              "type": "string",
              "enum": [
                "always",
                "never",
                "ignore"
              ]
            },
            "exports": {
              "type": "string",
              "enum": [
                "always",
                "never",
                "ignore"
              ]
            },
            "functions": {
              "type": "string",
              "enum": [
                "always",
                "never",
                "ignore"
              ]
            },
            "imports": {
              "type": "string",
              "enum": [
                "always",
                "never",
                "ignore"
              ]
            },
            "objects": {
              "type": "string",
              "enum": [
                "always",
                "never",
                "ignore"
              ]
            },
            "typeLiterals": {
              "type": "string",
              "enum": [
                "always",
                "never",
                "ignore"
              ]
            }
          }
        }
      ]
    },
    "singleline": {
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "always",
            "never"
          ]
        },
        {
          "type": "object",
          "properties": {
            "arrays": {
              "type": "string",
              "enum": [
                "always",
                "never",
                "ignore"
              ]
            },
            "exports": {
              "type": "string",
              "enum": [
                "always",
                "never",
                "ignore"
              ]
            },
            "functions": {
              "type": "string",
              "enum": [
                "always",
                "never",
                "ignore"
              ]
            },
            "imports": {
              "type": "string",
              "enum": [
                "always",
                "never",
                "ignore"
              ]
            },
            "objects": {
              "type": "string",
              "enum": [
                "always",
                "never",
                "ignore"
              ]
            },
            "typeLiterals": {
              "type": "string",
              "enum": [
                "always",
                "never",
                "ignore"
              ]
            }
          }
        }
      ]
    }
  },
  "additionalProperties": false
}