crate-ci / typos

Source code spell checker
Apache License 2.0
2.42k stars 93 forks source link

Specify file line ranges #1017

Open DanielCardonaRojas opened 3 months ago

DanielCardonaRojas commented 3 months ago

Hi,

I've been playing around with this awesome tool. One option I would love to see is a way to specify file ranges to spell check. Although could be considered controversial, some people might only want to spell check their git staged hunks, which helps avoid having larger PRs.

This gets pretty close:

git status -s | cut -c 4- | typos --file-list -

But will of course, spell-check the complete file, ideally I'd like to specify ranges for hunks so that when I apply suggestions I don't introduce new line changes.

epage commented 3 months ago

Know of any prior art for how users can specify hunks? Enumerating how other tools handle this today would help with the design and evaluation of this proposal.

epage commented 3 months ago

Also, what would the workflow look like for this? Having an idea of what it would take to adopt this feature can give an idea of how likely it is to be adopted which can affect the priority of it.

DanielCardonaRojas commented 2 months ago

Thinking twice, I can only think of one practical form for this feature, I imagine that the output of git diff is parsed to extract line ranges and file names. I don't think it would be practical to pass a range per file manually, instead a patch file or the output of git diff is used, since it has all the information required to process specific parts of the files.

Something along the lines of:

git diff | typos --hunks -

I'll look around for other tools process hunks and will share my findings if any.