Skip to content

One-line changes sometimes exceed line length #605

@jackfirth

Description

@jackfirth

In herbie-fp/herbie#1391, the quasiquote-to-list rule made this suggestion:

-      [`(,(and (or '+ '- '* '/ 'and 'or) op) ,as ..2 ,b) `(,op ,(loop `(,op ,@as) env) ,(loop b env))]
+      [`(,(and (or '+ '- '* '/ 'and 'or) op) ,as ..2 ,b) (list op (loop `(,op ,@as) env) (loop b env))]

This rewrites a line that's 102 characters long into one that's 103 characters long, exceeding the standard Racket line length.

Resyntax has some logic to avoid this, but it fails in this case because for one-line changes it doesn't consider the trailing text after the replacement. That is, the replacement above gets formatted with fmt by seeing if the new code, (list op (loop `(,op ,@as) env) (loop b env)), fits within 102 - 57 = 45 characters because the replaced expression starts at column 57. This does fit, but it fails to consider the trailing ] added at the end of the expression. Resyntax's formatting logic for single-line changes should consider not only the start position of the replaced expression but also the quantity of same-line trailing characters after the replaced expression's end position.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions