prettier-plugin-insert-comma
v1.1.7
Published
A Prettier plugin for inserting missing commas in multi-line objects.
Maintainers
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-commaThen 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 |
