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

feat: Linting Regex #43

Merged
merged 6 commits into from
Aug 4, 2024
Merged

feat: Linting Regex #43

merged 6 commits into from
Aug 4, 2024

Conversation

notJoon
Copy link
Contributor

@notJoon notJoon commented Jul 31, 2024

Description

Detect Repeated Regex Compilations

This rule detects cases where the same regex pattern is compiled multiple times within the same function. This pattern can lead to performance degradation and unnecessary memory usage.

Detection Mechanism

  1. AST Analysis
  2. Function-level Inspection:
    • Examines each function declarations (ast.FuncDecl) individually.
  3. Regex Compilation Call Identification:
    • Locates calls to regex.Compile or regexp.MustCompile functions.
  4. Pattern Tracking:
    • Stores the pattern string of each compile call in a map.
  5. Duplication Detection:
    • Simple map check. if the same pattern already exists in the map, it's considered a duplicated compilation.

@notJoon notJoon added the A-lint Adding or updating lint label Aug 1, 2024
@notJoon notJoon marked this pull request as ready for review August 4, 2024 02:47
@notJoon notJoon merged commit f25b3cb into main Aug 4, 2024
3 checks passed
@notJoon notJoon deleted the analyze-regex branch August 4, 2024 02:59
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant