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

Unnecessary semicolon fix removes subsequent lines #6214

Closed
Tracked by #4972
addisoncrump opened this issue Jul 31, 2023 · 1 comment · Fixed by #6219
Closed
Tracked by #4972

Unnecessary semicolon fix removes subsequent lines #6214

addisoncrump opened this issue Jul 31, 2023 · 1 comment · Fixed by #6219
Assignees
Labels
bug Something isn't working

Comments

@addisoncrump
Copy link
Contributor

Consider the following snippet:

a = \
  5;

We would expect that the (admittedly contrived example) would be corrected to:

a = \
  5

Instead, it is corrected to:

a =

This completely removes the second half of the expression on the continuation.

thread '<unnamed>' panicked at 'Fixed source has a syntax error where the source document does not. This is a bug in one of the generated fixes:
<filename>:1:5: E999 SyntaxError: Unexpected token Newline
  |
1 | a = 
  |     ^ E999
  |


Last generated fixes:
<filename>:2:4: E703 [*] Statement ends with an unnecessary semicolon
  |
1 | a = \
2 |   5;
  |    ^ E703
  |
  = help: Remove unnecessary semicolon

ℹ Fix
1   |-a = \
2   |-  5;
  1 |+a = 


Source with applied fixes:
a = 
', /home/addisoncrump/git/ruff/crates/ruff/src/test.rs:202:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Aborted
@addisoncrump
Copy link
Contributor Author

Note that this happens in a variety of scenarios:

(\
);

And so on.

@charliermarsh charliermarsh self-assigned this Aug 1, 2023
@charliermarsh charliermarsh added the bug Something isn't working label Aug 1, 2023
charliermarsh added a commit that referenced this issue Aug 1, 2023
## Summary

Previously, given:

```python
a = \
  5;
```

When detecting continuations starting at the offset of the `;`, we'd
flag the previous line as a continuation. We should only flag a
continuation if there isn't leading content prior to the offset.

Closes #6214
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.

2 participants