Skip to content

fix(#1146): correct the hasOwnProperty check in tinted-console.enable() - #1151

Open
ImilB wants to merge 1 commit into
objectionary:masterfrom
ImilB:issue-1146
Open

fix(#1146): correct the hasOwnProperty check in tinted-console.enable()#1151
ImilB wants to merge 1 commit into
objectionary:masterfrom
ImilB:issue-1146

Conversation

@ImilB

@ImilB ImilB commented Aug 1, 2026

Copy link
Copy Markdown

Description

Removes the broken for...in loop entirely. The function now checks directly whether the requested level exists as a property of the levels object. 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 to true. The JSDoc is updated to document the new @throws behaviour and to clarify that only the requested level is enabled.

What changed

src/tinted-console.js — The enable function 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, then levels[level] = true directly. This eliminates the loop, the incorrect variable reference, and the silent failure on typos all at once.
Fixes #1146

@Thayorns Thayorns left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/tinted-console.js
break;
}
}
if (!levels.hasOwnProperty(level)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

tinted-console.js: enable(level) erroneously enables unrelated levels and fails to flag unknown level names

2 participants