Skip to content

ignoreComments skips sections of code when true #42

@GaryGiebler

Description

@GaryGiebler

If you set ignoreComments true, the app can skip entire sections of code and report translations unused which are actually used.

A single line comment using /* and */ will cause the app to skip every line of code up to the next comment.

The following is only true if the line begins with '*/' - the '^' character causes the statement to match the beginning of the line:

const isEndOfMultilineComment = (str: string): boolean => /^(*/)/.test(str);

Even if you remove the '^' so the app catches the end of comments using '*/' it still skips code after single line comments.

This code in translations.ts sets skip true and skips subsequent lines of code:

  if (isStartOfMultilineComment(_str) || isEndOfMultilineComment(_str)) {
    skip = isStartOfMultilineComment(_str);
  }

The same statement causes the app to include the line containing '/*' in the case of multiline comments.

To fix these errors:

  1. Remove the '^' in the isEndOfMultilineComment statement:
    const isEndOfMultilineComment = (str: string): boolean => /(*/)/.test(str);

  2. Add the following statement to handle single line comments before the above statement:
    if (isStartOfMultilineComment(_str) && isEndOfMultilineComment(_str)) {
    skip = false;
    return acc;
    }

  3. Modify this statement to exclude the line with the end of a multiline comment '*/' :
    if (skip || isInlineComment(_str) || isHTMLComment(_str)) {

to be:
if (skip || isInlineComment(_str) || isHTMLComment(_str) || isEndOfMultilineComment(_str)) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions