prettier-plugin-compactify
raw JSON → 0.1.6 verified Sat Apr 25 auth: no javascript
A Prettier plugin that preprocesses JavaScript/TypeScript code to collapse object literals into compact single-line formatting. Version 0.1.6, actively maintained but early-stage. Unlike other Prettier plugins, it hooks into the parsing stage to enforce compact object notation, addressing a long-standing Prettier issue with unwanted newlines after opening braces. Requires Prettier >=2.x.
Common errors
error Error: Cannot find module 'prettier-plugin-compactify' ↓
cause Module not installed or Prettier cannot resolve it.
fix
Ensure prettier-plugin-compactify is installed as a devDependency and Prettier config is correct.
error TypeError: Cannot read properties of undefined (reading 'someProperty') ↓
cause Plugin might not be compatible with the installed Prettier version.
fix
Check Prettier version (>=2.x) and reinstall plugin.
Warnings
gotcha Plugin modifies formatting before Prettier runs; complex nested objects may be incorrectly collapsed. ↓
fix Review output manually for unexpected formatting; consider disabling for specific files via // prettier-ignore
breaking Requires Prettier >=2.0; not compatible with Prettier 1.x. ↓
fix Upgrade Prettier to version 2 or later.
gotcha Plugin does not support ESM imports; use CommonJS require or string plugin name. ↓
fix Configure plugins array in .prettierrc with the package name string instead of an import.
Install
npm install prettier-plugin-compactify yarn add prettier-plugin-compactify pnpm add prettier-plugin-compactify Imports
- default wrong
import plugin from 'prettier-plugin-compactify'correctmodule.exports = require('prettier-plugin-compactify')
Quickstart
// Install
npm install --save-dev prettier prettier-plugin-compactify
// .prettierrc
{
"plugins": ["prettier-plugin-compactify"]
}
// Input file test.js
const obj = {
foo: "bar"
}
// Run prettier
npx prettier --write test.js
// Output: const obj = { foo: "bar" }