Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Autofix error] Invalid code produce autofix error #3622

Closed
qarmin opened this issue Mar 20, 2023 · 6 comments · Fixed by #3665
Closed

[Autofix error] Invalid code produce autofix error #3622

qarmin opened this issue Mar 20, 2023 · 6 comments · Fixed by #3665
Assignees
Labels
bug Something isn't working

Comments

@qarmin
Copy link

qarmin commented Mar 20, 2023

Ruff a45753f

# flake8: noqa: F405
fom opts import *  # noqa

with

ruff file.py --fix
error: Autofix introduced a syntax error. Reverting all changes.

This indicates a bug in `ruff`. If you could open an issue at:

    https://github.com/charliermarsh/ruff/issues/new?title=%5BAutofix%20error%5D

...quoting the contents of `Desktop/RunEveryCommand/Ruff/Broken/94966__init__ (9 413th copy)0.py`, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!
@charliermarsh charliermarsh added the bug Something isn't working label Mar 20, 2023
@JonathanPlasse

This comment was marked as off-topic.

@charliermarsh
Copy link
Member

It might be a bug that we're considering that noqa to be unused though, it should be suppressing an E999 error...? Not sure why that's not getting raised here.

@JonathanPlasse
Copy link
Contributor

I think # noqa should never suppress E999, that seems to be the problem.

@charliermarsh
Copy link
Member

I think it should, that was used as a workaround for a while for match statement. But we're raising a RUF100, then fixing that, then Ruff thinks we introduced a syntax error.

@charliermarsh
Copy link
Member

Ahh, the issue is # flake8: noqa: F405. That suppress all errors, just like in Flake8.

@charliermarsh
Copy link
Member

The issue is here:

Err(parse_error) => {
    if settings.rules.enabled(Rule::SyntaxError) {
        pycodestyle::rules::syntax_error(&mut diagnostics, &parse_error);
    }

    // If the syntax error is ignored, suppress it (regardless of whether
    // `Rule::SyntaxError` is enabled).
    if !rule_is_ignored(
        Rule::SyntaxError,
        parse_error.location.row(),
        &directives.noqa_line_for,
        locator,
    ) {
        error = Some(parse_error);
    }
}

That needs to respect the whole file ignores, not just the inline ignores.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants