inshpect a glorified grep, primarily for C++ code. It can be used as a
poor-man's version of include-what-you-use.
inshpect helps you check for missing license and copyright headers, as well as
for use of names and includes that should or shouldn't be there.
inshpect is written in bash and requires:
- fd, for quickly finding files (with .gitignore taken into account as is the default behaviour of fd)
- ripgrep, for quickly searching files
- dasel version 2, for reading the configuration file (which can be any type supported by dasel (currently toml, yaml, and json))
inshpect [directory to inspect (default: .)] [configuration file (default: ./inshpect.toml)]If violations are found the program exits with a non-zero exit code. Otherwise it exits with zero.
inshpect is configured using a configuration file written in any language that
dasel can read. See the inshpect-example.toml file for an example
configuration. The configuration file should contain the following:
extensions: an array of strings of extensions to be checked.copyright.enable: whentrueenables the copyright check. It checks that the wordcopyrightorCopyrightexists somewhere in the file.license.enable: whentrueenables the license check. It checks that the corresponding pattern exists somewhere in the file.license.pattern(required when the license check is enabled): regex pattern which represents the license text.spdx.enable: whentrueenables the SPDX license identifier check. It checks that the corresponding pattern exists somewhere in the file, preceded bySPDX-License-Identifier.spdx.pattern(required when the license check is enabled): regex pattern which represents the SPDX license identifier.pragma_once.enable: whentrueenables the pragma once check. It checks that the word#pragma onceexists in the file.pragma_once.extensions(required when the pragma once check is enabled): extensions to check for#pragma once. These extensions should represent header files.deprecated_includes.enable: whentrueenables the deprecated includes check. It checks that any pattern given in the patterns does not exist, and suggests the replacement otherwise.deprecated_includes.patterns(required when the deprecated includes check is enabled): array of key-value pairs ofpatternandreplacement, wherepatternrepresents the include that should not be used andreplacementthe replacement include.deprecated_names.enable: whentrueenables the deprecated names check. It checks that any pattern given in the patterns does not exist, and suggests the replacement otherwise.deprecated_names.patterns(required when the deprecated names check is enabled): array of key-value pairs ofpatternandreplacement, wherepatternrepresents the name that should not be used andreplacementthe replacement name.disallowed_macros.enable: whentrueenables the disallowed macros check. It checks that any pattern given in the patterns does not exist.disallowed_macros.patterns(required when the disallowed macros check is enabled): array of macros that should not exist.includes.enable: whentrueenables the includes check. It checks that if any pattern given in the patterns exists, the corresponding include should also exist. This is a poor-man's include-what-you-use.includes.patterns(required when the includes check is enabled): array of key-value pairs ofpatternandinclude, wherepatternrepresents the name that should have the correspondinginclude.
See pika for an example of slightly more involved configuration files.
inshpect can further be controlled by the following environment variables:
INSHPECT_RG: the name of the ripgrep executable, defaults torgINSHPECT_FD: the name of the fd executable, defaults tofdINSHPECT_DASEL: the name of the dasel executable, defaults todaselINSHPECT_NUMTHREADS: the number of threads to use inripgrepandfd, defaults to1INSHPECT_VERBOSE: when set to1(exactly!) prints each pattern thatinshpectchecks
This is a very minimally viable piece of software and is missing a lot of polish. Maybe it shouldn't have been written in bash. If you find something that you'd like to see improved, please open an issue or even better a pull request! Non-exhaustive list of current limitations:
- Almost all configuration options must be present in the config file, there are
no fallback values. The
patternkeys can be omitted if the corresponding check is disabled. - Speed! ripgrep and fd are very fast, but especially the includes check can be very slow when there are many patterns and can likely be sped up.
- There is no possibilty for new checks to be defined in the config file, although one can probably abuse the existing checkers to check for things they weren't intended for.
- Files without extensions are not supported.
inshpect is a simplified version of the Boost inspect
tool, also used in
modified forms in HPX and (previously)
pika, and owes its existence to those tools.