Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first transform, then visit, to not get incorrect line markers #193

Open
Tracked by #124
jakkdl opened this issue May 3, 2023 · 0 comments
Open
Tracked by #124

first transform, then visit, to not get incorrect line markers #193

jakkdl opened this issue May 3, 2023 · 0 comments

Comments

@jakkdl
Copy link
Member

jakkdl commented May 3, 2023

low-priority QoL - unless flake8-trio is used in automated environments.

Failing test:

def test_line_numbers_match_end_result():
    text = """import trio
with trio.move_on_after(10):
  ...

trio.sleep(0)
"""
    plugin = Plugin.from_source(text)
    initialize_options(plugin, args=["--enable=TRIO100,TRIO115", "--autofix=TRIO100"])
    errors = tuple(plugin.run())
    new_source = plugin.module.code
    assert errors[1].line == plugin.module.code.split('\n').index('trio.sleep(0)')+1

the assertion fails with 5 != 4 as the line numbers of objects are never updated once parsed when initiating the plugin.

The best way to fix this would probably, as the header suggest, be to first make a pass where all enabled autofixers are run - with autofixed errors being printed out with old and/or no line markers. Then the file is reparsed, and enabled visitors are run on the file.

@jakkdl jakkdl mentioned this issue May 3, 2023
63 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant