A Prettier plugin for formatting PEG.js and Peggy grammar files. v2.0.2 is the latest stable, requires Node >= 16 and ships TypeScript definitions. It supports standard Prettier options plus an 'actionParser' to format action code (JavaScript/TypeScript by default, configurable). Unlike generic formatters, it deeply understands PEG syntax, preserving code within actions. Available for browser via standalone bundle.
npm install prettier-plugin-pegjsVerified import paths — ran on the pinned version, not inferred.
Formats a PEG.js grammar string using Prettier with the plugin, demonstrating usage in a Node.js TypeScript environment.
Use .pegjs extension or set parser: 'pegjs' in Prettier config
Upgrade to Node 16+ and use ESM imports (import) or dynamic import()
Migrate to import syntax or upgrade to v2 (ESM only)
Set actionParser to appropriate parser (e.g., 'babel' for JavaScript without TypeScript)
Run 'npm install --save-dev prettier prettier-plugin-pegjs' or 'yarn add --dev prettier prettier-plugin-pegjs'.
Check the grammar against PEG.js specification; ensure initial rule is uppercase.
Use dynamic import: const prettier = await import('prettier'); or migrate to ESM.