ruff/crates
Silvano Cerza 82410524d9
[pylint] Implement Pylint bad-format-character (E1300) (#6171)
## Summary

Relates to #970.

Add new `bad-format-character` Pylint rule.

I had to make a change in `crates/ruff_python_literal/src/format.rs` to
get a more detailed error in case the format character is not correct. I
chose to do this since most of the format spec parsing functions are
private. It would have required me reimplementing most of the parsing
logic just to know if the format char was correct.

This PR also doesn't reflect current Pylint functionality in two ways.

It supports new format strings correctly, Pylint as of now doesn't. See
pylint-dev/pylint#6085.

In case there are multiple adjacent string literals delimited by
whitespace the index of the wrong format char will relative to the
single string. Pylint will instead reported it relative to the
concatenated string.

Given this:
```
"%s" "%z" % ("hello", "world")
```

Ruff will report this:
```Unsupported format character 'z' (0x7a) at index 1```

Pylint instead:
```Unsupported format character 'z' (0x7a) at index 3```

I believe it's more sensible to report the index relative to the
individual string.

## Test Plan

Added new snapshot and a small test in
`crates/ruff_python_literal/src/format.rs`.

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2023-08-02 21:32:43 +00:00
..
flake8_to_ruff Bump version to 0.0.282 (#6241) 2023-08-01 13:21:33 +00:00
ruff [pylint] Implement Pylint bad-format-character (E1300) (#6171) 2023-08-02 21:32:43 +00:00
ruff_benchmark Remove Parse trait (#6235) 2023-08-01 18:35:03 +02:00
ruff_cache Only use a single cache file per Python package (#5117) 2023-06-19 17:46:13 +02:00
ruff_cli Replace .map_or(false, $closure) with .is_some_and(closure) (#6244) 2023-08-01 19:29:42 +02:00
ruff_dev Fix links in docs (#6265) 2023-08-02 09:42:25 +02:00
ruff_diagnostics Skip partial duplicates when applying multi-edit fixes (#6144) 2023-07-29 12:11:57 +00:00
ruff_formatter Replace .map_or(false, $closure) with .is_some_and(closure) (#6244) 2023-08-01 19:29:42 +02:00
ruff_index Add unreachable code rule (#5384) 2023-07-04 14:27:23 +00:00
ruff_macros Remove parser dependency from ruff-python-ast (#6096) 2023-07-26 17:47:22 +02:00
ruff_python_ast Add formatting of type parameters in class and function definitions (#6161) 2023-08-02 20:29:28 +00:00
ruff_python_codegen Add a TypeParams node to the AST (#6261) 2023-08-02 14:12:45 +00:00
ruff_python_formatter Add formatting of type alias statements (#6162) 2023-08-02 20:40:32 +00:00
ruff_python_index Avoid detecting continuations at non-start-of-line (#6219) 2023-08-01 00:20:29 -04:00
ruff_python_literal [pylint] Implement Pylint bad-format-character (E1300) (#6171) 2023-08-02 21:32:43 +00:00
ruff_python_parser Box type params and arguments fields on the class definition node (#6275) 2023-08-02 16:47:06 +00:00
ruff_python_resolver Replace .map_or(false, $closure) with .is_some_and(closure) (#6244) 2023-08-01 19:29:42 +02:00
ruff_python_semantic Remove CallArguments abstraction (#6279) 2023-08-02 13:25:43 -04:00
ruff_python_stdlib Replace .map_or(false, $closure) with .is_some_and(closure) (#6244) 2023-08-01 19:29:42 +02:00
ruff_python_trivia Remove Parse trait (#6235) 2023-08-01 18:35:03 +02:00
ruff_shrinking Use tracing for format_dev (#6177) 2023-07-31 19:14:01 +00:00
ruff_source_file Skip BOM when determining Locator's line starts (#6159) 2023-07-29 11:47:13 +00:00
ruff_text_size Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
ruff_wasm Skip partial duplicates when applying multi-edit fixes (#6144) 2023-07-29 12:11:57 +00:00