1# PerfettoSQL Style Guide 2 3_This page provides a suggested style guide for writing PerfettoSQL and is in 4use inside the PerfettoSQL standard library in the trace processor. It also 5provides guidance on the autoformatter._ 6 7## Rules 8 91. Keep lines below 80 characters long 102. Function names, macro names and table/view names should all be lower snake 11 case. 123. SQL keywords should all be upper case 134. When line-breaking SQL expressions, place the joining keyword (AND/OR) at the 14 _start of the next line_ rather than the _end of the previous line_. 15 16## Autoformatter 17 18PerfettoSQL comes with an auto-formatter as implemented by `tools/format_sql.py` 19Python script. This is a simple script which can be run over any set of files or 20directories and automatically formats the code to adhere to the above rules. 21 22This script is _required_ to be run when making contributions to the standard 23library. It's automatically executed as part of running `tools/gen_all` which is 24part of the standard development workflow in Perfetto. Presubmit will check to 25make sure you've done this. 26 27The autoformatter is not perfect by any means and does often have subtle edge 28cases: 291. It doesn't handle comments in the middle of complex expressions. Prefer 30placing comments at the start of these expressions instead of in the middle. 312. It doesn't format macro invocations as they have very complex semantics 32in many cases. 33