Prettier intentionally avoids formatting styles that involve alignment for aesthetic purposes, such as aligning = signs or colons, because its philosophy emphasizes consistency over visual alignment, which can be fragile and harder to maintain.
However, there are other tools and workarounds that can achieve what you're asking for:
✅ Option 1: align-yaml or align-js via custom scripts These are not official tools, but small CLI scripts or packages that parse and align JavaScript objects or variable declarations.
You could write a simple script or use a small utility like:
cli-align
columnify
align-code (not well-maintained but a starting point)
✅ Option 2: Use ESLint with custom rule or plugin Some ESLint plugins support alignment features. For example:
eslint-plugin-align-import
eslint-plugin-sort-destructure-keys
But aligning = in variable declarations isn’t supported out of the box. You could:
Write a custom ESLint rule
Use eslint --fix with tailored rules to preprocess code, then reformat with Prettier
✅ Option 3: Editor Macros / Align Plugins For manual or semi-automated formatting:
VSCode:
Extension: "Align"
Shortcut: Select lines → Ctrl+Shift+P → "Align" → Choose =
Sublime Text:
Plugin: AlignTab or built-in Find > Replace using regex
✅ Option 4: Use ast-grep or code mods For power users, tools like ast-grep or jscodeshift let you match and rewrite code structurally — useful for automating style changes like aligning assignments