Skip to content
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

Fix parsing empty line comments #24

Closed
wants to merge 1 commit into from
Closed

Fix parsing empty line comments #24

wants to merge 1 commit into from

Conversation

pronebird
Copy link

@pronebird pronebird commented Feb 28, 2019

This PR fixes the issue described in #23 by including the empty line comments into the output.

The fix is trivial but there are few things I'd like to suggest to improve the codebase to prevent the similar bugs from happening again:

  1. First of all, tightening up the TypeScript configuration would prevent the code to compile and thus let the buggy code slip into production. The codebase is very loosely typed, I'd definitely turn on strict: true in tsconfig.json, consider the following example:
private static extractLineComment(source: string): string // return type is a string
{
  let match = source.match(/^\/\/\s*(.*?)\s*$/);
  return match ? match[1] : null; // but sometimes it returns null
}
  1. Use const instead of let in immutable contexts. Same example:
private static extractLineComment(source: string): string
{
+ // prefer const over let, because match is meant to be immutable
-  let match = source.match(/^\/\/\s*(.*?)\s*$/);
+  const match = source.match(/^\/\/\s*(.*?)\s*$/);
  return match ? match[1] : null;
}

@lukasgeiter
Copy link
Owner

Thank you for your PR. Unfortunately I've already started working on a fix for the bug myself and I've pushed it just now. I'm going to create a new release with the fix soon.


I absolutely agree with you that the code base should be using strict type-checking. I've already started fixing the issues, but as you can imagine I have a limited amount of time I get to spend on this project.

@pronebird
Copy link
Author

@lukasgeiter fair enough. Thanks for maintaining this library 👍

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