[clang-format]: https://clang.llvm.org/docs/ClangFormat.html "Documentation of the ClangFormat tool at the Clang documentation site" {target="_blank"} [.clang-format]: r params$biocro_root/.clang-format "The Clang configuration file for BioCro" {target="_blank"} [.editorconfig]: r params$biocro_root/.editorconfig "BioCro's .editorconfig file" {target="_blank"} [EditorConfig]: https://editorconfig.org/ "The EditorConfig Web site" {target="_blank"} [Homebrew]: https://brew.sh/ "The Homebrew package manager Web site" {target="_blank"}

Formatting Tools

Clang's formatting tool

Many of these BioCro formatting preferences can be applied automatically using the program [clang-format][] with the [.clang-format][] file provided in the base directory of BioCro. Do not apply clang-format to all files indiscriminately, as that will ruin manually-aligned tables.

The best time to reformat a file is immediately before (or possibly immediately after) making substantive changes to the code in the file. But, as mentioned in Section \@ref(general-coding-considerations), sweeping formatting changes should be made in a separate commit, separate from any substantive changes made to the code. This way, changes to the functioning of the code won't be obscured by changes to formatting that have no effect on code semantics.

Installation

One can install clang-format on Ubuntu using sudo apt install clang-format. On macOS, clang-format is available from the [Homebrew][] package manager.

Using the Clang formatting tool

Files can be formatted using

clang-format file_name > new_file

or edited in place using

clang-format -i file_name

If your editor has the ability to display differences between the original and revised versions of the file, it is a good idea to step through and inspect the proposed changes to ensure they are desirable.

Using the Clang formatting tool with the CodeLite IDE

On Windows, macOS, or Linux, the CodeLite IDE includes clang-format and provides an easy way to use it. First go to Plugins -> Source Code Formatter -> Options. In the C++ tab, select use .clang-format file. Now press Ctrl-I or click Plugins -> Source Code Formatter -> Format Current Source to format a file.

EditorConfig

Another tool to help with formatting is EditorConfig. EditorConfig, when used in conjunction with the [.editorconfig][] file provided in the base directory of BioCro, provides a method for standardizing settings across different text editors. While some editors have native support, others require a plugin. See the [EditorConfig website][EditorConfig] for more details.



ebimodeling/biocro documentation built on May 3, 2024, 7:52 p.m.