The rule to check do assignments in the code follow some design patterns. Checked things:
- Do assignment is or not a shorthand assignment
The syntax in a configuration file is:
[ruleType] ?not? assignments [checkType]
- 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 an error if there is an assignment which violates any of the checks. Search type will list all assignments which violates any of checks or raise an error if nothing found. Count type will simply list the amount of the assignments which violates the checks. Fix type will try to upgrade the assignment to meet the rule settings. For example, it will ugprade the assignment to a shorthand assignment or replace by full if negation was used.
- optional word not means negation for the rule. Adding word not will change to inform only about assignments which not violate the checks. For example, it will raise an error when check type find a shorthand assignment.
- assignments is the name of the rule. It is case-insensitive, thus it can be set as assignments, assignments or aSsIgNmEnTs.
- checkType is the type of checks to perform on the assignments. Proper value is: shorthand. It will check if all assignments are shorthand assignments.
Disabling the rule
It is possible to disable the rule for a selected part of the checked code
by using pragma ruleOff: "assignments" in the element in code before it.
For example, if the rule should be disabled for assignment i = i + 1
, the
full declaration of it should be:
{.ruleOff: "assignments".}
i = i + 1
To enable the rule again, the pragma ruleOn: "assignments" should be added in
the code before it. For example, if the rule should be re-enabled for a += 1
,
the full declaration should be:
{.ruleOn: "assignments".}
a += 1
Examples
Check if all assignments in the code are shorthand assignments:
check assignments shorthand
Replace all shorthand assignments in the code with full assignments:
fix not assignments shorthand