Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Fix documentation fragment discovery #40

Merged
merged 2 commits into from
Sep 28, 2021
Merged

Conversation

tomaciazek
Copy link
Contributor

Fixes #39

Copy link
Member

@ssbarnea ssbarnea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but I only did a brief look. With absence of tests over the code we will need more eyes. Do not merge without extra reviews.

Copy link
Member

@ssbarnea ssbarnea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but I only did a brief look. With absence of tests over the code we will need more eyes. Do not merge without extra reviews.

Copy link
Member

@ganeshrn ganeshrn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@ganeshrn ganeshrn merged commit 1c7e58c into main Sep 28, 2021
@ganeshrn ganeshrn deleted the bugfix/extra_doc_fragments branch September 28, 2021 05:23
this.errors = document.errors;
let m;
while ((m = LazyModuleDocumentation.docsRegex.exec(contents)) !== null) {
if (m && m.groups && m.groups.name && m.groups.doc && m.groups.pre) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a late review (I'm still on PTO today) but I just wanted to say that the code here is deeply nested, meaning that it's hard to reason about.
A common way to avoid this problem is to use "guard expressions" that interrupt the control flow early. For example:

Suggested change
if (m && m.groups && m.groups.name && m.groups.doc && m.groups.pre) {
if (!m.groups.?name || !m.groups.?doc && !m.groups.?pre) {
continue;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, you could move the conditional into the loop clause.

this._contents = document.toJSON();
this.errors = document.errors;
let m;
while ((m = LazyModuleDocumentation.docsRegex.exec(contents)) !== null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole loop body is under a conditional block. It seems like if the conditional clause evaluates to false, this will end up being an infinite loop.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomaciazek Can you please make a follow-up to address this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's nothing to fix - this is how regex works in JavaScript, and this particular line is straight from documentation. This loop will always terminate unless it's content interacts (in a very particular way) directly with LazyModuleDocumentation.docsRegex, which it doesn't.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document fragments not discovered for some modules
4 participants