prettier-elastic

raw JSON →
3.2.5 verified Sat Apr 25 auth: no javascript

A fork of Prettier (v3.2.5) that customizes formatting for `var`, `let`, and `const` declarations by aligning variable names in multi-declaration statements. It provides an alternative style where commas appear at the start of continuation lines, aligning values vertically. The package supports all Prettier languages (JavaScript, TypeScript, CSS, HTML, etc.) and is maintained by medikoo. It tracks upstream Prettier releases and includes TypeScript type definitions. Key differentiator: solves dissatisfaction with Prettier's default declaration alignment, offering a more tabular format without plugins.

error Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'prettier-elastic'
cause Package not installed or wrong import path in ESM.
fix
Run: npm install prettier-elastic. Then import correctly: import { format } from 'prettier-elastic'.
error TypeError: prettier.format is not a function
cause Using default import incorrectly in CommonJS.
fix
Use: const prettier = require('prettier-elastic'); correctly exports format as a method.
error SyntaxError: Unexpected token 'export'
cause Using ESM import in a CommonJS file without 'type': 'module'.
fix
Add 'type': 'module' to package.json, or use require() syntax.
error Error: Cannot find module './parser-babel'
cause Plugin resolution issue; likely missing parser dependencies.
fix
Ensure @babel/parser is installed, or use parser: 'babel' which is built-in.
breaking This is a fork with different output than standard Prettier for var/let/const multi-declarations.
fix Do not use this if standard Prettier behavior is required. Alternatively, use 'prettier' package and configure plugins.
deprecated Deprecated '--use-tabs' option may behave differently; prefer 'tabWidth' and 'useTabs' config.
fix Use 'tabWidth' and 'useTabs' in your prettier config instead of --use-tabs.
gotcha The package name is 'prettier-elastic', not 'prettier'. Installing the wrong package will not give the custom formatting.
fix Run: npm install prettier-elastic and import from 'prettier-elastic'.
gotcha Version numbers do not necessarily match upstream Prettier; check changelog for exact mapping.
fix Verify behavior against expected Prettier version via tests.
npm install prettier-elastic
yarn add prettier-elastic
pnpm add prettier-elastic

Demonstrates the core formatting difference: var declarations with aligned equals and comma-first line continuation.

import { format } from 'prettier-elastic';

const code = `var eloBar = require("elo-bar"),
  foo = require("foo"),
  otherThing = require("other-thing");`;

const formatted = format(code, { parser: 'babel' });
console.log(formatted);
// Output:
// var eloBar     = require("elo-bar")
//   , foo        = require("foo")
//   , otherThing = require("other-thing");