Skip to content

lint: use consistent short slice creation syntax#729

Open
NathanBaulch wants to merge 1 commit intosamber:masterfrom
NathanBaulch:shortslice
Open

lint: use consistent short slice creation syntax#729
NathanBaulch wants to merge 1 commit intosamber:masterfrom
NathanBaulch:shortslice

Conversation

@NathanBaulch
Copy link
Contributor

@NathanBaulch NathanBaulch commented Nov 6, 2025

There are a few different patterns used to create slices. This PR makes them all consistent.
This is something I noticed whilst building the it subpackage.

@codecov
Copy link

codecov bot commented Nov 6, 2025

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 94.22%. Comparing base (4e2c33e) to head (d45d138).

Files with missing lines Patch % Lines
slice.go 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #729      +/-   ##
==========================================
+ Coverage   94.19%   94.22%   +0.03%     
==========================================
  Files          18       18              
  Lines        2806     2806              
==========================================
+ Hits         2643     2644       +1     
+ Misses        149      148       -1     
  Partials       14       14              
Flag Coverage Δ
unittests 94.22% <93.33%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@samber
Copy link
Owner

samber commented Nov 6, 2025

There is actually a small difference between var a []A and a := []A{}. When you compare a to nil, the first case will output true.

https://go.dev/play/p/ZT1csskjjK_b

@NathanBaulch
Copy link
Contributor Author

NathanBaulch commented Nov 7, 2025

I'm aware of that but have yet to find a real-world situation (other than edge cases using reflection) where this was an issue.
As usual, I advocate for consistency. If we want to avoid nil slices then we should do it everywhere and validate with unit tests.

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

Successfully merging this pull request may close these issues.

2 participants