Skip to content

Latest commit

 

History

History
37 lines (33 loc) · 1.54 KB

STANDARDS.md

File metadata and controls

37 lines (33 loc) · 1.54 KB

Standards followed in this framework

  1. Use four spaces for indentation. No tabs.

  2. Shell/local variables and function names follow "snake_case" - only lowercase letters, underscores, and digits.

  3. Environment variables use all uppercase names. For example, BASE_HOME, BASE_HOST, BASE_OS, BASE_SOURCES. See: https://stackoverflow.com/a/42290320/6862601

  4. In rare cases of global variables being shared between library functions and their callers, use all uppercase names. For example: OUTPUT and OUTPUT_ARRAY

  5. Place most code inside functions and invoke the main function at the bottom of the script.

  6. In libraries, have top level code that prevents the file from being sourced more than once. For example:

    [[ $__stdlib_sourced__ ]] && return
    __stdlib_sourced__=1
  7. Make sure all local variables inside functions are declared local.

  8. Use func naming convention for special purpose variables and functions. Use a leading underscore for "private" variables and functions.

  9. Double quote all variable expansions, except:

    • inside [[ ]] or (( ))
    • places where we need word splitting to take place
  10. Use [[ $var ]] to check if var has non-zero length, instead of [[ -n $var ]]. See: https://stackoverflow.com/a/49825114/6862601

  11. Use "compact" style for if statements and loops:

    if condition; then
        ...
    fi
    
    while condition; do
    ...
    done
    
    for ((i=0; i < limit; i++)); do
    ...
    done
  12. Make sure the code passes https://shellcheck.net checks.