Skip to content

linter: no-loop-func errors incorrectly on catch variable #24315

Description

@copperwall

What version of Oxlint are you using?

1.73.0

What command did you run?

oxlint

What does your .oxlintrc.json (or oxlint.config.ts) config file look like?

{
  "$schema": "./node_modules/oxlint/configuration_schema.json",
  "plugins": [
    "typescript",
    "unicorn",
    "oxc"
  ],
  "categories": {
    "correctness": "error"
  },
  "rules": {
    "no-loop-func": "error"
  },
  "env": {
    "builtin": true
  }
}

What happened?

Minimum reproduction repository: https://github.com/copperwall/oxc-no-func-loop-catch-variable-min-repro

I noticed that I was getting a no-loop-func error when referencing a catch variable within a function within a loop. I believe this should be okay because catch variables are scoped to the catch block and shouldn't be hoisted outside of the loop.

Example file

for (let i = 0; i < 10; i++) {
  try {
  } catch (e) {
    setTimeout(() => {
      // e is scoped to the catch block, so it shouldn't be shared between loop iterations
      console.log(e);
    })
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Fields

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions