JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 81
  • Score
    100M100P100Q69534F
  • License MIT

A Prettier plugin for inserting missing commas in multi-line objects.

Package Exports

  • prettier-plugin-insert-comma
  • prettier-plugin-insert-comma/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (prettier-plugin-insert-comma) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

prettier-plugin-insert-comma

A Prettier plugin that automatically inserts missing commas in multi-line object properties before formatting.

Prettier cannot format code with syntax errors like missing commas in objects. This plugin runs as a preprocessor to insert commas between properties, allowing Prettier to format your code successfully.

Requirements

  • Prettier 3.7.0 or higher

Example

Before — Prettier would throw a parse error:

const config = {
  host: 'localhost'
  port: 3000
  options: {
    debug: true
    verbose: false
  }
}

After — commas are inserted, Prettier formats normally:

const config = {
  host: 'localhost',
  port: 3000,
  options: {
    debug: true,
    verbose: false,
  },
};

Installation

Install prettier-plugin-insert-comma as a dev dependency:

npm install -D prettier prettier-plugin-insert-comma

Then add the plugin to your Prettier configuration:

// .prettierrc
{
  "plugins": ["prettier-plugin-insert-comma"],
}

For JSON files, you need to specify the parser explicitly with overrides:

{
  "plugins": ["prettier-plugin-insert-comma"],
  "overrides": [
    {
      "files": ["*.json"],
      "options": {
        "parser": "json",
        "quoteProps": "preserve",
        "singleQuote": false,
        "trailingComma": "none"
      }
    }
  ]
}

Supported Languages

Language
TypeScript, TSX
JavaScript, JSX
JSON