Include Rules

Managing include directives properly is crucial for build performance and code organization. These rules enforce a consistent style for including headers.

Include Order

INCLUDE_ORDER_WRONG

Enforces a standard include order: C standard library, C++ standard library, third-party libraries, and finally project-specific headers. This improves readability and helps identify dependencies.

Examples:

✅ Correct
❌ Incorrect (Lint Error)
// Correct order: C std, C++ std, third-party, project

// C standard library
#include <cstddef>
#include <cstdio>

// C++ standard library
#include <iostream>
#include <string>
#include <vector>

// Third-party libraries
#include <gtest/gtest.h>
#include <boost/optional.hpp>

// Project headers
#include "niti/core/engine.h"
#include "niti/rules/rule.h"
// Incorrect order

#include "niti/core/engine.h" // Project header first
#include <iostream>            // C++ std header
#include <gtest/gtest.h>       // Third-party header
#include <cstddef>             // C std header
#include "niti/rules/rule.h"    // Another project header
#include <string>              // Another C++ std header

Local Include Style

INCLUDE_ANGLE_BRACKET_FORBIDDEN

Requires local project headers to be included with quotes (`""`) and external/system headers with angle brackets (`<>`). This clearly distinguishes between internal and external dependencies.

Examples:

✅ Correct
❌ Incorrect (Lint Error)
// System headers use angle brackets
#include <vector>
#include <string>

// Project-local headers use quotes
#include "my_app/my_class.h"
#include "utils/string_helpers.h"
// Don't use angle brackets for local headers
#include <my_app/my_class.h> // Incorrect

// Don't use quotes for system headers
#include "vector" // Incorrect

Precompiled Headers (PCH) [Make it a Plugin for Vajra]

INCLUDE_MISSING_PCH

Ensures that if a precompiled header is used in the project, it is the very first include in every source file to improve build times.

Examples:

✅ Correct
❌ Incorrect (Lint Error)
// PCH must be the first include
#include "framework/precompiled.h"

#include <iostream>
#include "my_app/my_class.h"

// ... rest of the file
#include <iostream>
// PCH is not the first include
#include "framework/precompiled.h" // Incorrect

#include "my_app/my_class.h"

// ... rest of the file

Summary

A clean include policy is a cornerstone of a healthy C++ project:

  • Order matters: A consistent include order makes dependencies clear.

  • Quotes vs. Brackets: Visually separate internal and external code.

  • PCH First: Maximize build speed by including the precompiled header first.