After Code Developing ===================== CodeFactor ---------- We check the C++, R and Python format by `CodeFactor `__. More specifically, the formatters and rules are: - C++: `CppLint `__ with `CPPLINT.cfg `__ - Python: `Pylint `__ with `.pylintrc `__ - R: `Lintr `__ with `.lintr `__ Each pull request will be checked, and some recommendations will be given if not passed. But don't be worry about those complex rules, most of them can be formatted automatically by some tools. Note that there may be few problems that the auto-fix tools can NOT deal with. In that situation, please update your pull request following the suggestions by CodeFactor. Auto-format ----------- C++ ~~~ `Clang-Format `__ is a powerful tool to format C/C++ code. You can install it quickly: - Linux: ``$ sudo apt install clang-format``; - MacOS: ``$ brew install clang-format``; - Windows: download it from `LLVM `__; with VS Code ^^^^^^^^^^^^ If you use `Visual Studio Code `__ for coding, an extension called `C/C++ `__ supports auto-fix by Clang-Format. However, in order to adapt to our rules, you need to add some statements in ``setting.json`` (the configuration file for Visual Studio Code): .. code:: javascript "C_Cpp.clang_format_fallbackStyle": "{BasedOnStyle: Google, UseTab: Never, IndentWidth: 4, TabWidth: 4, ColumnLimit: 120, Standard: Cpp11}", "files.insertFinalNewline": true, "files.trimFinalNewlines": true, // "editor.formatOnSave": true // enable auto-fix after saving a file After that, you can right-click on an C++ file and then click “Format Document”. That will be done. with command line ^^^^^^^^^^^^^^^^^ Besides, Clang-Format supports using directly in command line or based on a configuration file. You can check them `here `__. The configuration is similar as above: .. code:: yaml # `.clang-format` in the same directory of your C++ files BasedOnStyle: Google UseTab: Never IndentWidth: 4 TabWidth: 4 ColumnLimit: 120 Standard: Cpp11 And then run ``$ clang-format -style=file some_code.cpp > some_code_formatted.cpp`` in command line. The formatted code is stored in ``some_code_formatted.cpp`` now. Python ~~~~~~ `Autopep8 `__ can be used in formatting Python code. You can easily install it by ``$ pip install autopep8``. .. _with-vs-code-1: with VS Code ^^^^^^^^^^^^ Visual Studio Code can deal with Python auto-fix too, with `Python `__ extension. There is no more steps to do. Right-click on an Python file and then click “Format Document”. That will be done. .. _with-command-line-1: with command line ^^^^^^^^^^^^^^^^^ As we memtioned above, the default setting of Autopep8 is enough for us. Hence run ``$ autopep8 some_code.py > some_code_formatted.py`` and the formatted code is stored in ``some_code_formatted.py`` now.