Ignore end-of-line file exemption comments (#6160)

## Summary

This PR protects against code like:

```python
from typing import Optional

import bar  # ruff: noqa
import baz

class Foo:
    x: Optional[str] = None
```

In which the user wrote `# ruff: noqa` to ignore a specific error, not
realizing that it was a file-level exemption that thus turned off all
lint rules.

Specifically, if a `# ruff: noqa` directive is not at the start of a
line, we now ignore it and warn, since this is almost certainly a
mistake.
This commit is contained in:
Charlie Marsh 2023-07-28 20:40:32 -04:00 committed by GitHub
parent e0d5c7564f
commit 646ff6497c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 86 additions and 26 deletions

View file

@ -12,7 +12,7 @@ pub fn indentation<'a, T>(locator: &'a Locator, located: &T) -> Option<&'a str>
where
T: Ranged,
{
indentation_at_offset(locator, located.start())
indentation_at_offset(located.start(), locator)
}
/// Return the end offset at which the empty lines following a statement.