-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
bugSomething isn't workingSomething isn't workingsuppressionRelated to supression of violations e.g. noqaRelated to supression of violations e.g. noqa
Description
Take the following code snippet:
assert foo, \
"""triple-quoted
string"""Running the following command repeatedly:
$ ruff check --no-cache --isolated --select=F821 fstring.py --add-noqa
Added 1 noqa directive.
$ ruff check --no-cache --isolated --select=F821 fstring.py --add-noqa
Added 1 noqa directive.
...It keeps on adding the noqa directive inside the first line of the string:
assert foo, \
"""triple-quoted # noqa: F821 # noqa: F821
string"""I think the problem is in the way the range is being pushed onto the NoQA mapping in the following code:
Lines 764 to 777 in dcbd8ea
| pub(crate) fn push_mapping(&mut self, range: TextRange) { | |
| if let Some(last_range) = self.ranges.last_mut() { | |
| // Strictly sorted insertion | |
| if last_range.end() <= range.start() { | |
| // OK | |
| } | |
| // Try merging with the last inserted range | |
| else if let Some(intersected) = last_range.intersect(range) { | |
| *last_range = intersected; | |
| return; | |
| } else { | |
| panic!("Ranges must be inserted in sorted order") | |
| } | |
| } |
- The
<=doesn't make it strict - We should use the union range instead of intersected range
So,
pub(crate) fn push_mapping(&mut self, range: TextRange) {
if let Some(last_range) = self.ranges.last_mut() {
// Strictly sorted insertion
if last_range.end() < range.start() {
// OK
} else if range.end() < last_range.start() {
panic!("Ranges must be inserted in sorted order")
} else {
*last_range = last_range.cover(range);
return;
}
}
self.ranges.push(range);
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingsuppressionRelated to supression of violations e.g. noqaRelated to supression of violations e.g. noqa