Skip to content

linter: eslint/no-var some case should be dangerous auto-fix #11656

Closed
@CoffeeChaton

Description

@CoffeeChaton

What version of Oxlint are you using?

1.1.0

What command did you run?

oxlint --fix

What does your .oxlintrc.json config file look like?

{
    "$schema": "./node_modules/oxlint/configuration_schema.json",
    "ignorePatterns": [
        "node_modules"
    ],
    "rules": {
        // https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-var.html
        "no-var": "error"
    }
}

What happened?

type TFoo = {
    play: () => void,
};

export class C1 {
    public play(index: number) {
        if (index > 1) {
            var a: TFoo | undefined = {
                play: () => {
                    console.warn("index > 1", index);
                },
            };
        } else {
            var a: TFoo | undefined = {
                play: () => {
                    console.warn("index > 1 , false", index);
                },
            };
        }
        if (a != null) {
            a.play();
        }
    }
}

run oxlint --fix , and get it.

type TFoo = {
    play: () => void,
};

export class C1 {
    public play(index: number) {
        if (index > 1) {
            const a: TFoo | undefined = {
                play: () => {
                    console.warn("index > 1", index);
                },
            };
        } else {
            const a: TFoo | undefined = {
                play: () => {
                    console.warn("index > 1 , false", index);
                },
            };
        }
        if (a != null) {
            a.play();
        }
    }
}

https://github.com/CoffeeChaton/oxlint-no-var-shouldbe-unsafe-fix

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions