Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Feature/better console log detection #413

Merged
merged 9 commits into from
Dec 14, 2023

Conversation

baristaGeek
Copy link
Collaborator

Description

LLMs didn't prove to be the correct approach towards console log detection.

They were a fast way to test interest and some initial cases. But since this is a key need users have, we need to run these through RegExes to make the console log detection not too lax, and not too strict.

I tested this with PR #412

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Chore: cleanup/renaming, etc
  • RFC
  • Test

Notes

  • Post-processing each addition in the line diff with AI is always an open option that we can go back to if we think about some application.
  • Let's leave the name of the file as it is. The logic in detectLeftoutComents.ts or detectPIIData.ts would eventually be different, despite being able to abstract some components such as commenting the line where the issues is found.

Acceptance

Copy link

vercel bot commented Dec 13, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
watermelon ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 13, 2023 7:58pm

Copy link

watermelon-copilot-for-code-review bot commented Dec 13, 2023

Watermelon AI Summary

The Pull Request implements a refined approach to console log detection by evolving a prototype regex pattern to achieve a balanced level of sensitivity. It replaces an initial AI-based method, ensuring logs are identified correctly without being too inclusive or exclusive, while also streamlining and cleaning up the codebase for this feature.

GitHub PRs

Click here to login to Jira
Click here to login to Confluence
Click here to login to Slack
No results found in Notion Pages :(

No results found in Linear Tickets :(

Click here to login to Asana
watermelon is an open repo and Watermelon will serve it for free.
🍉🫶
Why not invite more people to your team?

)
.catch((err) => {
console.log(err);
});

Choose a reason for hiding this comment

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

This PR contains console logs. Please review or remove them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ty! This might be over-informative.

const splitAdditions = additions.split("\n");

// RegEx to detect console log equivalents in different languages
const consoleLogRegex = /(console\.log|print|printf|fmt\.Print|log\.Print|NSLog|puts|println|println!)\([^)]*\)(?![^]*?\/\/|[^]*?\/\*|#)/;
Copy link
Member

Choose a reason for hiding this comment

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

Could we make an external list?
Adding to a single line seems harder

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What do you mean by an external list, exactly?

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const consoleLogRegex = /(console\.log|print|printf|fmt\.Print|log\.Print|NSLog|puts|println|println!)\([^)]*\)(?![^]*?\/\/|[^]*?\/\*|#)/;
const consoleLogTexts = ["console.log", "printLn"]

Copy link
Member

Choose a reason for hiding this comment

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

And then we use a template string to add it to the Regex

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's a valid suggestion. If I'm free of tasks during the holidays I'll improve the readability. Soft promise.

if (!currentLine.match(commentRegex) && currentLine.match(consoleLogRegex)) {
const commentFileDiff = async () => {

const consoleLogPosition = i + 1; // The +1 is because IDEs and GitHub file diff view index LOC at 1, not 0
Copy link
Member

Choose a reason for hiding this comment

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

I know this is fast, but should we do it concurrently?

Copy link
Member

Choose a reason for hiding this comment

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

Also, this generates a comment in the last consle log, isn't it better to show it at the top of the PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Steps to replicate?

I'm testing with this fizz buzz and it's commenting lines 6,8, and 10 respectively

Screen Shot 2023-12-14 at 11 16 54 AM

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I know this is fast, but should we do it concurrently?

Why would we want to do it concurrently? It's a pretty straightforward iteration of an array in O(n) to me. But I'd like to read your opinion.

Copy link
Member

Choose a reason for hiding this comment

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

For really long file diffs it will be a long running process, awaiting each time the posting of the comment.
As per the API we can send an object and never hit the rate limit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the very rare edge case that we get a very long file diff where every single line should be commented, I still don't think we'd have problems.

My argument for this is that when doing this with GPT, we were doing the very same thing with the additional computational complexity of async/awaiting the http call to Open AI which is an expensive one.

If we ever get to the rate limit we can always refactor this.

Copy link
Member

@EstebanDalelR EstebanDalelR left a comment

Choose a reason for hiding this comment

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

Some comments as improvements

@baristaGeek baristaGeek merged commit 336e40b into dev Dec 14, 2023
3 checks passed
@baristaGeek baristaGeek deleted the feature/better-console-log-detection branch December 14, 2023 20:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants