Skip to content

Commit 80f9684

Browse files
authored
man/checkers/variableScope.md: rewrite description and motivation (#8878)
1 parent 112e7e1 commit 80f9684

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

man/checkers/variableScope.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
# variableScope
22

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

88
## Description
99

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

1312
## Motivation
1413

15-
A variable declared too early forces a reader to track its lifetime across code that doesn't use it,
16-
and makes it unclear at a glance which block actually depends on it.
14+
It is common practice, especially in C++ code, to declare variables in inner scope when
15+
possible.
16+
17+
The motivation is to make the code more readable.
18+
19+
Opinions about what is more readable can differ so make your own decisions - these warnings
20+
can be easily suppressed.
1721

1822
## How to fix
1923

0 commit comments

Comments
 (0)