fix: test skipped-model membership with a Set, not in on an array - #281
Open
spokodev wants to merge 1 commit into
Open
fix: test skipped-model membership with a Set, not in on an array#281spokodev wants to merge 1 commit into
in on an array#281spokodev wants to merge 1 commit into
Conversation
The constructor nulls a `model` argument that is one of `keyword`, `gray`,
or `hex` (they have no array representation) so it falls back to rgb. The
guard used `model in skippedModels`, but `skippedModels` is an array, so
`in` tests its indices ('0', '1', '2'), never the model names — the guard
never fired:
Color([128, 128, 128], 'hex').string() // was "#80NANNAN"
Color([128, 128, 128], 'keyword').rgb() // threw TypeError
The model-method loop already uses the correct `skippedModels.includes(model)`.
Make `skippedModels` a Set and use `.has()` at both sites (a plain
`.includes()` at the constructor would trip the repo's `unicorn/prefer-set-has`
lint rule).
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.
Problem
The constructor nulls a
modelargument that is one of the deliberately-skipped models (keyword,gray,hex) so it falls back torgb— these have no array representation. But the guard never fires, so passing them as the explicitmodelproduces garbage or a crash:Cause
The
inoperator checks an object's keys; on an array those are the numeric indices, so the guard is dead code. The model-method loop lower in the same file already uses the correct test,skippedModels.includes(model)— confirming the intent.Fix
Make
skippedModelsaSetand use.has()at both sites. (A plain.includes()at the constructor would trip the repo's ownunicorn/prefer-set-hasxo rule, so a Set is the clean form for both.)Verification
test/index.js; the skipped models now fall back torgb— fails before, passes after.npm test(xo + tsd + mocha): 31 passing, lint clean.modelargument with array/number input, so normal string/object usage is unaffected.