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

there is bug in Lint/DuplicateHashKey cop #11953

Closed
Ivanov-Anton opened this issue Jun 15, 2023 · 0 comments · Fixed by #11955
Closed

there is bug in Lint/DuplicateHashKey cop #11953

Ivanov-Anton opened this issue Jun 15, 2023 · 0 comments · Fixed by #11955
Labels

Comments

@Ivanov-Anton
Copy link

The "Lint/DuplicateHashKey" cop in Robocop does not correctly flag offenses for duplicate hash keys in the provided code snippets.

Code Snippet 1:

ACTIONS = {
  HAS_1 => {
    SUB_HASH_1 => 'string',
    SUB_HASH_2 => 'string',
    SUB_HASH_3 => 'string',
    SUB_HASH_4 => 'string',
    SUB_HASH_5 => 'string',
    SUB_HASH_1 => 'string'
    
  }.freeze,
}.freeze

Expected Behavior:

According to the "Lint/DuplicateHashKey" cop, the duplicate key "SUB_HASH_1" should be flagged as an offense. However, in the provided code snippet, the cop does not generate any offense and ignores the duplicate key.

Code Snippet 2:

resource_classes = {
  PAS::REST::MAIN => {
    plan: :main_plan
  },
  RAM::REST::MAIN => {
    second_plan: :second_plan_value
  },
  PAS::REST::MAIN => {
    # some commented line
  }
}

Expected Behavior:

Similarly, the cop should flag the duplicate key "PAS::REST::MAIN" as an offense in the above code snippet. However, it fails to do so.


Environment:

robocop version: "1.52.1"

@Ivanov-Anton Ivanov-Anton changed the title there is bug in Lint/DuplicateHashKey cop there is bug in Lint/DuplicateHashKey cop Jun 15, 2023
@koic koic added the bug label Jun 15, 2023
koic added a commit to koic/rubocop that referenced this issue Jun 19, 2023
Fixes rubocop#11953.

This PR fixes a false negative for `Lint/DuplicateHashKey`
when there is a duplicated constant key in the hash literal.
bbatsov pushed a commit that referenced this issue Jun 19, 2023
Fixes #11953.

This PR fixes a false negative for `Lint/DuplicateHashKey`
when there is a duplicated constant key in the hash literal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants