Comments (9)
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.
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.
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.
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.
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.
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.
That would be great, thank you.
from whitespace.
I added a setting for this feature and made a pull request on golangci-lint.
from whitespace.
Thank you!!
from whitespace.
Related Issues (6)
- should not complain about unnecessary whitespace if func decleration is spread over multiple lines HOT 2
- How can I use this if I don't want to use golint ci? HOT 1
- Option to ignore newline in functions HOT 1
- Suggestion: Don't lint leading empty line after function using multiple lines HOT 1
- Inline function not recognized as multi-line function HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from whitespace.