Search code examples
google-cloud-firestorefirebase-security

How to format a firestore.rules file with a tool like prettier?


For example, I have these rules:

    function isValidTimestamp(timestampValue){return request.time==timestampValue;}

    match /users/{userID}{allow get: if resource.auth != null;allow create:if isValidTimeStamp(request.resource.data.createdAt)}

i would like to have something like this:

function isValidTimestamp(timestampValue){  
  return request.time == timestampValue;
}

match /users/{userID} {
  allow get: if resource.auth != null; 
  allow create: if isValidTimeStamp(request.resource.data.createdAt);
}

Is it possible to lint/format this file?


Solution

  • Unfortunately, there isn't a software developed yet, that formats the structure of Firestore rules like Prettier does. As mentioned in this conversation on Github here, it seems that talking about improving Prettier to format Firebase rules - which would include the Firestore ones - but for now, indeed, it seems that it's not possible. (I would really like that it worked as well, it would be really helpful)

    Let me know if the information clarified you!