Skip to content

fix: prevent block comment characters inside of existing comments to remove entire codeblock #268

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/__fixtures__/curriculum-helpers-javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ const arrowFunction = `const myFunc = name => console.log("Name")`;

const destructuredArgsFunctionDeclaration = `function printFruits({a, b},c = 1, ...rest) {`;

// eslint-disable-next-line no-template-curly-in-string
const jsCodeTemplateCurlyComment = "const v = /*a*/`/*b*/${/*c*/12}`";

// eslint-disable-next-line no-template-curly-in-string
const jsCodeTemplateCurlyNoComments = "const v = `/*b*/${12}`";

const testValues = {
jsCodeWithSingleAndMultLineComments,
jsCodeWithSingleAndMultLineCommentsRemoved,
Expand All @@ -81,6 +87,8 @@ const testValues = {
letFunction,
arrowFunction,
destructuredArgsFunctionDeclaration,
jsCodeTemplateCurlyComment,
jsCodeTemplateCurlyNoComments
};

export default testValues;
7 changes: 7 additions & 0 deletions lib/__tests__/curriculum-helper.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const {
jsCodeWithNoArgCall,
jsCodeWithArgCall,
jsCodeWithCommentedCall,
jsCodeTemplateCurlyComment,
jsCodeTemplateCurlyNoComments
} = jsTestValues;

describe("RandomMocker", () => {
Expand Down Expand Up @@ -107,6 +109,11 @@ describe("removeJSComments", () => {
it("does not remove a url found in JS code", () => {
expect(removeJSComments(jsCodeWithUrl)).toBe(jsCodeWithUrlUnchanged);
});

it("returns a string with no comments in template expressions", () =>
{
expect(removeJSComments(jsCodeTemplateCurlyComment)).toBe(jsCodeTemplateCurlyNoComments);
})
});

describe("removeCssComments", () => {
Expand Down
Loading