EditorConfig
Zeal uses EditorConfig to maintain consistent coding styles. The.editorconfig file in the repository root defines the core formatting rules.
Most modern editors and IDEs support EditorConfig automatically or through plugins. Make sure your editor is configured to respect the .editorconfig file.
General Formatting Rules
These rules apply to all files in the project:Character Encoding and Line Endings
- Charset: UTF-8
- Line endings: LF (Unix-style,
\n) - Final newline: Always insert a final newline at the end of files
- Trailing whitespace: Remove all trailing whitespace
Indentation
- Indent style: Spaces (never tabs)
- Indent size: 4 spaces
- Max line length: 100 characters
Exceptions for Specific File Types
CMake Files
- Files:
CMakeLists.txt,*.cmake - Indent size: 4 spaces (planned to be 2 in the future)
CSS Files
- Files:
*.css - Indent size: 2 spaces
JSON Files
- Files:
*.json - Indent size: 2 spaces
YAML Files
- Files:
*.yaml,*.yml - Indent size: 2 spaces
C++ Coding Conventions
File Organization
Header Files (.h)
- Copyright and license header
- Include guard (using
#ifndef/#define) - System includes (Qt, standard library)
- Namespace declarations
- Class declarations
- Include guard closing
Implementation Files (.cpp)
- Copyright and license header
- Corresponding header include
- System includes
- Local includes
- Anonymous namespace (for internal helpers)
- Implementation
Copyright Headers
All source files must include the copyright header:Naming Conventions
Namespaces
- Use PascalCase for namespace names
- Nest namespaces for logical organization
- Always close namespaces with comments
Classes and Structs
- Use PascalCase for class names
- Use descriptive names that indicate purpose
Functions and Methods
- Use camelCase for function names
- Start with a lowercase letter
- Use descriptive verb-based names
Variables
- Use camelCase for variable names
- Start with a lowercase letter
- Use descriptive names
Constants
- Use UPPER_CASE with underscores for constants
- Use
constexprwhen possible
Private Members
- No special prefix or suffix convention is enforced
- Use clear, descriptive names
Qt Coding Style
Zeal uses Qt extensively and follows Qt conventions:Qt Types
- Prefer Qt types:
QString,QList,QVector, etc. - Use Qt’s foreach alternatives when appropriate
Signals and Slots
- Use Qt’s signal/slot mechanism
- Prefix signal names with action verbs
Qt Keywords
- Use Qt parent/child memory management
- Use
Q_OBJECTmacro for classes with signals/slots
Code Structure
Braces
- Opening brace on the same line for control statements
- Opening brace on a new line for function definitions (varies by context)
- Always use braces for control statements, even single-line
Spacing
- Space after keywords:
if (,for (,while ( - No space between function name and opening parenthesis
- Space around operators:
a + b,x = 5 - No space inside parentheses
Include Order
- Corresponding header (for
.cppfiles) - Blank line
- Qt includes
- Blank line
- Standard library includes
- Blank line
- Local project includes
Documentation
Doxygen Comments
Use Doxygen-style comments for public APIs:Inline Comments
Use// for inline comments:
TODO Comments
Mark future work with TODO comments:Static Analysis
Zeal uses static analysis tools:- Coverity Scan: Automated static analysis
- Compiler warnings: Treated as errors (when CMake >= 3.24.0)
Pre-commit Checks
Before committing:- Format check: Ensure code follows EditorConfig rules
- Build: Code must compile without errors or warnings
- Tests: All tests must pass
- Static analysis: No new warnings
Editor Configuration
VS Code
Install the EditorConfig extension:CLion / Qt Creator
Both IDEs support EditorConfig natively. Enable EditorConfig support in settings.Vim
Install theeditorconfig-vim plugin.
Emacs
Install theeditorconfig-emacs package.
Additional Resources
Summary
Key points to remember:- Use EditorConfig settings (4 spaces, UTF-8, LF line endings)
- Follow Qt naming conventions (PascalCase for classes, camelCase for functions)
- Include copyright headers in all source files
- Write clear, documented code with Doxygen comments for public APIs
- Keep lines under 100 characters
- Run tests and ensure clean builds before committing