-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fmt nits #11750
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
base: rusowsky/fmt-solar
Are you sure you want to change the base?
fmt nits #11750
Conversation
2b76ecf
to
55036b7
Compare
aa71d29
to
695e98a
Compare
695e98a
to
0e9bc17
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testing this it looks good from my end
crates/fmt/src/state/common.rs
Outdated
{ | ||
self.hardbreak_if_not_bol() | ||
&& next_lo | ||
.filter(|&lo| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_some_and, but i feel like the previous is more readable. let chain > bunch of option methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reverted to prev in 5cc4a15
crates/fmt/src/state/sol.rs
Outdated
if let Some(first) = bases.first().map(|base| base.span()) | ||
&& let Some(last) = bases.last().map(|base| base.span()) | ||
&& self.inline_config.is_disabled(Span::new(first.lo(), last.hi())) | ||
&& self.inline_config.is_disabled(first.until(last)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to
not until
, see doc comments on both
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, 5cc4a15
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
brain fart, sorry
crates/fmt/src/state/sol.rs
Outdated
then: &'ast ast::Stmt<'ast>, | ||
inline: bool, | ||
) { | ||
// NOTE(rusowsky): unless we add bracket spans to solar, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment is outdated, can this be fixed / what's missing? @0xrusowsky
the until
is correct here, but should be to
as indicated by the comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is it outdated? @DaniPopes
/// An `if` statement with an optional `else` block: `if (expr) { ... } else { ... }`.
If(Box<'ast, Expr<'ast>>, Box<'ast, Stmt<'ast>>, Option<Box<'ast, Stmt<'ast>>>),
with this info i cannot print the comments as in the original code for these 2 scenarios:
if /* comment10 */ (anotherLongCondition) // comment11
/* comment12 */ {
execute() ;
} // comment13
if (
step.opcode == 0x52
&& /*MSTORE*/ step.stack[0] == testContract.memPtr() // MSTORE offset
&& step.stack[1] == testContract.expectedValueInMemory() // MSTORE val
) {
mstoreCalled = true;
}
cause the span of the if expr in the 1st scenario is only the anotherLongCondition
ident, and in the 2nd one the binary operator expr
so i either need to:
self.print_if_cond("if", cond, then.span.lo())
self.print_if_cond("if", cond, cond.span.hi())
the former is the one we do now, cause imo is more consistent with the old behavior (puts everything inside the condition's parenthesis)
the later leaves all comments out of the parenthesis, so the first scenario would work, but the other one would output something like:
if (
step.opcode == 0x52
&& /*MSTORE*/ step.stack[0] == testContract.memPtr() // MSTORE offset
&& step.stack[1] == testContract.expectedValueInMemory()
) // MSTORE val
{
mstoreCalled = true;
}
anyways, i think we can simply remove the comment. i only added it initially because i didn't know we were willing to not have 100% exact compatibility with the old formatter.
imo the if statement comment handling looks good, so the comment is not really necessary (unlike the DeclMulti
comment, which could be a little bit more annoying for users, although they can simply use inline disable)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi, i deleted the cmnt.
the only implication is that this code:
if /* comment10 */ (anotherLongCondition) // comment11
/* comment12 */ {
execute() ;
} // comment13
was previously formatted as:
if /* comment10 */ (
anotherLongCondition // comment11
) {
/* comment12 */
execute();
} // comment13
and now is:
```solidity
if /* comment10 */ (
anotherLongCondition // comment11
/* comment12 */
) {
execute();
} // comment13
which is totally acceptable.
and if users want cmnt12 to go below, they simply need to put it inside the block, so that its parsed as part of the stmt
crates/fmt/src/state/sol.rs
Outdated
fn is_inline_stmt(&self, stmt: &'ast ast::Stmt<'ast>, cond_len: usize) -> bool { | ||
if let ast::StmtKind::If(cond, then, els_opt) = &stmt.kind { | ||
let if_span = Span::new(cond.span.lo(), then.span.hi()); | ||
let if_span = cond.span.until(then.span); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed in 5cc4a15
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, pending Dani's validation
This reverts commit 541f4c8.
Motivation
Solution
PR Checklist