A custom Biome GritQL plugin that prevents direct console.* usage in React components (.tsx files).
I use OpenObserve for centralized log aggregation. To ensure all browser logs are captured and sent to OpenObserve, I created a browserLogger utility that wraps console methods and forwards logs to my observability backend.
This plugin enforces that pattern by flagging any direct console.log, console.error, console.warn, console.info, or console.debug calls in React components as errors.
Biome has a built-in noConsoleLog rule, but I chose to write a custom plugin instead. The custom error message "Use browserLogger instead of console in React components" provides clear guidance that LLMs (like Claude, Cursor, etc.) can understand and act on when fixing code.
See no-console-in-tsx.grit in this gist.
Add the plugin to your biome.json using overrides to apply it only to .tsx files:
{
"overrides": [
{
"includes": ["**/*.tsx"],
"plugins": ["./plugins/no-console-in-tsx.grit"]
}
]
}Run Biome as usual:
bunx biome check .Any console.* calls in .tsx files will be flagged with:
Use browserLogger instead of console in React components