Skip to content
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

It doesn't work for "if with a statement" #139

Open
y7ls8i opened this issue Jul 25, 2024 · 2 comments
Open

It doesn't work for "if with a statement" #139

y7ls8i opened this issue Jul 25, 2024 · 2 comments

Comments

@y7ls8i
Copy link

y7ls8i commented Jul 25, 2024

if err := veryLongFunctionWithManyLongArguments(veryLongArgument1, veryLongArgument2, veryLongArgument3, veryLongArgument4, veryLongArgument5); err != nil {
	// ... ... ...
}

should have been broken down into:

if err := veryLongFunctionWithManyLongArguments(
	veryLongArgument1,
	veryLongArgument2,
	veryLongArgument3,
	veryLongArgument4,
	veryLongArgument5,
); err != nil {
	// ... ... ...
}

but it doesn't.

@y7ls8i y7ls8i changed the title It doesn't work for "if with a short statement" It doesn't work for "if with a statement" Jul 25, 2024
@shuaiyy
Copy link

shuaiyy commented Aug 12, 2024

the same case

if err = n.db.Unscoped().Model(&models.User{}).Where("id = ?", id).First(&item).Error; err == nil {
}

but below is worked:

err = n.db.Unscoped().Model(&models.NotebookEnv{}).Where("id = ?", id).First(&item).Error
if err == nil {
}

@matthewhughes934
Copy link

The IfStmt.Init node isn't considered for shortening in the block:

case *dst.IfStmt:
, but even if it was the shortening Decoration is on the IfStmt node and not the Init node so even if we did s.formatStmt(st.Init) in that first block linked the hasAnnotation call in formatStmt will return false"
shouldShorten := HasAnnotation(stmt)

I suspect a fix would require adding something like the force parameter like formatExpr has:

func (s *Shortener) formatExpr(expr dst.Expr, force bool, isChain bool) {

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

No branches or pull requests

3 participants