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

Unhandled Edge Case: Style/AccessModifierDeclarations #13213

Closed
CoderMiguel opened this issue Sep 9, 2024 · 1 comment · Fixed by #13214
Closed

Unhandled Edge Case: Style/AccessModifierDeclarations #13213

CoderMiguel opened this issue Sep 9, 2024 · 1 comment · Fixed by #13214
Labels

Comments

@CoderMiguel
Copy link

CoderMiguel commented Sep 9, 2024

similar to #5953

Expected behavior

I expect symbol array literal notation to not be offensive to RuboCop

class MyClass
  ... # some public methods
  
  private
  
  def mata_programming_method # to remain private
    # leverages __callee__ (the name of the alias method) for dynamic behavior
    ...
  end
  alias my_first_alias mata_programming_method
  alias my_second_alias mata_programming_method

  public(*%i[my_first_alias my_second_alias]) 
end

Actual behavior

Describe here what actually happened.
Offenses:

[Correctable] Style/AccessModifierDeclarations: public should not be inlined in method definitions.
  public(*%i[my_first_alias my_second_alias])
  ^^^^^^

1 file inspected, 1 offense detected, 1 offense autocorrectable

Steps to reproduce the problem

refactor a non-offensive use of AllowModifiersOnSymbols: true (default)

  public :my_first_alias, :my_second_alias #=> No Offense

to use symbol array literal notation and re-run rubocop

  public(*%i[my_first_alias my_second_alias]) # => Style/AccessModifierDeclarations: `public` should not be inlined in method definitions.

Further down the rabbit hole

This is also throwing errors when the array of symbols is a variable or constant

  MY_PUBLIC_ALIASES = %i[my_first_alias my_second_alias].freeze
  public(*MY_PUBLIC_ALIASES) # => Style/AccessModifierDeclarations: `public` should not be inlined in method definitions.

When the array is not in array literal notation RuboCop suggests array literal notation, that is not being accepted by its sibling cop

  MY_PUBLIC_ALIASES = [:my_first_alias, :my_second_alias] # => Style/SymbolArray: Use `%i` or `%I` for an array of symbols.
  public(*MY_PUBLIC_ALIASES) # => Style/AccessModifierDeclarations: `public` should not be inlined in method definitions.

RuboCop version

rubocop -v => 1.66.1

@koic koic added the bug label Sep 9, 2024
koic added a commit to koic/rubocop that referenced this issue Sep 9, 2024
…arations`

Fixes rubocop#13213.

This PR fixes false positives for `Style/AccessModifierDeclarations` when `AllowModifiersOnAttrs: true`
and using splat with a percent array symbol literal, or with a constant.
koic added a commit to koic/rubocop that referenced this issue Sep 9, 2024
…arations`

Fixes rubocop#13213.

This PR fixes false positives for `Style/AccessModifierDeclarations` when `AllowModifiersOnAttrs: true`
and using splat with a percent symbol array, or with a constant.
@CoderMiguel
Copy link
Author

@koic thank you for the quick response to this issue. For what it is worth, the PR looks good to me.

bbatsov pushed a commit that referenced this issue Sep 24, 2024
Fixes #13213.

This PR fixes false positives for `Style/AccessModifierDeclarations` when `AllowModifiersOnAttrs: true`
and using splat with a percent symbol array, or with a constant.
koic added a commit to koic/rubocop that referenced this issue Sep 27, 2024
…arations`

Fixes rubocop#13213.

This PR fixes false positives for `Style/AccessModifierDeclarations` when `AllowModifiersOnAttrs: true`
and using splat with a percent symbol array, or with a constant.
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