Velocity Code Style
Last modified by Alexandru Brassat on 2024/09/13 11:42
Velocity scripts must follow these rules:
- Use 2 spaces for indentation
- Use single quotes for strings that don't need to be parsed/interpreted. This improves performance.
- Comments should start with an uppercase letter and end with a dot. For example: ## This macro loops through all users in a wiki.
- All macros and velocity directives should have a space between the name and the parentheses. For example:#set ($debugLevel = 1)
#if ($debugLevel > 0)
#foreach ($user in $users)
#myDisplayMacro ($user)
#end
#end
- Always capture the result of a method call in a variable to avoid side effects (things output to the result: what the method returns or unwanted empty lines). For example:#set ($discard = $someVar.someMethod())
- Internal macros that are not aiming at being exposed as API should always be prefixed with the character _. API macros should always be properly documented with information on the parameters and a since information. This rule has been introduced with XWiki 15.10RC1 so old macros don't rely on it: they are considered by default as APIs but can be renamed after a vote.