Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support More Regex Related Linting Rules #50

Open
notJoon opened this issue Aug 4, 2024 · 0 comments
Open

Support More Regex Related Linting Rules #50

notJoon opened this issue Aug 4, 2024 · 0 comments
Labels
A-lint Adding or updating lint P-low Priority: Low

Comments

@notJoon
Copy link
Contributor

notJoon commented Aug 4, 2024

Description

Regular expressions (regex) can potentially use a lot of memory unintentionally. Therefore, it would be useful if the linter could detect this, and we could consider the following elements:

Avoid Catastrophic Backtracking

Some regex patterns migh cause exponential execution time as input size increase. For example, a pattern like ^(a+)+$ can cause performance issues with input like aaaaX. This pattern should be simplified like ^a+$.

Detect Greedy Quantifier on Large Input

Greedy quantifier can use a lot of memory on large input. For example, use pattern .*? instead of .* to make it non-greedy.

Detect Unnecessary Capture Group

Capture groups are use memory, so they should be removed when not really needed.

We can use (?:...) pattern when capturing is not necessary

// Unnecessary capture group
re := regexp.MustCompile(`(abc)`)
// Improved version
re := regexp.MustCompile(`(?:abc)`)

Minimize Regex (regex => NFA => DFA)

Go seems to simplify internally, by using regexp/syntax package. but need to check if the same applies to gno.

If it possible to minimize the given regex while maintain the its functionalities, we must show the minimized regex as suggestion. But not important features (YAGNI alert).

Related

#43

@notJoon notJoon added A-lint Adding or updating lint P-low Priority: Low labels Aug 4, 2024
@notJoon notJoon changed the title Add More Regex Related Linting Rules Support More Regex Related Linting Rules Aug 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Adding or updating lint P-low Priority: Low
Projects
None yet
Development

No branches or pull requests

1 participant