From 64da02ddeefad689774126219baf10bf9909175b Mon Sep 17 00:00:00 2001 From: toiletbril Date: Thu, 25 Jan 2024 20:17:04 +0300 Subject: [PATCH 1/3] feat: Add comment blocks with garbage along whitespace --- src/utils/cst-formatter/white-space.ts | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/utils/cst-formatter/white-space.ts b/src/utils/cst-formatter/white-space.ts index cefac9e..2e95874 100644 --- a/src/utils/cst-formatter/white-space.ts +++ b/src/utils/cst-formatter/white-space.ts @@ -17,18 +17,24 @@ function addRandomWhiteSpace(code: any) { code.selectTokensByType('Punctuator').forEach((token: any) => { try { const randomWhitespaceBefore = getRandomWhitespace(); - + const randomCommentBlockBefore = getRandomCommentBlocks(); const prevToken = token.getPreviousToken(); if (prevToken.isWhitespace) { prevToken.value = randomWhitespaceBefore; prevToken._sourceCode = randomWhitespaceBefore; prevToken._sourceCodeLines = [randomWhitespaceBefore]; } else { - const whitespaceBefore = new Token( - 'Whitespace', - randomWhitespaceBefore - ); - token.parentElement.insertChildBefore(whitespaceBefore, token); + const shouldUseComments = (Math.random() < 0.2); + let distractionBefore = (shouldUseComments) + ? new Token( + 'CommentBlock', + randomCommentBlockBefore + ) + : new Token( + 'Whitespace', + randomWhitespaceBefore + ); + token.parentElement.insertChildBefore(distractionBefore, token); } } catch (err) { // TODO: Handle token errors @@ -43,4 +49,12 @@ function getRandomWhitespace() { return whitespaceOptions[randomIndex]; } +function getRandomCommentBlocks() { + const commentOptions = [ + ':3', '.-.', 'hello world', 'T__T', 'i love javascript', 'why', ': - )' + ]; + const randomIndex = Math.floor(Math.random() * commentOptions.length); + return ' ' + commentOptions[randomIndex] + ' '; +} + export { addInconsistentIndentation, addRandomWhiteSpace }; From 0e80cc3cb898bf4576ee71fd9dee26053858dd54 Mon Sep 17 00:00:00 2001 From: toiletbril Date: Sun, 28 Jan 2024 14:58:54 +0300 Subject: [PATCH 2/3] update: Add some sarcastic comments --- src/utils/cst-formatter/white-space.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/utils/cst-formatter/white-space.ts b/src/utils/cst-formatter/white-space.ts index 2e95874..3fe89f3 100644 --- a/src/utils/cst-formatter/white-space.ts +++ b/src/utils/cst-formatter/white-space.ts @@ -51,7 +51,24 @@ function getRandomWhitespace() { function getRandomCommentBlocks() { const commentOptions = [ - ':3', '.-.', 'hello world', 'T__T', 'i love javascript', 'why', ': - )' + ':3c', + 'T__T', + 'yikes', + 'Hard to explain', + 'Big loop of doom', + 'drunk, fix later', + 'Biblical reference', + 'Comment this later', + 'Autogenerated, do not edit.', + 'it just keeps getting worse', + 'This comment is self explanatory.', + 'evil floating point bit level hacking', + 'the following code is self-documenting', + 'You are not expected to understand this', + 'this is a violation of the Geneva Convention', + 'If this comment is removed the program will blow up', + 'sometimes I believe the compiler ignores all my comments', + 'trying to reinvent the wheel but it\'s coming out more like a square', ]; const randomIndex = Math.floor(Math.random() * commentOptions.length); return ' ' + commentOptions[randomIndex] + ' '; From a37e96dc2dc8ae79969771551c02e0d0fb27a824 Mon Sep 17 00:00:00 2001 From: toiletbril Date: Sun, 28 Jan 2024 14:59:07 +0300 Subject: [PATCH 3/3] update: Make random comments more rare --- src/utils/cst-formatter/white-space.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/cst-formatter/white-space.ts b/src/utils/cst-formatter/white-space.ts index 3fe89f3..d362d48 100644 --- a/src/utils/cst-formatter/white-space.ts +++ b/src/utils/cst-formatter/white-space.ts @@ -24,7 +24,7 @@ function addRandomWhiteSpace(code: any) { prevToken._sourceCode = randomWhitespaceBefore; prevToken._sourceCodeLines = [randomWhitespaceBefore]; } else { - const shouldUseComments = (Math.random() < 0.2); + const shouldUseComments = (Math.random() <= 0.1); let distractionBefore = (shouldUseComments) ? new Token( 'CommentBlock',