Skip to content

refirst11/prettier-plugin-insert-comma

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors