lukasgeiter / gettext-extractor

A flexible and powerful Gettext message extractor with support for JavaScript, TypeScript, JSX and HTML.
MIT License
98 stars 21 forks source link

Fix parsing empty line comments #24

Closed pronebird closed 5 years ago

pronebird commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

@lukasgeiter fair enough. Thanks for maintaining this library 👍