Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whitespace trimming in template literals #16

Closed
kachkaev opened this issue Sep 20, 2024 · 4 comments
Closed

Whitespace trimming in template literals #16

kachkaev opened this issue Sep 20, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@kachkaev
Copy link

kachkaev commented Sep 20, 2024

πŸ‘‹ @dahlia! Just started playing with logtape – awesome architecture!

I faced a small issue with template literals and decided to share. Technically, there is no bug, it's just a small DX trap that could be avoided.

It turned out that {foo} and { foo } were not the same thing, which caught me:

logger.info('{ hello }', { hello: 'HELLO' });
// Expected: HH:MM:SS.xxx INF 'HELLO'
// Received: HH:MM:SS.xxx INF undefined
logger.info('{ hello }', { ' hello ': 'HELLO' });
// HH:MM:SS.xxx INF 'HELLO'

Because I use Prettier and it puts whitespace around { } in objects, I uncontentiously did the same in template literals. It took a bit of time to figure out what was going on.

Here is an idea: if we detect dev mode and there is a key mismatch like ' hello ' / 'hello', logtape could log a warning and explaining the situation. Or maybe it could even β€˜forgive’ spaces around braces. This could help folks with onboarding, because every new team member who uses logtape for the first time can accidentally fall into the same trap as I did.

WDYT?

@dahlia dahlia added the enhancement New feature or request label Sep 21, 2024
@dahlia
Copy link
Owner

dahlia commented Sep 21, 2024

How about a behavior that strips out the whitespace to find the variable if there is leading and trailing whitespace in a template variable and it doesn't match exactly?

logger.info("value = { foo }", { " foo ": 1, foo: 2 });
// INF value = 1
logger.info("value = { foo }", { foo: 2 });
// INFO value = 2

@dahlia dahlia closed this as completed in 33bdf82 Sep 23, 2024
@dahlia dahlia self-assigned this Sep 23, 2024
@dahlia
Copy link
Owner

dahlia commented Sep 23, 2024

It will be shipped with v0.6.0, which is the next release. You can give it a try in advance at v0.6.0-dev.80+33bdf827 (JSR & npm).

@kachkaev
Copy link
Author

Perfect, thanks! πŸš€

@dahlia
Copy link
Owner

dahlia commented Sep 24, 2024

This is shipped with LogTape v0.6.0 (JSR & npm).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants