prettier-plugin-brace-style

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

A Prettier plugin that applies ESLint's brace-style rules (1tbs, stroustrup, allman) to code formatting. Current stable version is 0.10.1, released on 2025-04-02. It supports JavaScript, TypeScript, JSX, TSX, Flow, CSS, SCSS, Less, Vue, Svelte, Angular, and HTML via Prettier's parsers. It requires Prettier >=3 and Node >=18. Key differentiators: directly enforces brace style as a Prettier plugin, works across multiple languages, and can be combined with other plugins using prettier-plugin-merge. It uses @prettier/plugin-oxc for oxc parser support, and optionally integrates with prettier-plugin-astro and prettier-plugin-svelte for those frameworks.

error Cannot find module 'prettier-plugin-brace-style'
cause The plugin is not installed or not in node_modules.
fix
Run: npm install -D prettier-plugin-brace-style (or yarn add --dev prettier-plugin-brace-style)
error Error: The "braceStyle" option is not supported by Prettier
cause The plugin is not loaded because it is not listed in the plugins array.
fix
Add 'prettier-plugin-brace-style' to the plugins array in your Prettier config: { plugins: ['prettier-plugin-brace-style'] }
error TypeError: Cannot read properties of undefined (reading 'name')
cause A transition from Prettier v2 to v3 or a misconfiguration with other plugins.
fix
Ensure Prettier >=3 is installed. If the issue persists, check that the plugin is listed after other conflicting plugins in the plugins array.
error Error: [prettier-plugin-brace-style] Unsupported parser for file
cause The file uses a language/parser not supported by the plugin.
fix
Check supported parsers: babel, typescript, flow, espree, meriyah, css (including SCSS/Less), vue, svelte, angular, html, or use overrides to exclude unsupported files.
breaking Version 0.8.0 dropped support for Prettier v2 and Node <18. If you are on Prettier v2 or Node 16, upgrading will break your setup.
fix Upgrade to Prettier >=3.0.0 and Node >=18. For legacy projects, stay on v0.7.x (which supports Prettier v2).
deprecated For versions <0.5.0, you needed to install @prettier/sync as a dependency. This is no longer required.
fix If using v0.4.x or earlier, remove @prettier/sync and upgrade the plugin. Or better, upgrade to the latest version.
gotcha If multiple Prettier plugins handle the same file type, only the last plugin in the plugins array is used. This can cause brace style not to be applied if another plugin takes precedence.
fix Add 'prettier-plugin-merge' as the last plugin in the list to apply plugins sequentially. See the README for an example.
gotcha Markdown and MDX files are not supported by this plugin, but it may still affect code blocks inside them if a supported language is detected. This can cause unintended formatting.
fix Use Prettier overrides to disable the plugin for Markdown and MDX files, as shown in the README.
gotcha The plugin relies on @prettier/plugin-oxc as an optional peer dependency for oxc parser support. If not installed, it may fall back to a slower parser or produce different results.
fix Install @prettier/plugin-oxc to ensure optimal performance and consistency: npm install -D @prettier/plugin-oxc
gotcha When using the plugin with TypeScript, the enum syntax is only fully supported with Prettier >=3.6.
fix If using enum declarations, ensure Prettier is updated to v3.6 or later.
npm install prettier-plugin-brace-style
yarn add prettier-plugin-brace-style
pnpm add prettier-plugin-brace-style

Demonstrates installation, configuration with braceStyle option, and formatting a JavaScript file. Shows how the plugin transforms code to the 'stroustrup' style.

// 1. Install:
// npm install -D prettier prettier-plugin-brace-style

// 2. Create .prettierrc.cjs (CommonJS):
module.exports = {
  plugins: ['prettier-plugin-brace-style'],
  braceStyle: 'stroustrup'  // Options: '1tbs' (default), 'stroustrup', 'allman'
};

// 3. Create test.js:
function foo() {
  if (condition) {
    console.log('hello');
  } else {
    console.log('world');
  }
}

// 4. Run: npx prettier --write test.js
// Output with 'stroustrup':
// function foo() {
//   if (condition) {
//     console.log('hello');
//   }
//   else {
//     console.log('world');
//   }
// }