Skip to content

Commit

Permalink
refactor: reuse urlRegex in parsing logic
Browse files Browse the repository at this point in the history
Consolidate URL matching logic by reusing urlRegex across the module.
  • Loading branch information
gentlementlegen committed Nov 19, 2024
1 parent 706bb32 commit 320ecb8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/configuration/formatting-evaluator-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const commentType = stringLiteralUnion(
);

export const wordRegex = /\b\w+\b/;
export const urlRegex = /https?:\/\/\S+/g;

const htmlEntity = Type.Object({
score: Type.Number(),
Expand Down
9 changes: 6 additions & 3 deletions src/parser/formatting-evaluator-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { commentEnum, CommentType } from "../configuration/comment-types";
import {
FormattingEvaluatorConfiguration,
formattingEvaluatorConfigurationType,
urlRegex,
wordRegex,
} from "../configuration/formatting-evaluator-config";
import { IssueActivity } from "../issue-activity";
Expand Down Expand Up @@ -176,16 +177,18 @@ export class FormattingEvaluatorModule extends BaseModule {
}
} else {
const bodyContent = element.textContent;
const urlPattern = /https?:\/\/\S+/g;
const matches = bodyContent?.match(urlPattern);
const matches = bodyContent?.match(urlRegex);
matches?.map((url) => url.split("#")[0]).forEach((url) => urlSet.add(url));
this._updateTagCount(formatting, tagName, score);
}
}
urlSet.forEach(() => {
this._updateTagCount(formatting, "a", this._multipliers[commentType].html["a"].score ?? 0);
});
const words = this._countWordsFromRegex(htmlElement.textContent ?? "", this._multipliers[commentType]?.wordValue);
const words = this._countWordsFromRegex(
htmlElement.textContent?.replace(urlRegex, "") ?? "",
this._multipliers[commentType]?.wordValue
);

return { formatting, words };
}
Expand Down

0 comments on commit 320ecb8

Please sign in to comment.