Code action DR007
(Readability) Simplify 1-variable block
Description
A variable block with only one variable can be simplified by moving the expression directly into the RETURN
part of the block. This assumes the variable is only referenced once without any context modifiers.
Example
Change:
VAR _sales = [Total Sales]
RETURN
_sales * 1.25
To:
[Total Sales] * 1.25
Why is Tabular Editor suggesting this?
When variable declarations are sufficiently simple, and when the variable is used exactly once in the RETURN
part of the code without any context modifications, there is no need to declare the variable at all. This makes the code more concise and easier to read.