ruff/crates
Charlie Marsh 507961f27d
Emit warnings for invalid # noqa directives (#5571)
## Summary

This PR adds a `ParseError` type to the `noqa` parsing system to enable
us to render useful warnings instead of silently failing when parsing
`noqa` codes.

For example, given `foo.py`:

```python
# ruff: noqa: x

# ruff: noqa foo

# flake8: noqa: F401
import os  # noqa: foo-bar
```

We would now output:

```console
warning: Invalid `# noqa` directive on line 2: expected a comma-separated list of codes (e.g., `# noqa: F401, F841`).
warning: Invalid `# noqa` directive on line 4: expected `:` followed by a comma-separated list of codes (e.g., `# noqa: F401, F841`).
warning: Invalid `# noqa` directive on line 6: Flake8's blanket exemption does not support exempting specific codes. To exempt specific codes, use, e.g., `# ruff: noqa: F401, F841` instead.
warning: Invalid `# noqa` directive on line 7: expected a comma-separated list of codes (e.g., `# noqa: F401, F841`).
```

There's one important behavior change here too. Right now, with Flake8,
if you do `# flake8: noqa: F401`, Flake8 treats that as equivalent to `#
flake8: noqa` -- it turns off _all_ diagnostics in the file, not just
`F401`. Historically, we respected this... but, I think it's confusing.
So we now raise a warning, and don't respect it at all. This will lead
to errors in some projects, but I'd argue that right now, those
directives are almost certainly behaving in an unintended way for users
anyway.

Closes https://github.com/astral-sh/ruff/issues/3339.
2023-07-08 16:37:55 +00:00
..
flake8_to_ruff Bump version to 0.0.277 (#5515) 2023-07-04 17:31:32 -04:00
ruff Emit warnings for invalid # noqa directives (#5571) 2023-07-08 16:37:55 +00:00
ruff_benchmark Create PyFormatOptions 2023-06-26 14:02:17 +02:00
ruff_cache Only use a single cache file per Python package (#5117) 2023-06-19 17:46:13 +02:00
ruff_cli Only run pyproject.toml lint rules when enabled (#5578) 2023-07-08 11:05:05 -04:00
ruff_dev Check formatter stability on CI (#5446) 2023-07-07 18:28:36 +02:00
ruff_diagnostics Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff_formatter Fix typos found by codespell (#5607) 2023-07-08 12:33:18 +02:00
ruff_index Add unreachable code rule (#5384) 2023-07-04 14:27:23 +00:00
ruff_macros Fix remaining Copyright rule references (#5577) 2023-07-07 02:49:19 +00:00
ruff_python_ast Format ExprIfExp (ternary operator) (#5597) 2023-07-07 19:11:52 +00:00
ruff_python_formatter Fix typos found by codespell (#5607) 2023-07-08 12:33:18 +02:00
ruff_python_resolver Fix CI by downgrading to cargo insta 1.29.0 (#5589) 2023-07-08 14:54:49 +00:00
ruff_python_semantic Differentiate between runtime and typing-time annotations (#5575) 2023-07-07 00:21:44 -04:00
ruff_python_stdlib Remove some additional manual iterator matches (#5482) 2023-07-03 16:29:59 +00:00
ruff_python_whitespace Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff_rustpython Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff_textwrap Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff_wasm [pyupgrade] Restore the keep-runtime-typing setting (#5470) 2023-07-03 02:11:31 +00:00