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.
Common errors
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.
Warnings
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.
Install
npm install prettier-plugin-space-before-function-paren yarn add prettier-plugin-space-before-function-paren pnpm add prettier-plugin-space-before-function-paren Imports
- space-before-function-paren (plugin) wrong
"plugins": ["prettier-plugin-space-before-function-paren"] // Omitting from plugins array: plugin won't applycorrect// In prettier config "plugins": ["prettier-plugin-space-before-function-paren"] - Plugin as ES module (for programmatic use) wrong
const plugin = require('prettier-plugin-space-before-function-paren');correctimport plugin from 'prettier-plugin-space-before-function-paren'; await prettier.format(code, { plugins: [plugin], parser: 'babel' }); - Type import (TypeScript) wrong
import plugin from 'prettier-plugin-space-before-function-paren'; // TypeScript may not resolve typescorrectimport type { Plugin } from 'prettier'; const plugin: Plugin = require('prettier-plugin-space-before-function-paren');
Quickstart
// 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 () {}