Skip to content

Commit

Permalink
fix extra whitespce
Browse files Browse the repository at this point in the history
  • Loading branch information
rgoldfinger-quizlet committed May 24, 2019
1 parent 3e48f1c commit 8858f92
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 21 deletions.
5 changes: 4 additions & 1 deletion dist/cli.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/cli.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/converter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/converter.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/stripComments.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export declare function stripComments(code: string, comments: string[]): string;
export declare function stripComments(code: string, comments: string[]): [string, number];
9 changes: 7 additions & 2 deletions dist/stripComments.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/stripComments.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/stripCommentsRunner.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { FilePaths } from "./cli";
export default function run(paths: FilePaths, shouldComit: boolean): Promise<void>;
export default function run(paths: FilePaths, comments: string[] | undefined, shouldComit: boolean): Promise<void>;
9 changes: 5 additions & 4 deletions dist/stripCommentsRunner.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/stripCommentsRunner.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/stripComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ export function stripComments(
const matchedComment = comments.find(c => line.includes(c))!;
const matchedIndex = line.indexOf(matchedComment);
if (matchedIndex > 0) {
acc.push(line.slice(0, matchedIndex));
count = count + 1;
const firstPartOfLine = line.slice(0, matchedIndex);
if (firstPartOfLine.match(/\S/)) {
acc.push(firstPartOfLine);
count = count + 1;
}
}
} else {
acc.push(line);
Expand Down
15 changes: 10 additions & 5 deletions test/stripComments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const bar = undefined;
return {
audioId: getAudioIdFromTerm(term, termSide),
// $FlowFixMeImmutable
url:
termSide === TermSide.WORD
? // $FlowFixMeImmutable
Expand All @@ -24,26 +25,30 @@ return {

describe("stripComments", () => {
it("should strip // @flow", () => {
expect(stripComments(testCode, ["// @flow"])).not.toContain("// @flow");
expect(stripComments(testCode, ["// @flow"])[0]).not.toContain("// @flow");
});
it("should strip // $FlowFixMe", () => {
expect(stripComments(testCode, ["// $FlowFixMe"])).not.toContain(
expect(stripComments(testCode, ["// $FlowFixMe"])[0]).not.toContain(
"// $FlowFixMe"
);
});
it("should retain any code before the comment", () => {
expect(stripComments(testCode, ["// $FlowFixMeImmutable"])).toContain("?");
expect(stripComments(testCode, ["// $FlowFixMeImmutable"])[0]).toContain(
"?"
);
});
it("should preserve 'undefined'", () => {
expect(stripComments(testCode, ["// $FlowFixMeImmutable"])).toContain("?");
expect(stripComments(testCode, ["// $FlowFixMeImmutable"])[0]).toContain(
"?"
);
});
it("should strip all at once", () => {
expect(
stripComments(testCode, [
"// @flow",
"// $FlowFixMeImmutable",
"// $FlowFixMe"
])
])[0]
).toMatchSnapshot();
});
});

0 comments on commit 8858f92

Please sign in to comment.