{"id":20400,"library":"prettier-plugin-pegjs","title":"prettier-plugin-pegjs","description":"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.","status":"active","version":"2.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/siefkenj/prettier-plugin-pegjs","tags":["javascript","pegjs","parser","prettier","typescript"],"install":[{"cmd":"npm install prettier-plugin-pegjs","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-pegjs","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-pegjs","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency, plugin requires Prettier to be installed","package":"prettier","optional":false}],"imports":[{"note":"Package is ESM-only. Use dynamic import() for CommonJS projects.","wrong":"const prettierPluginPegjs = require('prettier-plugin-pegjs')","symbol":"default","correct":"import prettierPluginPegjs from 'prettier-plugin-pegjs'"},{"note":"printPrettier is exported from the standalone subpath. Direct import from main entry only exports the Prettier plugin object.","wrong":"import { printPrettier } from 'prettier-plugin-pegjs'","symbol":"printPrettier","correct":"import { printPrettier } from 'prettier-plugin-pegjs/standalone'"},{"note":"TypeScript type export; only available for type imports in CJS.","wrong":"const PegjsParser = require('prettier-plugin-pegjs').PegjsParser","symbol":"PegjsParser","correct":"import { PegjsParser } from 'prettier-plugin-pegjs'"}],"quickstart":{"code":"import prettier from 'prettier';\nimport prettierPluginPegjs from 'prettier-plugin-pegjs';\n\nconst code = `Expression = head:Term tail:(_(\"+\"/\"-\")_ Term)* { return tail.reduce(function(result, element) { if (element[1] === \"+\") { return result + element[3]; } if (element[1] === \"-\") { return result - element[3]; } }, head) }`;\n\nconst formatted = await prettier.format(code, {\n  parser: 'pegjs',\n  plugins: [prettierPluginPegjs],\n  tabWidth: 2,\n});\nconsole.log(formatted);","lang":"typescript","description":"Formats a PEG.js grammar string using Prettier with the plugin, demonstrating usage in a Node.js TypeScript environment."},"warnings":[{"fix":"Use .pegjs extension or set parser: 'pegjs' in Prettier config","message":"The plugin parses PEG.js (original) grammar, not Peggy (fork) — ensure your grammar file uses .pegjs extension or specify parser explicitly","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade to Node 16+ and use ESM imports (import) or dynamic import()","message":"v2.0.0 dropped support for Node < 16, CommonJS via require() fails","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Migrate to import syntax or upgrade to v2 (ESM only)","message":"Using default export with require('prettier-plugin-pegjs') will return undefined in older versions — always use default import","severity":"deprecated","affected_versions":">=1.0.0 <2.0.0"},{"fix":"Set actionParser to appropriate parser (e.g., 'babel' for JavaScript without TypeScript)","message":"actionParser option defaults to 'babel-ts' — may cause parse errors if actions contain other languages","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'16':22 'action':37,54 'actionpars':34 'avail':55 'browser':57 'bundl':60 'code':38,52 'configur':42 'deepli':47 'default':41 'definit':26 'file':14 'format':9,36 'formatt':45 'generic':44 'grammar':13 'javascript':61 'javascript/typescript':39 'latest':18 'node':21 'option':31 'parser':63 'peg':49 'peg.js':10 'peggi':12 'pegj':4,62 'plugin':3,7 'plus':32 'preserv':51 'prettier':2,6,30,64 'prettier-plugin-pegj':1 'requir':20 'ship':24 'stabl':19 'standalon':59 'standard':29 'support':28 'syntax':50 'typescript':25,65 'understand':48 'unlik':43 'v2.0.2':15 'via':58 'within':53","created_at":"2026-04-25T11:22:55.006510+00:00","updated_at":"2026-04-25T11:22:55.006510+00:00","problems":[{"fix":"Run 'npm install --save-dev prettier prettier-plugin-pegjs' or 'yarn add --dev prettier prettier-plugin-pegjs'.","cause":"Plugin not installed or not in node_modules","error":"Error: Cannot find module 'prettier-plugin-pegjs'"},{"fix":"Check the grammar against PEG.js specification; ensure initial rule is uppercase.","cause":"The grammar file is not valid PEG.js syntax (e.g., missing header or invalid rule)","error":"SyntaxError: Unexpected token (1:1) while parsing PEG grammar"},{"fix":"Use dynamic import: const prettier = await import('prettier'); or migrate to ESM.","cause":"Using CommonJS require with ESM-only version or importing incorrectly","error":"TypeError: prettier.format is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/siefkenj/prettier-plugin-pegjs","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/prettier-plugin-pegjs","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-24","install_tag":null}}