python-trio / flake8-async

Highly opinionated linter for Trio code
https://flake8-async.readthedocs.io
MIT License
17 stars 2 forks source link

implement autofix for TRIO100 #149

Closed jakkdl closed 1 year ago

jakkdl commented 1 year ago

Before jumping on autofixing TRIO91X I decided to start with the simpler TRIO100. Turns out I'd forgotten how messy it is to manipulate code and preserve whitespace, comments, lines, etc etc etc :upside_down_face:

~~But I remember solving it in shed, so I can probably crib that from there and write some helper function. Also remaining is actually changing the file on disk, and adding a flag.~~

shed/Black/isort is also back to being incredibly annoying, I'll have to figure out a better way of writing autofix files so they don't get fucked with as much as is done currently.

jakkdl commented 1 year ago

It be done!

Very happy with this new autofix testing infrastructure, and I even just now realized that I can exclude autofix files from being shed'd by excluding them in pre-commit ^^

Uses a similar approach to https://github.com/Zac-HD/shed/pull/52 ; and shed would normally codemod away the useless pass statements that are inserted in the autofix files sometimes ... which would cause the autofix tests to fail. It would be great if I could highly selectively disable pass removal, so shed can check that the autofixed files are otherwise generated with good formatting. fmt: off does nothing.

--generate-autofix maybe deserves a mention in CONTRIBUTING.md - it helps a lot when developing. And ofcourse --autofix should be documented, but it should probably be a comma-separated list anyway.

jakkdl commented 1 year ago

I realize now I added this comment in #124

just remove the context, unless there's other warnings about the content of the context.

that's ... really really hard to implement properly - at least until everything is converted to libcst. So that will have to wait for a later PR, if it turns out to actually be of use. I was probably mainly thinking of missing awaits - but if I can fix trio typing so type checkers can warn on async function calls not being awaited that should be a non-issue.

jakkdl commented 1 year ago

merged! :rocket: