{"id":20364,"library":"prettier-plugin-firestore-rules","title":"Prettier Plugin for Firestore Rules","description":"A prettier plugin to format Firebase Firestore Security Rules files (.rules). Version 0.1.5 adds support for the 'in' operator. It is a lightweight, single-purpose plugin that integrates with Prettier, providing consistent formatting for Firestore rules alongside other code. Compared to manual formatting or IDE extensions, it offers automated, reproducible formatting within the Prettier ecosystem. The plugin is actively maintained with regular releases and supports Node.js ≥11. It is an ideal choice for Firebase projects using Prettier, ensuring rules keep the same code style as the rest of the codebase.","status":"active","version":"0.1.5","language":"javascript","source_language":"en","source_url":"https://github.com/ChFlick/prettier-plugin-firestore-rules","tags":["javascript","prettier","prettier-plugin","plugin","firebase","firestore"],"install":[{"cmd":"npm install prettier-plugin-firestore-rules","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-firestore-rules","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-firestore-rules","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; required as the formatting engine","package":"prettier","optional":false}],"imports":[{"note":"This is a prettier plugin, used via configuration or CLI, not directly imported in JavaScript/TypeScript.","wrong":"import plugin from 'prettier-plugin-firestore-rules'; // Not needed and will not work","symbol":"prettier-plugin-firestore-rules","correct":"No explicit import needed; use in .prettierrc or CLI as --plugin=prettier-plugin-firestore-rules"},{"note":"Works out of the box for .rules files if the plugin is installed and listed in prettier config.","wrong":"Relying on file detection without registering the plugin","symbol":"firestore.rules","correct":"Files with .rules extension are automatically detected and formatted when plugin is registered"},{"note":"The plugin is not meant to be required directly; it is loaded by prettier.","wrong":"const rulesPlugin = require('prettier-plugin-firestore-rules'); // Not a standalone module","symbol":"require('prettier-plugin-firestore-rules')","correct":"Add to .prettierrc: { \"plugins\": [\"prettier-plugin-firestore-rules\"] }"}],"quickstart":{"code":"// 1. Install plugin and prettier\nnpm install --save-dev prettier prettier-plugin-firestore-rules\n\n// 2. Create .prettierrc in project root\n// .prettierrc\n{\n  \"plugins\": [\"prettier-plugin-firestore-rules\"],\n  \"singleQuote\": true,\n  \"tabWidth\": 2\n}\n\n// 3. Format a .rules file (e.g., firestore.rules)\n// Run: npx prettier --write firestore.rules\n\n// Example firestore.rules before formatting:\n// rules_version = '2';\n// service cloud.firestore {\n// match /databases/{database}/documents {\n//   match /{document=**} {\n//     allow read, write: if false;\n//   }\n// }\n// }\n\n// After formatting:\n// rules_version = '2';\n// service cloud.firestore {\n//   match /databases/{database}/documents {\n//     match /{document=**} {\n//       allow read, write: if false;\n//     }\n//   }\n// }","lang":"javascript","description":"Install the plugin, configure .prettierrc to include the plugin, then format .rules files using prettier CLI."},"warnings":[{"fix":"Update to >=0.1.5 and re-format .rules files.","message":"v0.1.5 changed formatting for 'in' operator. Previous versions may have formatted 'in' differently, causing formatting diffs.","severity":"breaking","affected_versions":"<=0.1.4"},{"fix":"Upgrade Node.js to version 11 or later.","message":"Node.js v10 and below are not supported. The plugin requires Node >=11.","severity":"deprecated","affected_versions":"all"},{"fix":"Ensure plugins array includes \"prettier-plugin-firestore-rules\" in .prettierrc or use --plugin=... on CLI.","message":"Plugin must be listed in prettier config or passed via CLI argument; otherwise, .rules files will not be formatted.","severity":"gotcha","affected_versions":"all"},{"fix":"Use separate prettier plugins or formatters for other file types.","message":"The plugin only formats .rules files; other Firebase configuration files (e.g., firestore.indexes.json) are not affected.","severity":"gotcha","affected_versions":"all"},{"fix":"If using TypeScript in your project, ignore missing types or write a declaration file.","message":"No TypeScript typings are provided in this version; the plugin is plain JavaScript.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run 'npm install --save-dev prettier-plugin-firestore-rules'.","cause":"Plugin not installed or not in node_modules.","error":"Error: Cannot find module 'prettier-plugin-firestore-rules'"},{"fix":"Remove direct require/import and add the plugin name to prettier's plugins config.","cause":"Incorrect usage: trying to require the plugin as a standalone module instead of via prettier configuration.","error":"TypeError: plugin is not a function"},{"fix":"Add the plugin to .prettierrc plugins array.","cause":"Plugin not registered in prettier config; prettier does not know how to parse .rules files.","error":"Error: No parser could be inferred for file: firestore.rules"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}