Block usage of for loops directly overwriting the indexing variable
Source:R/for_loop_index_linter.R
for_loop_index_linter.Rd
for (x in x)
is a poor choice of indexing variable. This overwrites
x
in the calling scope and is confusing to read.
See also
linters for a complete list of linters available in lintr.
Examples
# will produce lints
lint(
text = "for (x in x) { TRUE }",
linters = for_loop_index_linter()
)
#> <text>:1:6: warning: [for_loop_index_linter] Don't re-use any sequence symbols as the index symbol in a for loop.
#> for (x in x) { TRUE }
#> ^
lint(
text = "for (x in foo(x, y)) { TRUE }",
linters = for_loop_index_linter()
)
#> <text>:1:6: warning: [for_loop_index_linter] Don't re-use any sequence symbols as the index symbol in a for loop.
#> for (x in foo(x, y)) { TRUE }
#> ^
# okay
lint(
text = "for (xi in x) { TRUE }",
linters = for_loop_index_linter()
)
#> ℹ No lints found.
lint(
text = "for (col in DF$col) { TRUE }",
linters = for_loop_index_linter()
)
#> ℹ No lints found.