Skip to content

Conversation

@jenul-ferdinand
Copy link

The email validation regex (in validator.ts) had been defined inside the isEmail() function, so it's re-compiled every time the function is called. Moving it to the module scope ensures that it is compiled only once.

Not too much of a big deal, minimal performance gain.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR moves the email validation regex from function scope to module scope in validator.ts to avoid re-compiling the regex on every function call, providing a minor performance optimization.

Key Changes

  • Email regex pattern extracted to module-level constant EMAIL_REGEX
  • Associated comments and eslint directives moved alongside the constant

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

/* eslint-disable */
const regex =
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
/* eslint-enable */
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

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

The /* eslint-enable */ comment is in the wrong location. Since /* eslint-disable */ is now at line 4 (module scope), the corresponding /* eslint-enable */ should be at line 5 (after the EMAIL_REGEX constant definition), not inside the isEmail function.

Suggested fix:

// Found at https://emailregex.com/
/* eslint-disable */
const EMAIL_REGEX = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
/* eslint-enable */
export const isEmail = (email: string): boolean => {
  return EMAIL_REGEX.test(email);
};

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant