fix(#1146): correct the hasOwnProperty check in tinted-console.enable() - #1151
fix(#1146): correct the hasOwnProperty check in tinted-console.enable()#1151ImilB wants to merge 1 commit into
Conversation
Thayorns
left a comment
There was a problem hiding this comment.
Replaces the for...in loop in enable with a direct membership check and a single assignment, which is the right shape: the mis-scoped condition is gone, an unknown level now fails loudly instead of doing nothing, and enable('debug') no longer drags trace on with it. One indentation slip will stop npx eslint. There is no test for either of the two behaviours the fix introduces, so the file only keeps its existing console.warn smoke test and nothing pins the throw or the single-level effect.
| break; | ||
| } | ||
| } | ||
| if (!levels.hasOwnProperty(level)) { |
There was a problem hiding this comment.
This line is indented three spaces while the closing brace under it sits at two. eslint.config.js sets 'indent': ['error', 2, {"SwitchCase": 1}], so npx eslint reports this file as an error and the build stops before anything else in the change is looked at.
Description
Removes the broken
for...inloop entirely. The function now checks directly whether the requested level exists as a property of thelevelsobject. If it doesn't, an error is thrown immediately with the unknown level name in the message. If it does, only that single key is set totrue. The JSDoc is updated to document the new@throwsbehaviour and to clarify that only the requested level is enabled.What changed
src/tinted-console.js— Theenablefunction body went from a multi-iteration loop with a mis-scoped condition to a straightforward guard-and-set: first check!levels.hasOwnProperty(level)and throw if the level is unknown, thenlevels[level] = truedirectly. This eliminates the loop, the incorrect variable reference, and the silent failure on typos all at once.Fixes #1146