ruff
ruff copied to clipboard
ERA001 false positive on examples in comments
Ruff treats this as commented-out code, despite being an example.
# NOTE: Only upper-case fields in `extra` will be sent to `journald`.
# For instance, this:
#
# logging.error("Uh oh!", extra={"payload": "my-payload"})
#
# Will not show up as a `payload` field in `journalctl`, but this will:
#
# logging.error("Uh oh!", extra={"PAYLOAD": "my-payload"})
journal_handler = JournalHandler()
It would be nice if Ruff could recognize "for example" or ```python-blocks as "example code".
Hmm that's an interesting one. The rule is working as intended but I can see how it is undesired in this specific case.
I would favor the solution where the rule ignores Python code blocks, although that would require that the rule supports some form of markdown parsing, which seems a bit much.
It's a bit of a hack, but you can use triple quotes to get around this case https://play.ruff.rs/42481cc7-c07b-4158-9b6b-c65f0be7c09c
Mine is different but matches the title. Maybe the rule is too eager? It worked on ruff 0.2.1, FP on 0.3.7
# case 1: both codes are CREATE
if cond1:
pass
# case 2: one code is a CREATE, the other is an existing
elif cond2:
pass
# case 3: both codes are existing
elif cond3:
pass
removing the colons removes the FP, is that how it is meant to be?