Skip to content

[Linting Rule] Useless Loop

github-actions[bot] edited this page Nov 8, 2026 · 1 revision

Generated from 'wiki-linter.ts' on 2026-10-27, 10:46:55 UTC (v2.16.6), do not edit directly.

Useless Loops [overview]

smell readability

This rule is a best-effort rule.

Finds loops that iterate only once.
This linting rule is implemented in src/linter/rules/useless-loop.ts.

Configuration

Linting rules can be configured by passing a configuration object to the linter query as shown in the example below. The useless-loop rule accepts the following configuration options:

Examples

for(i in c(1)) { print(i) }

The linting query can be used to run this rule on the above example:

[ { "type": "linter",   "rules": [ { "name": "useless-loop",     "config": {} } ] } ]

Results (prettified and summarized):

Query: linter (2 ms)
   ╰ Useless Loops (useless-loop):
       ╰ certain:
           ╰ for-loop at 1.1-27 only loops once

More examples are the test cases in test/functionality/linter/lint-useless-loop.test.ts.

Clone this wiki locally

⌂ 换网址