Giter Club home page Giter Club logo

Comments (9)

NiseVoid avatar NiseVoid commented on August 15, 2024

The message it's giving is correct, as it's a leaing newline in this code block (anything surrounded by {}).

However I agree there is a case to be made about the readability, it would be interesting to see how this is handled in Go's source code. Sadly gofmt can't be used as an example since it doesn't seem to have an opinion about single newlines.

from whitespace.

NiseVoid avatar NiseVoid commented on August 15, 2024

I took a look at multi-line if statements in the Go source code. There were no cases with an extra newline. Half of them did have a comment after the if, which achieves similar readability.

from whitespace.

Zamiell avatar Zamiell commented on August 15, 2024

Can you link some cases? How did you find them? Is there a command-line way to search through a repo for multi line if statements?

from whitespace.

NiseVoid avatar NiseVoid commented on August 15, 2024

I used a simple grep command to find some cases:

grep -A5 "if .* &&$" $(find /usr/lib/go/src -name "*.go")

This command is not perfect as it misses many case, but I'd say there's plenty of examples with this one command

from whitespace.

Zamiell avatar Zamiell commented on August 15, 2024

Thanks. I used this grep statement on the Kubernetes repository. Similar to the Golang repository, they also do not seem to use any newline between conditionals and more code, which was honestly surprising to me.

With that said, there is still a case to be made for programmers preferring a newline here for easy readability. Should whitespace be updated to ignore this specific kind of newline?

from whitespace.

NiseVoid avatar NiseVoid commented on August 15, 2024

Ignoring the newlines sounds like a bad solution. It could lead to inconsistent code. A better solution would be to make a setting that gives a warning when there is no newline (or comment) after every multi-line if.

from whitespace.

Zamiell avatar Zamiell commented on August 15, 2024

That would be great, thank you.

from whitespace.

NiseVoid avatar NiseVoid commented on August 15, 2024

I added a setting for this feature and made a pull request on golangci-lint.

golangci/golangci-lint#723

from whitespace.

Zamiell avatar Zamiell commented on August 15, 2024

Thank you!!

from whitespace.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.