Skip to content

Address several autofix output issues by adding per-file line/column offset tracking - #4429

Merged
brendongo merged 7 commits into
semgrep:developfrom
finnigja:autofix_offsets
Dec 16, 2021
Merged

Address several autofix output issues by adding per-file line/column offset tracking#4429
brendongo merged 7 commits into
semgrep:developfrom
finnigja:autofix_offsets

Conversation

@finnigja

@finnigja finnigja commented Dec 14, 2021

Copy link
Copy Markdown
Contributor

This change addresses several autofix-related issues by adding per-file line/column offset tracking, and using those offsets when making edits to files.

There is no change in usage or documentation; it just addresses several edge cases within the existing autofix implementation (multi-line fixes, multiple-fixes-in-one-line fixes) that were not cleanly handled until now.

This should address several open issues; #4428, #3577, and #3388.

It adds several new e2e tests with rules/targets based on the issues above, and passes the existing tests in tests/e2e/test_autofix.py on my local machine.

PR checklist:

  • Documentation is up-to-date
  • Changelog is up-to-date
  • Change has no security implications (otherwise, ping security team)

@CLAassistant

CLAassistant commented Dec 14, 2021

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@finnigja finnigja changed the title Autofix offsets Address several autofix output issues by adding per-file line/column offset tracking Dec 14, 2021
@aryx
aryx requested review from brendongo and emjin December 15, 2021 18:48

@ievans ievans left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chair6 thanks for a terrific first contribution. This looks good to me. I think a docstring in code about what FileOffsets represents might be helpful, as it wasn't obvious to me at first, but as I understand it maintains the state the is necessary to track maintain correct behavior when applying multiple fixes to a single file/line.

@finnigja

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @ievans! Yup, you got it.. I've added the docstring.

@emjin emjin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks awesome! Made a very minor clarification to your comment. Also, I believe this won't work if two rules make a change to the same line, so we should just make a note of that.

Thank you so much for this contribution! A huge improvement for autofix

Comment thread semgrep/semgrep/autofix.py Outdated
Comment thread semgrep/semgrep/autofix.py
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

Successfully merging this pull request may close these issues.

5 participants