Add require-len checker for fail-fast indexed access guards - #312
Open
mmorel-35 wants to merge 3 commits into
Open
Add require-len checker for fail-fast indexed access guards#312mmorel-35 wants to merge 3 commits into
require-len checker for fail-fast indexed access guards#312mmorel-35 wants to merge 3 commits into
Conversation
mmorel-35
force-pushed
the
require-len
branch
3 times, most recently
from
June 1, 2026 12:40
802c5f0 to
fe51083
Compare
Contributor
|
While I like the feature it brings, I'm a bit annoyed by the complexity of the code. I know this comment is not actionable, I'm sorry. But I wanted to share my point of view |
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
…d deduplicated autofix Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
mmorel-35
force-pushed
the
require-len
branch
2 times, most recently
from
July 10, 2026 10:36
1450ce1 to
8a245a3
Compare
Removed 'require-len' section from CONTRIBUTING.md.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a dedicated
require-lenchecker that enforces fail-fast length guards before indexed collection access.require-erroris left untouched and remains focused solely on error assertions.New
require-lencheckerassert.Len*calls that guard indexed access but should userequireinsteadassert.*calls that use indexed access without a priorrequire.Len/require.NotEmptyguardrequire.Len(t, arr, N)before the assertion, usingrequire.NotEmpty(t, arr)when only index0is accessedhasLenGuardcheck only accepts fail-fast (require.*) guards and verifies the asserted length is>= maxIndex+1Missing
requireimport handled in autofixgithub.com/stretchr/testify/require, the fix also inserts the importrequireas the qualifier; falls back torequire1,require2, etc. ifrequireis already taken as a local identifierRegistered as enabled-by-default with dedicated README docs, analyzer fixtures, and golden autofix output