The rule checks if declarations of local variables can be changed from var to let or const and from let to const. The syntax in a configuration file is:
[ruleType] ?not? varUplevel
- ruleType is the type of rule which will be executed. Proper values are:
check, search, count and fix. For more information about the types of
rules, please refer to the program's documentation. Check type will raise
error when the declaration of the variable can be changed into let or
const. Search type will list all declarations which can be updated and
count type will show the amount of variables' declarations which can be
updated. Fix type will try to update the type of the variable declaration,
for example,
var i = 1
will be updated tolet i = 1
. If variable was in a declaration block, it will be moved to a new declaration above the current position. It may produce an invalid code, especially if the variable's declaration depends on a previous declaration in the same block. - optional word not means negation for the rule. Adding word not will change to inform only about variables' declarations, which can't be updated to let or const.
- varUplevel is the name of the rule. It is case-insensitive, thus it can be set as varuplevel, varUplevel or vArUpLeVeL.
Disabling the rule
It is possible to disable the rule for a selected part of the checked code
by using pragma ruleOff: "varUplevel" in the element from which the rule
should be disabled or in code before it. For example, if the rule should
be disabled for variable var i = 1
, the full declaration of it can be:
var i {.ruleOff: "varUplevel".} = 1
To enable the rule again, the pragma ruleOn: "varUplevel" should be added in
the element which should be checked or in the code before it. For example,
if the rule should be re-enabled for const a = 1
, the full declaration
should be:
const a {.ruleOn: "varUplevel".} = 1
Examples
Check if any declaration of local variable can be updated::
check varUplevel
Search for declarations of local variables which can't be updated:
search not varUplevel