Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Folds/unfolds all Firebase rules that are direct children of the "rules" node in the rules editor
// Sometimes the rules editor lags when many rules are expanded.
// This snippet collapses all the rules that are direct children of the root "rules" node.
// Rules editor can be found at:{PROJECT_ID}/database/rules.
// Get CodeMirror instance
const editor = $('.CodeMirror')[0].CodeMirror;
// Find direct children of "rules" node and fold them.
editor.eachLine((l) => {
// Perhaps a better way is to check the parent of `l` to handle different indentations.
const isDirectChild = l.text.indexOf(' "') === 0 && l.text.indexOf('{') !== -1;
if (!isDirectChild) return;
const num = editor.getLineNumber(l);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment