Skip to content

Conversation

@Hweinstock
Copy link
Contributor

@Hweinstock Hweinstock commented Oct 28, 2024

Problem

contributors often use JSON.stringify to get a printable form of an object in log messages, but this is hard for humans to read.

Solution

Implement a custom eslint rule that checks for instances of JSON.stringify inside of a logging statement. The implementation involves a few heuristics for catching edge cases that are explained in the comments.

In addition to implementing the lint rule, existing cases are migrated to use %O string substitution.

Within the lint message, we mention the depth limit. There is a workaround this depth limit by manually converting it to a string first with util.format: https://stackoverflow.com/questions/10729276/how-can-i-get-the-full-object-in-node-jss-console-log-rather-than-object, but seems rather involved, and uncommon enough to leave out of suggestion message.


License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@aws aws deleted a comment from github-actions bot Oct 29, 2024
@justinmk3 justinmk3 changed the title feat(lint): throw error on JSON.stringify within a logging statement build(lint): throw error on JSON.stringify within a logging statement Oct 29, 2024
@Hweinstock Hweinstock marked this pull request as ready for review October 29, 2024 16:27
@Hweinstock Hweinstock requested review from a team as code owners October 29, 2024 16:27
@Hweinstock Hweinstock force-pushed the lint/noJsonStringify branch from 773df53 to 504a31a Compare November 5, 2024 17:44
@Hweinstock Hweinstock merged commit a4662aa into aws:master Nov 5, 2024
22 of 25 checks passed
@Hweinstock Hweinstock deleted the lint/noJsonStringify branch November 5, 2024 20:17
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.

2 participants