Coding Guidelines
Like any other project we have some small guidelines about our source code, too. The rules we have are not there to punish you - the rules are in place to help us all. By having a consistent coding style it becomes very easy for new and also longtime contributors to navigate through the sources and all the implied logic of any one source file.
Python 3 shall be used. How long can we keep Python 2 alive anyway? No considerations for Python 2 compatibility should be taken at any time.
Formatting
- Python: Tabs shall not be used. Every indentation level should be 4 spaces
- XML: Tabs shall not be used. Every indentation level should be 2 spaces
There are extensions to e.g. VIM (xmllint) which will help you to get your indention levels correct. Add to following to your .vimrc file:
au FileType xml setlocal equalprg=xmllint\ --format\ --recover\ -\ 2>/dev/null
now you can call the linter using gg=G in command mode.
Text generation
Template processor should be used for generating config files. Built-in string formatting may be used for simple line-oriented formats where every line is self-contained, such as iptables rules. Template processor must be used for structured, multi-line formats such as those used by ISC DHCPd.
The default template processor for VyOS code is Jinja2.
Summary
When modifying the source code, remember these rules of the legacy elimination campaign:
- No new features in Perl
- No old style command definitions
- No code incompatible with Python3
- Last Author
- Unknown Object (User)
- Last Edited
- Mar 22 2020, 12:51 AM