Skip to content

Commit

Permalink
golangci-lint - disable prealloc linter (elastic#40532)
Browse files Browse the repository at this point in the history
This disables the prealloc linter. Having prealloc enabled on CI leads to
false positives which cause build failures, and those are often addressed
in ways that are worse for the codebase. For example, allocating an empty
slice like `make([]string, 0)` resolves the linter finding but goes against
best practices.

It can also be seen as a form of premature optimization, where you are making
changes in the name of performance before you have done the performance profiling.

If you still want to check your code locally, you can use `--enable=prealloc`
when running golangci-lint.

References

https://go.dev/wiki/CodeReviewComments#declaring-empty-slices

https://golangci-lint.run/usage/linters/#prealloc
  • Loading branch information
andrewkroh authored Aug 15, 2024
1 parent 11e71e0 commit 08dac31
Showing 1 changed file with 0 additions and 1 deletion.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ linters:
- unconvert # Remove unnecessary type conversions
- wastedassign # wastedassign finds wasted assignment statements.
- gomodguard # check for blocked dependencies
- prealloc # Finds slice declarations that could potentially be pre-allocated
- depguard

# all available settings of specific linters
Expand Down

0 comments on commit 08dac31

Please sign in to comment.