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

[js] Fix linting #13753

Merged
merged 2 commits into from
Apr 1, 2024
Merged

[js] Fix linting #13753

merged 2 commits into from
Apr 1, 2024

Conversation

pujagani
Copy link
Contributor

@pujagani pujagani commented Mar 28, 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

Fix linting for JS binding

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.

Type

enhancement, bug_fix


Description

  • Simplified preload script handling in Bidi tests by removing redundant window handle retrievals.
  • Standardized the file system module import in setFiles_command_test.js.
  • Cleaned up imports and dependencies in storage_test.js and driver_factory.js.
  • Refactored driver_factory.js to improve clarity and correctness.
  • Optimized linting and formatting configurations in BUILD.bazel for efficiency.

Changes walkthrough

Relevant files
Enhancement
script_test.js
Simplify Preload Script Handling in Bidi Tests                     

javascript/node/selenium-webdriver/test/bidi/script_test.js

  • Removed redundant getWindowHandle calls in multiple test cases.
  • Enhanced script management by simplifying preload script handling.
  • +0/-6     
    setFiles_command_test.js
    Standardize File System Module Import                                       

    javascript/node/selenium-webdriver/test/bidi/setFiles_command_test.js

  • Updated fs module import to use the more common require('fs') instead
    of require('node:fs').
  • +1/-1     
    storage_test.js
    Clean Up Storage Test Imports                                                       

    javascript/node/selenium-webdriver/test/bidi/storage_test.js

  • Removed unused ignore import.
  • Cleaned up imports and dependencies.
  • +1/-1     
    driver_factory.js
    Refactor Driver Factory for Clarity and Correctness           

    javascript/node/selenium-webdriver/test/driver_factory.js

  • Removed unused Builder import.
  • Added missing require comment for ESLint.
  • Fixed Browser.SAFARI reference to use imported Browser enum.
  • +3/-2     
    Configuration changes
    BUILD.bazel
    Optimize Linting and Formatting Test Configurations           

    javascript/node/selenium-webdriver/BUILD.bazel

  • Added size = "small" to eslint-test and prettier-test configurations.
  • +2/-0     

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link
    Contributor

    PR Description updated to latest commit (fd61808)

    Copy link
    Contributor

    PR Review

    ⏱️ Estimated effort to review [1-5]

    2, because the changes are mostly about code simplification and minor adjustments. The removal of redundant code and the switch from 'node:fs' to 'fs' are straightforward. The eslint and prettier configurations are also simple changes.

    🧪 Relevant tests

    No

    🔍 Possible issues

    Possible Bug: The removal of const id = await driver.getWindowHandle() in multiple tests without a clear explanation might introduce issues if the window handle was used for context or scoping in any subsequent calls. It's important to ensure that these changes do not affect the tests' ability to accurately assess the functionality they are designed to test.

    🔒 Security concerns

    No


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.

    The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.

    • When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:
    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    
    [pr_reviewer]
    some_config1=...
    some_config2=...
    

    See the review usage page for a comprehensive guide on using this tool.

    Copy link
    Contributor

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Best practice
    Use scoped package name for built-in Node.js modules.

    Consider using the scoped package name node:fs instead of fs for importing the File System
    module. This makes it explicit that you're using a built-in Node.js module and can help
    avoid conflicts with any local or third-party modules named fs.

    javascript/node/selenium-webdriver/test/bidi/setFiles_command_test.js [28]

    -const fs = require('fs')
    +const fs = require('node:fs')
     
    Possible issue
    Ensure necessary classes are imported.

    It seems that the Builder class import was removed, but it might still be necessary for
    the file's functionality. Ensure that if Builder is used in this file, it is properly
    imported from ../index. If Builder is not used, then this change is fine.

    javascript/node/selenium-webdriver/test/driver_factory.js [22]

    -const { Browser } = require('../index')
    +const { Builder, Browser } = require('../index')
     
    Ensure Browser is correctly imported and used.

    The change from webdriver.Browser.SAFARI to Browser.SAFARI might introduce a reference
    error if Browser is not correctly imported or defined in the scope. Ensure that Browser is
    imported from the correct module and contains the SAFARI property.

    javascript/node/selenium-webdriver/test/driver_factory.js [94]

    +const { Browser } = require('../index');
     builder.forBrowser(Browser.SAFARI)
     
    Maintainability
    Handle potentially missing modules gracefully.

    Replace the commented-out eslint-disable-next-line node/no-missing-require with a check to
    ensure that the @bazel/runfiles module is available or handle the case where it's missing.
    This approach improves code robustness and maintainability.

    javascript/node/selenium-webdriver/test/driver_factory.js [27]

    -// eslint-disable-next-line node/no-missing-require
    -const { runfiles } = require('@bazel/runfiles')
    +let runfiles;
    +try {
    +  runfiles = require('@bazel/runfiles');
    +} catch (error) {
    +  console.error('Module @bazel/runfiles is missing');
    +  // Handle the missing module appropriately
    +}
     
    Enhancement
    Add size attribute to all test rules for clarity.

    For consistency and clarity, consider adding a size attribute to all test rules, not just
    eslint-test and prettier-test. This helps in understanding the expected resource
    consumption and execution time of the tests.

    javascript/node/selenium-webdriver/BUILD.bazel [190]

    -size = "small",
    +# Example for another test rule
    +my_test_rule(
    +  name = "example-test",
    +  size = "small",
    +  # other attributes...
    +)
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

    • When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:
    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    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