for_loop_index_linter: Block usage of for loops directly overwriting the indexing...

for_loop_index_linterR Documentation

Block usage of for loops directly overwriting the indexing variable

Description

⁠for (x in x)⁠ is a poor choice of indexing variable. This overwrites x in the calling scope and is confusing to read.

Usage

for_loop_index_linter()

Tags

best_practices, readability, robustness

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()
)

lint(
  text = "for (x in foo(x, y)) { TRUE }",
  linters = for_loop_index_linter()
)

# okay
lint(
  text = "for (xi in x) { TRUE }",
  linters = for_loop_index_linter()
)

lint(
  text = "for (col in DF$col) { TRUE }",
  linters = for_loop_index_linter()
)


r-lib/lintr documentation built on Dec. 20, 2024, 7:24 p.m.