{"id":20368,"library":"prettier-plugin-groq","title":"Prettier Plugin for GROQ","description":"A Prettier plugin for formatting GROQ queries used with Sanity.io. Version 0.2.5 is the latest stable release. Release cadence is irregular, driven by community contributions. Key differentiators: opinionated formatting following Prettier philosophy, groups object properties by value type, respects printWidth and inlineShorthandProperties option. Supports filters, projections, order, select, and conditional expressions. Does not preserve whitespace or inline comments. Standard Prettier plugin installation; auto-detected by editors when installed locally.","status":"active","version":"0.2.5","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","groq","prettier-plugin","prettier","formatter"],"install":[{"cmd":"npm install prettier-plugin-groq","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-groq","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-groq","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required to use the plugin","package":"prettier","optional":false}],"imports":[{"note":"Prettier plugins are typically specified in config files, not imported directly. The plugin auto-registers when installed.","wrong":"const prettierPluginGroq = require('prettier-plugin-groq')","symbol":"Plugin","correct":"import * as prettierPluginGroq from 'prettier-plugin-groq'"},{"note":"Add the plugin name to the plugins array in .prettierrc or prettier.config.js to enable GROQ formatting.","wrong":"// incorrect: plugins: ['prettier-plugin-groq'] missing in config","symbol":"Config","correct":"// .prettierrc\n{ \"plugins\": [\"prettier-plugin-groq\"], \"groqInlineShorthandProperties\": false }"},{"note":"Option name is groqInlineShorthandProperties, not groqInlineShorthandProps.","wrong":"// typo: \"groqInlineShorthandProps\": true","symbol":"groqInlineShorthandProperties","correct":"// .prettierrc\n{ \"groqInlineShorthandProperties\": true }"}],"quickstart":{"code":"npm install --save-dev prettier prettier-plugin-groq\n\necho '{\n  \"plugins\": [\"prettier-plugin-groq\"],\n  \"groqInlineShorthandProperties\": true\n}' > .prettierrc\n\ncat << 'EOF' > query.groq\n*[_type == \"movie\" && popularity > 10] | order(popularity desc){ _id, title, popularity }\nEOF\n\nnpx prettier --write query.groq\n\ncat query.groq\n# Output:\n# *[_type == \"movie\" && popularity > 10] | order(popularity desc) {\n#   _id,\n#   title,\n#   popularity\n# }","lang":"javascript","description":"Installs the plugin, configures Prettier, formats a .groq file with inline shorthand enabled."},"warnings":[{"fix":"Avoid inline comments; use block comments /* ... */ if needed, but they are also unsupported. Consider reformulating the query without comments.","message":"Inline comments in GROQ queries are ignored and will be removed during formatting.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Rewrite map components using filter syntax or ensure the GROQ parser supports them. They are currently unsupported.","message":"Map components like `* | ([ like, this ])` are not supported by the parser and will cause errors.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Review formatted output to ensure expansion semantics are correct. The plugin groups and reorganizes properties.","message":"Expansion operator `...` behavior may not be preserved exactly as input due to AST-based formatting.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use the exact option name with correct capitalization.","message":"Option name `groqInlineShorthandProperties` is case-sensitive and must be spelt correctly.","severity":"gotcha","affected_versions":">=0.0.0"}],"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-groq' and add '\"plugins\": [\"prettier-plugin-groq\"]' to .prettierrc.","cause":"Prettier plugin not installed or not added to plugins array in config.","error":"Cannot find module 'prettier-plugin-groq'"},{"fix":"Remove inline comments from .groq files before formatting.","cause":"Inline comments are not supported by the GROQ parser used by this plugin.","error":"Unexpected token '//' (or similar comment error)"},{"fix":"Use correct option name: 'groqInlineShorthandProperties' in .prettierrc.","cause":"Option name is misspelled.","error":"Unknown option: groqInlineShorthandProps (or typo)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}