• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

homer0 / jsdoc-ts-utils / 4457244662

pending completion
4457244662

push

github

GitHub
Merge pull request #40 from homer0/next

103 of 103 branches covered (100.0%)

Branch coverage included in aggregate %.

1011 of 1011 relevant lines covered (100.0%)

2.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/features/removeTaggedBlocks.js
1
// @ts-check
1✔
2
/**
1✔
3
 * This class removes blocks that use the `jsdoc-remove` tag.
1✔
4
 */
1✔
5
class RemoveTaggedBlocks {
1✔
6
  /**
1✔
7
   * @param {EventEmitter} events       To hook to the necessary events to parse the code.
1✔
8
   * @param {EventNames}   EVENT_NAMES  To get the name of the events the class needs to
1✔
9
   *                                    listen for.
1✔
10
   */
1✔
11
  constructor(events, EVENT_NAMES) {
1✔
12
    /**
3✔
13
     * The list of comments that use `jsdoc-remove`.
3✔
14
     *
3✔
15
     * @type {string[]}
3✔
16
     * @access protected
3✔
17
     * @ignore
3✔
18
     */
3✔
19
    this._comments = [];
3✔
20
    // Setup the listeners.
3✔
21
    events.on(EVENT_NAMES.newComment, this._readComment.bind(this));
3✔
22
    events.on(EVENT_NAMES.commentsReady, this._replaceComments.bind(this));
3✔
23
  }
3✔
24
  /**
1✔
25
   * This is called every time a new JSDoc comment block is found on a file. It validates
1✔
26
   * if the block uses `jsdoc-remove` and saves it so it can be parsed later.
1✔
27
   *
1✔
28
   * @param {string} comment  The comment to analyze.
1✔
29
   * @access protected
1✔
30
   * @ignore
1✔
31
   */
1✔
32
  _readComment(comment) {
1✔
33
    if (comment.match(/\s*\* @jsdoc-remove\s*\*/)) {
2✔
34
      this._comments.push(comment);
1✔
35
    }
1✔
36
  }
2✔
37
  /**
1✔
38
   * This is called after all the JSDoc comments block for a file were found and the
1✔
39
   * plugin is ready to make changes.
1✔
40
   * The method takes all the comments that were found before and replace them with empty
1✔
41
   * lines.
1✔
42
   *
1✔
43
   * @param {string} source  The code of the file being parsed.
1✔
44
   * @returns {string}
1✔
45
   * @access protected
1✔
46
   * @ignore
1✔
47
   */
1✔
48
  _replaceComments(source) {
1✔
49
    const result = this._comments.reduce(
2✔
50
      (acc, comment) =>
2✔
51
        acc.replace(
1✔
52
          comment,
1✔
53
          comment
1✔
54
            .split('\n')
1✔
55
            .map(() => '')
1✔
56
            .join('\n'),
1✔
57
        ),
2✔
58
      source,
2✔
59
    );
2✔
60

2✔
61
    this._comments = [];
2✔
62
    return result;
2✔
63
  }
2✔
64
}
1✔
65

1✔
66
module.exports.RemoveTaggedBlocks = RemoveTaggedBlocks;
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc