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

[Rule] Duplicated Variable Name #1119

Open
sebastianciupinski opened this issue Oct 3, 2024 · 2 comments
Open

[Rule] Duplicated Variable Name #1119

sebastianciupinski opened this issue Oct 3, 2024 · 2 comments

Comments

@sebastianciupinski
Copy link

Robot Framework still have flat, common variables namespace. When you define the same variable in more than one resource or variablefile, and import them both, execution results may be unpredictable. That would be great if robocop will catch such problems.

@Lakitna
Copy link
Contributor

Lakitna commented Dec 14, 2024

I've made this for our codebase (which is proprietary, unfortunately). I did not build it in Robocop though.

Instead, I made a runtime keyword that logs all variables with duplicate values. But this only works when Robot has created the current scope (e.g. did all imports). This is why I needed to do it in the Robot runtime instead of Robocop.

While writing this I realize that we might have a small communication issue here. Are we talking about:

  1. Duplicate variable names
    For example, the variable ${foo} is defined in both amazing.resource and beautiful.resource

    # amazing.resource
    *** Variables ***
    ${foo}    123
    # beautiful.resource
    *** Variables ***
    ${foo}    Hello, world!
  2. Duplicate variable values
    For example, you've defined the same base URL twice:

    # amazing.resource
    *** Variables ***
    ${foo}    https://example.com
    # beautiful.resource
    *** Variables ***
    ${not_foo}    https://example.com

The second one is what I implemented in our codebase.

@bhirsz
Copy link
Member

bhirsz commented Dec 15, 2024

I believe the author of the thread is talking about 1). Which is quite unpredictable in Robot Framework. If you import resource, and it imports another, you will have hard time tracking which variable will be finally used (it depends on the order of imports etc). It's now currently possible to catch this in our linter, but maybe it would in the Robotcode (as he already finds not used keywords etc in his IDE plugin and tool). We may benefit from potential cooperation between Robocop and Robotcode.

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

No branches or pull requests

3 participants