Test major Koha Wiki changes or bug fixes here without fear of breaking the production wiki.
For the current Koha Wiki, visit https://wiki.koha-community.org .User:Victor Grousset - tuxayo/Unofficial coding guidelines
To document lists widely used conventions that are not in the official guidelines. And personal preferences when there is no dominant usage.
JavaScript
Naming conventions (underscore_case vs camelCase)
As of march 2018 it's pretty even split.
I generally prefer underscore_case because there are reasons to believe that it's more readable for most people. But I have mixed feelings because the platform (JS + web browser APIs) use camelCase.
oleonard is in favor of underscore_case too so I lean on underscore_case :)
Spacing conventions
Space before { (opening curly bracket)
As of march 2018
## all the code ##
# all the {
rg -tjs --glob '!{*lib*}' '\{' -tjs --glob '!{*lib*}' | wc -l # → 2294
# all the { with a space before in JS
rg -tjs --glob '!{*lib*}' ' \{' -tjs --glob '!{#*lib*}' | wc -l # → 1716
## in function declarations ##
# all js function declarations
rg -tjs --glob '!{*lib*}' 'function.*\(.*\).*\{' -tjs --glob '!{*lib*}' | wc -l # → 881
# one space before {
rg -tjs --glob '!{*lib*}' 'function.*\(.*\) \{' -tjs --glob '!{*lib*}' | wc -l # → 564
# no space before {
rg -tjs --glob '!{*lib*}' 'function.*\(.*\)\{' -tjs --glob '!{*lib*}' | wc -l # → 317
Conclusion: put a space before {
No space before ( (opening parenthesis)
As of march 2018
## all the code ##
# all the ( in JS
rg -tjs --glob '!{*lib*}' '\(' -tjs --glob '!{*lib*}' | wc -l # → 4487
# space before (
rg -tjs --glob '!{*lib*}' ' \(' -tjs --glob '!{*lib*}' | wc -l # → 992
## in function declarations ##
# no space before (
rg -tjs --glob '!{*lib*}' 'function\(' -tjs --glob '!{*lib*}' | wc -l # → 505
# space before (
rg -tjs --glob '!{*lib*}' 'function \(' -tjs --glob '!{*lib*}' | wc -l # → 114
Conclusion: don't put a space before (
Spacing inside parenthesis (foo) vs ( foo )
tl;dr: There should be spaces => ( foo )
Current practice
See bug 27246 patch as an example
($ENV{'HTTP_USER_AGENT'})
( $ENV{'HTTP_USER_AGENT'} )
Current code state
As of march 2018
# all the (.*) in JS
rg -tjs --glob '!{*lib*}' '\(.*\)' -tjs --glob '!{*lib*}' | wc -l # → 4428
# all the ( foo )
rg -tjs --glob '!{*lib*}' '\( .* \)' -tjs --glob '!{*lib*}' | wc -l # → 786
Space before end of self closing tag - bar="foo" /> vs bar="foo"/>
As of march 2018
rg '" />' --glob '{*.tt}' | wc -l # → 4242
rg '"/>' --glob '{*.tt}' | wc -l # → 256
String literals: use double quotes instead of simple quotes
As of april 2018
rg -tjs --glob '!{*lib*}' '"' | wc -l # → 2214
rg -tjs --glob '!{*lib*}' "'" | wc -l # → 1240
Browser support
IE 11 for the OPAC.