A modern C++ linter written in Python
Project description
Niti by Vajra
Fast, Modern, Lean Linter for C++ code for Vajra. Easy to configure no frills supercharged C++ linter with plugin support for custom rules.
Setup
Installation
pip install niti
Usage
Basic Linting
# Lint a single file
niti path/to/file.cpp
# Lint a directory (recursively finds all C++ files)
niti path/to/project/
# Lint current directory
niti .
# Show help and available options
niti --help
# List all available rules
niti --list-rules
# List rules with descriptions
niti --list-rules --verbose
Discovering Available Rules
Before disabling rules, you can discover what rules are available and which ones are triggering:
# See all available rules and their categories
niti --list-rules
# Run linter to see which rules are being triggered
niti --check your_project/
# Get detailed information about specific rule violations
niti --check --verbose your_file.cpp
Configuration File (.nitirc or niti.yaml)
Create a .nitirc or niti.yaml file in your project root to customize linting behavior:
# Basic configuration
documentation_style: doxygen # Options: doxygen, javadoc, plain
copyright_holders:
- "Your Organization"
- "Your Team"
# File organization
header_extensions: [".h", ".hpp", ".hxx"]
source_extensions: [".cpp", ".cc", ".cxx"]
excluded_paths: ["/kernels/", "/test/", "/build/"]
# Disable specific rules globally
disabled_rules:
- type-forbidden-int
- modern-missing-noexcept
- doc-function-missing
# Enable specific rules (overrides defaults)
enabled_rules:
- modern-nodiscard-missing
- doc-function-param-desc-quality
# Override rule severities
rule_severities:
naming-function-case: error
safety-raw-pointer-param: warning
doc-class-missing: info
Disabling Rules
Niti supports multiple approaches for rule suppression:
Configuration-based (global):
# .nitirc or niti.yaml
rules:
type-forbidden-int:
enabled: false
naming-variable-case:
severity: warning
Comment-based (NOLINT):
int value = 42; // NOLINT
int badName = 10; // NOLINT naming-variable-case
int multiple = 99; // NOLINT type-forbidden-int,naming-variable-case
// NOLINTNEXTLINE type-forbidden-int
int nextLine = 24;
File-level disable:
// NOLINT naming-variable-case
// NOLINT type-forbidden-int
๐ Complete Rule Suppression Guide โ
Development
Prerequisites
- Python 3.8 or higher
Setting Up Development Environment
We recommend using a virtual environment to isolate dependencies. You can use either uv or conda:
Option 1: Using uv (Recommended)
# Clone the repository
git clone https://github.com/project-vajra/niti.git
cd niti
# Create and activate virtual environment with uv
uv venv
source .venv/bin/activate
# Install dependencies
# For development:
uv pip install -r requirements-dev.txt
# Install Niti
uv pip install -e .
# Or install directly with optional dependencies:
uv pip install -e .[dev]
Option 2: Using conda/mamba
# Clone the repository
git clone https://github.com/project-vajra/niti.git
cd niti
# Create conda environment from file
conda env create -f environment.yml
conda activate niti
# Install the package in editable mode
pip install -e .
# Or use the Makefile for convenience
make install-dev
Installing Dependencies
The project has the following main dependencies:
pyyaml: For configuration file parsingtree-sitter&tree-sitter-cpp: For C++ code parsing
Development dependencies include:
pytest: Testing frameworkblack,isort&autoflake: Code formatting and cleanupflake8&mypy: Linting and type checkingpytest-cov: Coverage reporting
Note: Niti is not yet available on PyPI. For now, please install from source as shown above.
Development Workflow
Running Tests using PyTests
Niti has a comprehensive test suite organized into unit and integration tests:
# Run all tests
pytest
# Run all tests with coverage report
pytest --cov=niti --cov-report=html
# Run only unit tests (fast, isolated)
pytest -m unit
# Run only integration tests (slower, end-to-end)
pytest -m integration
# Run tests for specific rule categories
pytest test/unit/naming/ # Naming convention rules
pytest test/unit/safety/ # Safety rules
pytest test/unit/modern_cpp/ # Modern C++ rules
pytest test/unit/documentation/ # Documentation rules
# Run tests with verbose output
pytest -v
# Run a specific test file
pytest test/unit/types/test_type_rules.py
# Run a specific test method
pytest test/unit/naming/test_naming_rules.py::TestNamingFunctionCase::test_detects_snake_case_functions
Using the Custom Test Runner
The project includes a custom test runner for convenience:
# Run unit tests
python test/run_tests.py unit
# Run integration tests
python test/run_tests.py integration
# Run all tests
python test/run_tests.py all
# Run with verbose output and coverage
python test/run_tests.py unit -v -c
Test Structure
The test suite is organized as follows:
test/unit/: Fast, isolated unit tests organized by rule categorytest/integration/: End-to-end integration teststest/fixtures/: Reusable C++ code samples for testingtest/test_utils.py: Base classes and testing utilities
Each rule category has comprehensive positive (should pass) and negative (should fail) test cases using real C++ code examples.
Code Quality Checks
You can use individual commands or the convenient Makefile targets:
Using Makefile (Recommended)
# Format code (autoflake + black + isort)
make format
# Run linting (flake8 + mypy)
make lint
# Run tests
make test
# Run tests with coverage
make test-cov
# Show all available commands
make help
Project Structure
niti/
โโโ niti/ # Main package
โ โโโ cli.py # Command-line interface
โ โโโ core/ # Core functionality
โ โ โโโ config.py # Configuration handling
โ โ โโโ engine.py # Linting engine
โ โ โโโ issue.py # Issue representation
โ โ โโโ severity.py # Severity levels
โ โโโ rules/ # Linting rules (54+ rules across categories)
โ โโโ base.py # Base rule classes
โ โโโ naming.py # Naming convention rules
โ โโโ safety.py # Safety-related rules
โ โโโ modern_cpp.py # Modern C++ best practices
โ โโโ documentation.py # Documentation requirements
โ โโโ types.py # Type system rules
โ โโโ ... # Other rule categories
โโโ test/ # Comprehensive test suite
โ โโโ unit/ # Unit tests by rule category
โ โ โโโ naming/ # Tests for naming rules
โ โ โโโ safety/ # Tests for safety rules
โ โ โโโ modern_cpp/ # Tests for modern C++ rules
โ โ โโโ documentation/ # Tests for documentation rules
โ โ โโโ types/ # Tests for type system rules
โ โ โโโ ... # Other rule category tests
โ โโโ integration/ # End-to-end integration tests
โ โโโ fixtures/ # Reusable C++ code samples
โ โโโ test_utils.py # Testing base classes and utilities
โ โโโ run_tests.py # Custom test runner
โโโ pyproject.toml # Project configuration
โโโ Makefile # Development workflow commands
โโโ CLAUDE.md # Claude Code assistant guidance or for other Agentic tools
โโโ README.md # This file
Examples
Full sample on using the Linter in a large-scale C++ project in the Vajra project will be out soon. We're building Vajra the second-generation LLM serving engine in C++. Watch out this space for more details soon.
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file niti-0.2.4.tar.gz.
File metadata
- Download URL: niti-0.2.4.tar.gz
- Upload date:
- Size: 108.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92f7a2960cac7448c8ad5ffdbca809fad4db5e4908f47cf58f6844d92bfd18c9
|
|
| MD5 |
3a7edeb067427e63fd2697f85012b96f
|
|
| BLAKE2b-256 |
4853e8e847ba35148f91138594de0b5e4625ee15fb11142916739f9a0ba10ec2
|
Provenance
The following attestation bundles were made for niti-0.2.4.tar.gz:
Publisher:
publish_release.yml on project-vajra/niti
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
niti-0.2.4.tar.gz -
Subject digest:
92f7a2960cac7448c8ad5ffdbca809fad4db5e4908f47cf58f6844d92bfd18c9 - Sigstore transparency entry: 581296248
- Sigstore integration time:
-
Permalink:
project-vajra/niti@faf72552a781ad9db3dd06c90ec7ec8a43ca6428 -
Branch / Tag:
refs/tags/v0.2.4 - Owner: https://github.com/project-vajra
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_release.yml@faf72552a781ad9db3dd06c90ec7ec8a43ca6428 -
Trigger Event:
release
-
Statement type:
File details
Details for the file niti-0.2.4-py3-none-any.whl.
File metadata
- Download URL: niti-0.2.4-py3-none-any.whl
- Upload date:
- Size: 113.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a37c4a186cfb4c7cc92adf0688657b2138d989c7425b7ca5fbeedff43c3d15be
|
|
| MD5 |
07045a60924ddba3e881e51657265049
|
|
| BLAKE2b-256 |
b72d0c1cd6ab271fd6d1e9d864c9383d93e01a12c7e7a524007ace483bf83644
|
Provenance
The following attestation bundles were made for niti-0.2.4-py3-none-any.whl:
Publisher:
publish_release.yml on project-vajra/niti
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
niti-0.2.4-py3-none-any.whl -
Subject digest:
a37c4a186cfb4c7cc92adf0688657b2138d989c7425b7ca5fbeedff43c3d15be - Sigstore transparency entry: 581296261
- Sigstore integration time:
-
Permalink:
project-vajra/niti@faf72552a781ad9db3dd06c90ec7ec8a43ca6428 -
Branch / Tag:
refs/tags/v0.2.4 - Owner: https://github.com/project-vajra
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_release.yml@faf72552a781ad9db3dd06c90ec7ec8a43ca6428 -
Trigger Event:
release
-
Statement type: