Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions man/checkers/variableScope.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
# variableScope

**Message**: The scope of the variable 'x' can be reduced.<br/>
**Category**: Code Quality<br/>
**Category**: Readability<br/>
**Severity**: Style<br/>
**Language**: C/C++

## Description

A variable is declared in an outer scope than where it's actually used - narrowing its declaration to
the innermost block that needs it makes the code easier to follow.
A variable is declared in an outer scope, it can be declared in an inner scope.

## Motivation

A variable declared too early forces a reader to track its lifetime across code that doesn't use it,
and makes it unclear at a glance which block actually depends on it.
It is common practice, especially in C++ code, to declare variables in inner scope when
possible.

The motivation is to make the code more readable.

Opinions about what is more readable can differ so make your own decisions - these warnings
can be easily suppressed.

## How to fix

Expand Down
Loading