Detect noqa directives for multi-line f-strings#7326
Merged
dhruvmanila merged 4 commits intodhruv/pep-701from Sep 21, 2023
Merged
Detect noqa directives for multi-line f-strings#7326dhruvmanila merged 4 commits intodhruv/pep-701from
noqa directives for multi-line f-strings#7326dhruvmanila merged 4 commits intodhruv/pep-701from
Conversation
This was referenced Sep 13, 2023
Member
Author
This was referenced Sep 13, 2023
d7e004e to
d018b5b
Compare
eeadcac to
f1e192f
Compare
d018b5b to
79c5a1a
Compare
fbcedf2 to
9c4d048
Compare
9c4d048 to
0a404ec
Compare
0a404ec to
cc91933
Compare
dhruvmanila
commented
Sep 14, 2023
crates/ruff/src/directives.rs
Outdated
Comment on lines
110
to
112
| // SAFETY: If we're at the end of a f-string, the indexer must have a | ||
| // corresponding f-string range for it. | ||
| let f_string_start = indexer.f_string_range(range.start()).unwrap().start(); |
Member
Author
There was a problem hiding this comment.
There's a slight performance penalty here as not many single quoted f-strings are going to be multi-line but we can't really know that until we get the entire f-string range.
MichaReiser
reviewed
Sep 14, 2023
db4992a to
101f9be
Compare
7f349c5 to
e01be7c
Compare
b2cbb1a to
4d96b57
Compare
e01be7c to
08eebaa
Compare
4d96b57 to
1aa2390
Compare
08eebaa to
cd374e8
Compare
dhruvmanila
added a commit
that referenced
this pull request
Sep 21, 2023
## Summary
This PR updates the NoQA directive detection to consider the new
f-string tokens.
The reason being that now there can be multi-line f-strings without
triple-quotes:
```python
f"{
x
*
y
}"
```
Here, the `noqa` directive should go at the end of the last line.
## Test Plan
* Add new test cases for f-strings
* Tested with `--add-noqa` using the following command with the above
code snippet:
```console
$ cargo run --bin ruff -- check --select=F821 --no-cache --isolated
~/playground/ruff/fstring.py --add-noqa
Added 1 noqa directive.
```
Output:
```python
f"{
x
*
y
}" # noqa: F821
```
Running the same command again doesn't add `noqa` directive and without
the `--add-noqa` flag, the violation isn't reported.
fixes: #7291
dhruvmanila
added a commit
that referenced
this pull request
Sep 22, 2023
## Summary
This PR updates the NoQA directive detection to consider the new
f-string tokens.
The reason being that now there can be multi-line f-strings without
triple-quotes:
```python
f"{
x
*
y
}"
```
Here, the `noqa` directive should go at the end of the last line.
## Test Plan
* Add new test cases for f-strings
* Tested with `--add-noqa` using the following command with the above
code snippet:
```console
$ cargo run --bin ruff -- check --select=F821 --no-cache --isolated
~/playground/ruff/fstring.py --add-noqa
Added 1 noqa directive.
```
Output:
```python
f"{
x
*
y
}" # noqa: F821
```
Running the same command again doesn't add `noqa` directive and without
the `--add-noqa` flag, the violation isn't reported.
fixes: #7291
dhruvmanila
added a commit
that referenced
this pull request
Sep 22, 2023
## Summary
This PR updates the NoQA directive detection to consider the new
f-string tokens.
The reason being that now there can be multi-line f-strings without
triple-quotes:
```python
f"{
x
*
y
}"
```
Here, the `noqa` directive should go at the end of the last line.
## Test Plan
* Add new test cases for f-strings
* Tested with `--add-noqa` using the following command with the above
code snippet:
```console
$ cargo run --bin ruff -- check --select=F821 --no-cache --isolated
~/playground/ruff/fstring.py --add-noqa
Added 1 noqa directive.
```
Output:
```python
f"{
x
*
y
}" # noqa: F821
```
Running the same command again doesn't add `noqa` directive and without
the `--add-noqa` flag, the violation isn't reported.
fixes: #7291
This was referenced Sep 22, 2023
dhruvmanila
added a commit
that referenced
this pull request
Sep 22, 2023
## Summary
This PR updates the NoQA directive detection to consider the new
f-string tokens.
The reason being that now there can be multi-line f-strings without
triple-quotes:
```python
f"{
x
*
y
}"
```
Here, the `noqa` directive should go at the end of the last line.
## Test Plan
* Add new test cases for f-strings
* Tested with `--add-noqa` using the following command with the above
code snippet:
```console
$ cargo run --bin ruff -- check --select=F821 --no-cache --isolated
~/playground/ruff/fstring.py --add-noqa
Added 1 noqa directive.
```
Output:
```python
f"{
x
*
y
}" # noqa: F821
```
Running the same command again doesn't add `noqa` directive and without
the `--add-noqa` flag, the violation isn't reported.
fixes: #7291
dhruvmanila
added a commit
that referenced
this pull request
Sep 26, 2023
## Summary
This PR updates the NoQA directive detection to consider the new
f-string tokens.
The reason being that now there can be multi-line f-strings without
triple-quotes:
```python
f"{
x
*
y
}"
```
Here, the `noqa` directive should go at the end of the last line.
## Test Plan
* Add new test cases for f-strings
* Tested with `--add-noqa` using the following command with the above
code snippet:
```console
$ cargo run --bin ruff -- check --select=F821 --no-cache --isolated
~/playground/ruff/fstring.py --add-noqa
Added 1 noqa directive.
```
Output:
```python
f"{
x
*
y
}" # noqa: F821
```
Running the same command again doesn't add `noqa` directive and without
the `--add-noqa` flag, the violation isn't reported.
fixes: #7291
dhruvmanila
added a commit
that referenced
this pull request
Sep 27, 2023
## Summary
This PR updates the NoQA directive detection to consider the new
f-string tokens.
The reason being that now there can be multi-line f-strings without
triple-quotes:
```python
f"{
x
*
y
}"
```
Here, the `noqa` directive should go at the end of the last line.
## Test Plan
* Add new test cases for f-strings
* Tested with `--add-noqa` using the following command with the above
code snippet:
```console
$ cargo run --bin ruff -- check --select=F821 --no-cache --isolated
~/playground/ruff/fstring.py --add-noqa
Added 1 noqa directive.
```
Output:
```python
f"{
x
*
y
}" # noqa: F821
```
Running the same command again doesn't add `noqa` directive and without
the `--add-noqa` flag, the violation isn't reported.
fixes: #7291
dhruvmanila
added a commit
that referenced
this pull request
Sep 28, 2023
## Summary
This PR updates the NoQA directive detection to consider the new
f-string tokens.
The reason being that now there can be multi-line f-strings without
triple-quotes:
```python
f"{
x
*
y
}"
```
Here, the `noqa` directive should go at the end of the last line.
## Test Plan
* Add new test cases for f-strings
* Tested with `--add-noqa` using the following command with the above
code snippet:
```console
$ cargo run --bin ruff -- check --select=F821 --no-cache --isolated
~/playground/ruff/fstring.py --add-noqa
Added 1 noqa directive.
```
Output:
```python
f"{
x
*
y
}" # noqa: F821
```
Running the same command again doesn't add `noqa` directive and without
the `--add-noqa` flag, the violation isn't reported.
fixes: #7291
dhruvmanila
added a commit
that referenced
this pull request
Sep 29, 2023
## Summary
This PR updates the NoQA directive detection to consider the new
f-string tokens.
The reason being that now there can be multi-line f-strings without
triple-quotes:
```python
f"{
x
*
y
}"
```
Here, the `noqa` directive should go at the end of the last line.
## Test Plan
* Add new test cases for f-strings
* Tested with `--add-noqa` using the following command with the above
code snippet:
```console
$ cargo run --bin ruff -- check --select=F821 --no-cache --isolated
~/playground/ruff/fstring.py --add-noqa
Added 1 noqa directive.
```
Output:
```python
f"{
x
*
y
}" # noqa: F821
```
Running the same command again doesn't add `noqa` directive and without
the `--add-noqa` flag, the violation isn't reported.
fixes: #7291
dhruvmanila
added a commit
that referenced
this pull request
Sep 29, 2023
## Summary
This PR updates the NoQA directive detection to consider the new
f-string tokens.
The reason being that now there can be multi-line f-strings without
triple-quotes:
```python
f"{
x
*
y
}"
```
Here, the `noqa` directive should go at the end of the last line.
## Test Plan
* Add new test cases for f-strings
* Tested with `--add-noqa` using the following command with the above
code snippet:
```console
$ cargo run --bin ruff -- check --select=F821 --no-cache --isolated
~/playground/ruff/fstring.py --add-noqa
Added 1 noqa directive.
```
Output:
```python
f"{
x
*
y
}" # noqa: F821
```
Running the same command again doesn't add `noqa` directive and without
the `--add-noqa` flag, the violation isn't reported.
fixes: #7291
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
This PR updates the NoQA directive detection to consider the new f-string tokens.
The reason being that now there can be multi-line f-strings without triple-quotes:
Here, the
noqadirective should go at the end of the last line.Test Plan
Add new test cases for f-strings
Tested with
--add-noqausing the following command with the above code snippet:Output:
Running the same command again doesn't add
noqadirective and without the--add-noqaflag, the violation isn't reported.fixes: #7291