eslint/no-unassigned-vars Correctness
What it does
Disallow let or var variables that are read but never assigned.
Ignored Files
This rule ignores .svelte and .vue files entirely. Oxlint only parses the <script> blocks of these files, so a binding that the template assigns looks like it is never assigned. In Svelte the template writes through bind:this={el} and bind:value={x}; in Vue a <script setup> let is a setup-let binding that v-model="x" and inline handlers such as @click="x = 1" assign to directly.
Why is this bad?
This rule flags let or var declarations that are never assigned a value but are still read or used in the code. Since these variables will always be undefined, their usage is likely a programming mistake.
Examples
Examples of incorrect code for this rule:
let status;
if (status === "ready") {
console.log("Ready!");
}Examples of correct code for this rule:
let message = "hello";
console.log(message);
let user;
user = getUser();
console.log(user.name);How to use
To enable this rule using the config file or in the CLI, you can use:
{
"rules": {
"no-unassigned-vars": "error"
}
}import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"no-unassigned-vars": "error",
},
});oxlint --deny no-unassigned-varsVersion
This rule was added in v1.10.0.
