astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
32.58k stars 1.09k forks source link

Feature: Check for unintended non-printing characters #13297

Open jaraco opened 2 months ago

jaraco commented 2 months ago

In https://github.com/jaraco/zipp/pull/125, I learned that users can, intentionally or not, sneak non-printable characters into the code through otherwise innocuous pull requests. This particular one was caught by mach lint in a downstream system. It would be nice if ruff could catch such changes. I'm not confident it's possible, but I wanted to flag it as a feature for consideration.

MichaReiser commented 1 month ago

I'm rather surprised that we don't already have that. There's an existing rule to catch ambiguous unicode characters, but it doesn't cover invisible characters.

I'm very much in favor of adding the rule. We would have to think about if it should be a new rule or be added to the above mentioned rule

xyb commented 1 month ago

I suggest add --show-all-characters option to show non-printable characters like bat also:

Screenshot 2024-09-11 at 17 26 12

MichaReiser commented 1 month ago

@xyb, this issue is different. It isn't about showing invisible characters; it's about linting for invisible characters.

xyb commented 1 month ago

@MichaReiser I agree this is a separate request, but it's related because it would be confusing if Ruff reports an invisible character without helping the user fix it. If you agree, I'll go ahead and create a new issue to track this requirement.