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

[dotnet] Annotate nullable reference types on ActionBuilder #14844

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from

Conversation

RenderMichael
Copy link
Contributor

@RenderMichael RenderMichael commented Dec 2, 2024

User description

Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

enhancement


Description

  • Enabled nullable reference types in ActionBuilder.cs to improve null safety and code reliability.
  • Refactored the sequences dictionary to be readonly, ensuring it is only initialized once and cleared when needed.
  • Updated the AddAction method to use a new ProcessTick method, which manages action sequences more effectively.
  • Replaced the FindSequence method with GetOrAddSequence to streamline sequence retrieval and addition, improving code clarity and efficiency.

Changes walkthrough 📝

Relevant files
Enhancement
ActionBuilder.cs
Enhance ActionBuilder with nullable annotations and refactoring

dotnet/src/webdriver/Interactions/ActionBuilder.cs

  • Enabled nullable reference types for better null safety.
  • Changed sequences to be a readonly dictionary.
  • Refactored AddAction to use ProcessTick.
  • Replaced FindSequence with GetOrAddSequence for sequence management.
  • +25/-9   

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link
    Contributor

    qodo-merge-pro bot commented Dec 2, 2024

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Possible Bug
    The usedDevices list is populated but never used in ProcessTick method. The check for duplicate devices may not work as intended.

    Code Smell
    The AddAction method calls ProcessTick with a single interaction but there's also a ProcessTick method for multiple interactions. Consider consolidating these to avoid code duplication.

    Copy link
    Contributor

    qodo-merge-pro bot commented Dec 2, 2024

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Fix a critical bug where duplicate device actions are not properly prevented due to missing device tracking

    Add the missing usedDevices.Add(interaction.SourceDevice) call to properly track
    used devices and prevent duplicate actions per device in a tick.

    dotnet/src/webdriver/Interactions/ActionBuilder.cs [111-117]

     foreach (Interaction interaction in interactionsToAdd)
     {
         if (usedDevices.Contains(interaction.SourceDevice))
         {
             throw new ArgumentException("You can only add one action per device for a single tick.");
         }
    +    usedDevices.Add(interaction.SourceDevice);
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: The suggestion identifies a critical bug where the code checks for duplicate devices but fails to track used devices, potentially allowing multiple actions per device in a single tick. Adding usedDevices.Add() is essential for the check to work correctly.

    9
    Complete the initialization of a critical variable used for sequence management

    Initialize the longestSequenceLength variable before using it in the
    GetOrAddSequence method, as the code block appears incomplete.

    dotnet/src/webdriver/Interactions/ActionBuilder.cs [142-143]

     int longestSequenceLength = 0;
     foreach (KeyValuePair<InputDevice, ActionSequence> pair in this.sequences)
    +{
    +    longestSequenceLength = Math.Max(longestSequenceLength, pair.Value.Count);
    +}
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion correctly identifies an incomplete implementation where longestSequenceLength is declared but not properly initialized, which could lead to incorrect sequence management. The fix is essential for proper functionality.

    8

    💡 Need additional feedback ? start a PR chat

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant