Prettier Plugin Space Before Function Paren

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

A Prettier plugin that adds a space before function parentheses for function definitions (not function calls) in JavaScript and TypeScript. Current stable version 0.1.0, released as a proof of concept. Release cadence: irregular, early stage. Differentiator: unlike Prettier's deprecated space-before-function-paren option, this plugin works with Prettier 3.0.0+ and only targets definitions, not calls. Requires Prettier >=3.0.0 as a peer dependency.

error Error: Cannot find module 'prettier-plugin-space-before-function-paren'
cause Plugin not installed or not in node_modules.
fix
Run 'npm install -D prettier prettier-plugin-space-before-function-paren'
error error: Couldn't resolve plugin "prettier-plugin-space-before-function-paren". The plugin is probably not installed or is incompatible with Prettier version.
cause Prettier version <3.0.0 or plugin not in config correctly.
fix
Update Prettier to >=3.0.0 and ensure plugin is in plugins array.
error TypeError: prettier.resolveConfig is not a function or its return value is not iterable
cause CommonJS require of plugin in Prettier 3 ESM context.
fix
Use ES module syntax (import) or ensure Prettier is running in ESM mode.
breaking Plugin requires Prettier 3.0.0 or later. Older versions will fail to load the plugin.
fix Upgrade Prettier to >=3.0.0
gotcha Plugin is a proof of concept; may not cover all edge cases (e.g., async functions, generators, TypeScript).
fix Test thoroughly with your codebase. Report issues on GitHub.
gotcha Plugin does not affect function calls, only function definitions. Misconfiguration may lead to inconsistent formatting if expectations differ.
fix Use Prettier's space-before-function-paren option (deprecated) for function calls if needed, but note incompatibility.
gotcha When used alongside other JS/TS Prettier plugins, they may conflict. Use prettier-plugin-merge to preserve changes.
fix Install prettier-plugin-merge and add it to the end of your plugins array.
deprecated Prettier's built-in space-before-function-paren option is deprecated in Prettier 3. This plugin is a replacement specifically for function definitions.
fix Use this plugin or remove the deprecated option entirely.
npm install prettier-plugin-space-before-function-paren
yarn add prettier-plugin-space-before-function-paren
pnpm add prettier-plugin-space-before-function-paren

Shows installation, config, and formatting: adds space before function paren in definitions only.

// 1. Install
// npm install -D prettier prettier-plugin-space-before-function-paren

// 2. Configure .prettierrc
{
  "plugins": ["prettier-plugin-space-before-function-paren"]
}

// 3. Input file (input.js)
function foo() {}

// 4. Format with Prettier
// npx prettier --write input.js

// 5. Output (input.js)
function foo () {}