astral-sh / ruff

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

Request: Spelling check #1628

Closed strickvl closed 1 year ago

strickvl commented 1 year ago

There are seemingly two big Python code checkers: pyspelling and codespell. Codespell doesn't catch everything, and pyspelling is slow to run. It'd be great to have a version / implementation of the logic of these (eventually including PySpelling's exception syntax etc) in ruff.

colin99d commented 1 year ago

@charliermarsh could we just port over typos, or is it too rust specific?

charliermarsh commented 1 year ago

I think the best option would be to try and integrate typos as a library (https://docs.rs/typos/0.10.6/typos/). Not sure if the API is amenable to that.

charliermarsh commented 1 year ago

(That is: call the typos functions directly in Rust, rather than using the CLI, and report typos as Ruff errors.)

colin99d commented 1 year ago

I have been thinking about this for a while and I think we should keep spell checking separate from Ruff for the following reasons:

  1. This spell checker is already blazingly fast, so users of typos have no reason to switch
  2. Spell checkers do not need to parse python code, so we would not save any additional time from them being part of the library
  3. Having to support multiple languages could be burdensome
charliermarsh commented 1 year ago

Yeah that makes sense. Let's pass on this for now.

MicaelJarniac commented 1 year ago

I have been thinking about this for a while and I think we should keep spell checking separate from Ruff for the following reasons:

1. This spell checker is already blazingly fast, so users of typos have no reason to switch

2. Spell checkers do not need to parse python code, so we would not save any additional time from them being part of the library

3. Having to support multiple languages could be burdensome

Regarding 2, I think spell checkers can benefit greatly from parsing Python code.

For example, say I've installed a lib from PyPI that has typos on its function names. There's nothing I can do about them, they're outside my control, but I'll need to type the typos if I want to use these functions.

A normal spell checker, that treats everything as plain text, would see the typo and complain about it. But again, there's nothing I can do about them.

If the spell checker understands Python, it'll be able to tell what's my fault and what's outside my control, and so if the typo is on something from an external lib, it can ignore them, as I can't control that, but if the typo is on my own functions and variable names, it can then warn me.