-
Notifications
You must be signed in to change notification settings - Fork 15
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
safety checks #77
safety checks #77
Conversation
this is nifty, once impl'd i'll probably call smlfmt from millet with this flag and move the disclaimer to only apply to my naive formatter. can there be specific exit codes so a caller of smlfmt (like millet) can tell the difference between user error (e.g. parse error) and smlfmt internal error (e.g. |
Oh, nice idea. Exit codes seem like they would work. Although, I'm wondering, looking ahead -- would it be useful to have an interface for interesting queries and responses? E.g., |
that sounds nice but also a lot more work |
On the
This wouldn't be much harder to implement than different exit codes. Would this be difficult to support on Millet's side? (I think it's worth the investment, because then the protocol could be incrementally extended with more interesting functionality down the line.) |
oh no it wouldn't really be much harder to consume that on the millet side. the 'more work' i was thinking of would be smlfmt being able to input/output incremental diffs. i'd suggest a flag like |
Excellent! The |
…tions. request bug reports
Progress on #43. This patch implements a flag
--check
which, before writing to the output, checks the following:lex(output) = lex(input)
: no tokens added, removed, or reordered (including comments).parse(output) = parse(input)
: make sure nothing terrible has gone wrong in the parser. (If the result of the lexer is good, then this check should be superfluous. But, uhhh, for my sanity... I'm just gonna check it explicitly.)format(output) = format(input)
: make sure the formatter is idempotent.Together, these checks should ensure that
smlfmt
is always safe to use. The first two checks are crucial, whereas the idempotence check is moreso an aesthetic concern. And actually, I've found a few edge cases wheresmlfmt
is not idempotent, due to how comments are handled. (We should fix that later.)So, for now, with
--check
enabled,smlfmt
will exit with an error if safety is violated (i.e., due to tokens mangled), and will only output a warning if idempotence is violated.CheckOutput.check
interface--check
flag, and plumbing for callingCheckOutput.check
in the right placeimplement. ImplementCheckOutput.checkTokenSeqs.checkTokens
Token.sameExceptForMultilineIndentation
, which compares two tokens, handling multiline tokens where it's okay for indentation to differ.CompareAst
.