CQM-IncludeLie

Unused includes

Required inputs: IR

A file or library is included, but not used anywhere and can be removed.
Motivation

Individual files or entire libraries are included in the source code, although they are not referenced at all. These unnecessary includes do not change the behavior of the system, but increase the demands on the build process. All listed files or libraries must be available for a successful build. In addition, an import lie creates the false impression of a dependency between included and including file.

This rule is based on the CQM Quality Indicator: Importlüge (p. 219-221).

Reference

Simon, Frank/ Seng, Olaf/ Mohaupt, Thomas (2006): Code-Quality-Management: Technische Qualität industrieller Softwaresysteme transparent und vergleichbar gemacht, 1st ed., Heidelberg, Germany: dpunkt.verlag GmbH.

Possible Messages

Key

Text

Severity

Disabled

contents_covered_include

#include {inc} can be removed as it only provides symbols covered by other #include(s)

None

False

more_precise_include

#include {inc} can be replaced with #include {srcfile}

None

False

move_include

#include {inc} can be moved into {srcfile}

None

False

move_include_with_many_clients

#include {inc} is unused locally, but there are many other files possibly relying on it

None

False

unused_include

#include {inc} can be removed as file does not use anything from it

None

False

Options

accept_incomplete_arguments

accept_incomplete_arguments

Type: list[bauhaus.analysis.config.ShortTypeName]

Default: ['shared_ptr', 'unique_ptr', 'weak_ptr', 'auto_ptr', 'default_delete', 'enable_shared_from_this', 'list', 'forward_list', 'vector', 'allocator', 'polymorphic_allocator', 'is_void', 'is_null_pointer', 'is_integral', 'is_floating_point', 'is_array', 'is_pointer', 'is_lvalue_reference', 'is_rvalue_reference', 'is_member_object_pointer', 'is_member_function_pointer', 'is_enum', 'is_union', 'is_class', 'is_function', 'is_reference', 'is_arithmetic', 'is_fundamental', 'is_object', 'is_scalar', 'is_compound', 'is_member_pointer', 'is_const', 'is_volatile', 'is_signed', 'is_unsigned', 'rank', 'extent', 'is_same', 'remove_const', 'remove_volatile', 'remove_cv', 'add_const', 'add_volatile', 'add_cv', 'remove_reference', 'add_lvalue_reference', 'add_rvalue_reference', 'make_signed', 'make_unsigned', 'remove_extent', 'remove_all_extents', 'remove_pointer', 'add_pointer', 'decay', 'enable_if', 'conditional']

Names of templates for which incomplete types should be accepted as allowed template type arguments (so forward declarations of these arguments are enough to instantiate the template).
 

avoid_uncertain_messages

avoid_uncertain_messages : bool = True

Whether messages should be omitted if they are tagged as uncertain due to possibly unknown symbol references in templates.
 

context_macros

context_macros : list[str] = []

List of macro names which are intentionally not defined inside a file or in files included from it. The names can contain regexp patterns.
 

enums_can_be_redeclared

enums_can_be_redeclared : bool = False

Whether local redeclarations of enums should be allowed to avoid #includes.
 

interface_headers

interface_headers : list[bauhaus.analysis.config.FileGlobPattern] = []

Globbing patterns for files which should be seen as ok although they might just #include files without using them. #includes to these interface files are also treated as ok.
 

limit_for_moving

limit_for_moving : int = 3

If an include is unused locally, but used in client files or inside subsequently included headers, this limit determines the maximum number of such target files up to which a Move_Include suggestion will be generated; if there are too many target files, a Move_Include_With_Many_Clients will be reported instead.
 

limit_for_replacing

limit_for_replacing : int = 3

If an include can be replaced by forward declarations and other, more precise #includes covering only parts of the previous #include, this limit determines the maximum number of such replacements up to which such a suggestion is generated; if there are too many replacements, the include is accepted instead.
 

routines_can_be_redeclared

routines_can_be_redeclared : bool = False

Whether local redeclarations of functions should be allowed to avoid #includes.
 

typedefs_can_be_redeclared

typedefs_can_be_redeclared : bool = False

Whether local redeclarations of typedefs should be allowed to avoid #includes.