Skip to content

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

Open
@jakkdl

Description

@jakkdl

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions