Skip to main content

Sort #include directives of C/C++ files

Project description

cpp-include-lint

Since I was tired of having a messy bunch of #include at the top of my C++ sources I decided to do a script that sorts the #include lines of C/C++ files with a fair criterion.

The sorting precedence between #include lines is the following:

  1. header with the same name as this source file
  2. headers between square brackets (<>), alphabetically
  3. headers between quotes (""), alphabetically

e.g.

database.cpp

#include "database.h"
#include <iostream>
#include <string>
#include <unordered_set>
#include <vector>
#include "arguments.h"
#include "logger.h"
#include "manager.h"
#include "timer.h"

INSTALLATION

pip install cpp-include-lint

USAGE

usage: cpp-include-lint [-h] [-r] [-d] [-f REGEX] [-q] input [output]

Sort #include directives of C/C++ files.

positional arguments:
  input                 input path
  output                output path

optional arguments:
  -h, --help            show this help message and exit
  -r, -R, --recursive   lint all the files in the input folder recursively
  -d, --dry-run         just print the files that would have been linted
  -f REGEX, --filter REGEX
                        filter files to lint using the given regular expression. 
                        The default one is: ".*\.(h|hpp|c|cpp|tpp)"
  -q, --quiet           suppress information messages

EXAMPLES

  • Lint a single source file in place
cpp-include-lint main.cpp
  • Lint a single source file writing to another file
cpp-include-lint main.cpp /tmp/main.cpp
  • Lint an entire directory recursively in place
cpp-include-lint /home/user/develop/project/src -R
  • Lint an entire directory recursively to another directory
cpp-include-lint /home/user/develop/project/src /tmp/src -R
  • Lint an entire directory recursively in place using a different file filter
cpp-include-lint /home/user/develop/project/src -R -f ".*\.(hxx|cxx)"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

cpp_include_lint-0.2-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file cpp_include_lint-0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for cpp_include_lint-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 80fe9f73e26a90e3789031590edf42edc55686cc964f14c2b1a17b798fee147a
MD5 c3f6e40f2c53291e75b0b2f82e6bd00e
BLAKE2b-256 d14367be00a29f9d1cf2476b51f3e192d256bb38654d47b61b0fff39a8445b97

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page