{"id":16501,"library":"prettier-plugin-firebase-database","title":"Prettier Plugin for Firebase Realtime Database Rules","description":"The `prettier-plugin-firebase-database` package, currently at version 2.0.0, is a specialized Prettier plugin designed to format Firebase Realtime Database Rules. It enforces a consistent code style for `*.rules` files (e.g., `database.rules.json`), ensuring readability and maintainability within development teams working with Firebase. As a Prettier plugin, it integrates into existing Prettier setups via configuration, providing custom parsing and formatting logic tailored to the unique JSON-like syntax of Firebase security rules. The project follows Prettier's major release cadence, with updates typically occurring to maintain compatibility with new Prettier versions or to adapt to changes in Firebase rules syntax. Its key differentiator is providing specific, correct formatting for Firebase rules, which generic JSON formatters often handle incorrectly.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/maxpatiiuk/prettier-plugin-firebase-database","tags":["javascript","firebase","firebase-realtime-database","prettier","prettier-plugin","typescript"],"install":[{"cmd":"npm install prettier-plugin-firebase-database","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-firebase-database","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-firebase-database","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for Prettier plugin functionality, requiring version 3 or newer.","package":"prettier","optional":false}],"imports":[{"note":"This package is a Prettier plugin loaded by Prettier through its configuration file (e.g., `prettier.config.js`), not via a direct JavaScript `import` or `require` statement. The correct usage is to include its package name as a string within the `plugins` array.","wrong":"import * as FirebasePrettierPlugin from 'prettier-plugin-firebase-database';","symbol":"\"prettier-plugin-firebase-database\"","correct":"// In prettier.config.js\nplugins: [\"prettier-plugin-firebase-database\"]"},{"note":"When using Prettier `overrides` to explicitly associate specific file patterns (like `*.rules`) with this plugin, the `parser` option must be set to the full plugin package name as a string.","wrong":"parser: 'firebase' || parser: 'rules'","symbol":"parser: 'prettier-plugin-firebase-database'","correct":"// prettier.config.js, inside overrides.options\nparser: 'prettier-plugin-firebase-database'"},{"note":"For TypeScript-enabled Prettier configuration files (e.g., `prettier.config.js` or `prettier.config.mjs`), you typically import the `Config` type from the `prettier` package itself for type checking, not from the plugin.","wrong":"import { Config } from 'prettier-plugin-firebase-database';","symbol":"import(\"prettier\").Config","correct":"/** @type {import(\"prettier\").Config} */\nconst config = { ... };"}],"quickstart":{"code":"// prettier.config.js\n/**\n * @see https://prettier.io/docs/en/configuration.html\n * @type {import(\"prettier\").Config}\n */\nconst config = {\n  plugins: ['prettier-plugin-firebase-database'],\n  // Recommended: Explicitly associate .rules files with the plugin's parser.\n  // This ensures consistent formatting for all files ending with .rules.\n  overrides: [\n    {\n      files: '*.rules',\n      options: {\n        parser: 'prettier-plugin-firebase-database'\n      }\n    }\n  ]\n};\n\nexport default config;\n","lang":"javascript","description":"This quickstart demonstrates how to configure Prettier to load the Firebase Database Rules plugin. After installing `prettier` and `prettier-plugin-firebase-database` as dev dependencies, create or update your `prettier.config.js` file with the plugin reference. You can then format `.rules` files using `prettier --write your-file.rules`."},"warnings":[{"fix":"Upgrade Prettier to version 3 or greater by running `npm install prettier@latest` or `yarn add prettier@latest`.","message":"Version 2.0.0 and above of `prettier-plugin-firebase-database` requires Prettier version 3 or newer due to a peer dependency. Older versions of Prettier (e.g., v2.x) are not supported and will lead to installation or runtime errors.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Verify that `plugins: ['prettier-plugin-firebase-database']` is present and correctly spelled in your Prettier config.","message":"If Prettier isn't formatting your `.rules` files, ensure the plugin is correctly listed in the `plugins` array of your Prettier configuration file (e.g., `prettier.config.js`). Typos or missing the entry will prevent the plugin from being loaded.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Add an `overrides` entry to your Prettier config: `overrides: [{ files: '*.your_extension', options: { parser: 'prettier-plugin-firebase-database' } }]` where `your_extension` is the actual file extension.","message":"The plugin by default attempts to parse `.rules` files. If you have Firebase rules files with different extensions or if auto-detection fails, explicitly configure `overrides` in your `prettier.config.js` to associate specific file patterns with the plugin's parser.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure `prettier-plugin-firebase-database` is installed as a dev dependency and correctly listed in the `plugins` array of your `prettier.config.js`. If using package managers like Yarn PnP, check plugin resolution.","cause":"Prettier could not find or load the `prettier-plugin-firebase-database` plugin, or it's not correctly referenced in your configuration.","error":"[error] Unknown parser \"prettier-plugin-firebase-database\" for file \"your-file.rules\""},{"fix":"Install `prettier` version 3 or greater: `npm install --save-dev prettier@latest` or `yarn add --dev prettier@latest`.","cause":"The `prettier-plugin-firebase-database` package has a peer dependency on `prettier` version 3 or higher, but an incompatible or missing version of `prettier` is installed.","error":"Error: Cannot find module 'prettier' (or similar during npm install/yarn add)"},{"fix":"Verify the file path and pattern provided to the `prettier --write` command. Ensure the file exists and the glob pattern is correct relative to where you run the command.","cause":"This is a Prettier CLI error, indicating that the command-line pattern provided to `prettier --write` did not find any files.","error":"No files matching the pattern were found: \"firebase-database.rules\""}],"ecosystem":"npm"}