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

ERA001 does not detect commented out case statements #10031

Closed
dosisod opened this issue Feb 18, 2024 · 2 comments · Fixed by #10055
Closed

ERA001 does not detect commented out case statements #10031

dosisod opened this issue Feb 18, 2024 · 2 comments · Fixed by #10055
Labels
bug Something isn't working good first issue Good for newcomers help wanted Contributions especially welcome

Comments

@dosisod
Copy link
Contributor

dosisod commented Feb 18, 2024

Commented out case statements are ignored if they are missing a body, or have a body and fit on one line:

match 1:
    # case 1:          # commented code ignored
    # case 1: print()  # commented code ignored

    case 1:
        pass
        # print()  # commented code found

# if 1: print()  # commented code found

if 1:
    pass
    # print()  # commented code found

Running:

$ ruff --version
ruff 0.2.2

$ ruff file.py --output-format=concise
file.py:7:9: ERA001 Found commented-out code
file.py:9:1: ERA001 Found commented-out code
file.py:13:5: ERA001 Found commented-out code

The first 2 case blocks should be counted but aren't. Often times I will duplicate and comment out a case statement to figure out why a pattern isn't matching, only to forget to remove the commented out case.

The example with the case/body on one line is less of an issue but still odd, perhaps the case statement is preventing the body from being detected.

@MichaReiser
Copy link
Member

Thanks for the report.

I think we need to extend the POSITIVE_CASES to handle case

Playground: https://play.ruff.rs/5a305aa9-6e5c-4fa4-999a-8fc427ab9a23

@MichaReiser MichaReiser added bug Something isn't working help wanted Contributions especially welcome good first issue Good for newcomers labels Feb 19, 2024
@ottaviohartman
Copy link
Contributor

@MichaReiser opened my first PR for this! Let me know how it looks

charliermarsh pushed a commit that referenced this issue Feb 20, 2024
…e support (#10055)

## Summary

Closes #10031 

- Detect commented out `case` statements. Playground repro:
https://play.ruff.rs/5a305aa9-6e5c-4fa4-999a-8fc427ab9a23
- Add more support for one-line commented out code.

## Test Plan

Unit tested and tested with
```sh
cargo run -p ruff -- check crates/ruff_linter/resources/test/fixtures/eradicate/ERA001.py --no-cache --preview --select ERA001
```

TODO:
- [x] `cargo insta test`
nkxxll pushed a commit to nkxxll/ruff that referenced this issue Mar 10, 2024
…e support (astral-sh#10055)

## Summary

Closes astral-sh#10031 

- Detect commented out `case` statements. Playground repro:
https://play.ruff.rs/5a305aa9-6e5c-4fa4-999a-8fc427ab9a23
- Add more support for one-line commented out code.

## Test Plan

Unit tested and tested with
```sh
cargo run -p ruff -- check crates/ruff_linter/resources/test/fixtures/eradicate/ERA001.py --no-cache --preview --select ERA001
```

TODO:
- [x] `cargo insta test`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Contributions especially welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants