Replies: 2 comments 1 reply
-
|
RuboCop will have trouble with types here I think, bunch of false positives. It's lacking the type information for this to properly work. I guess it may make sense to have a generic cop that checks for Style/AliasedMethods:
Enabled: true
Aliases:
find_index: index
each_pair: pair
etc... |
Beta Was this translation helpful? Give feedback.
-
|
I don't think any new cop is needed here. You can add your own methods to Style/CollectionMethods:
PreferredMethods:
filter: 'select'The Hash methods ( See https://docs.rubocop.org/rubocop/cops_style.html#stylecollectionmethods and https://docs.rubocop.org/rubocop/cops_style.html#stylepreferredhashmethods |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to suggest an idea 💡 : having more aliases style cops!
There are many aliases in Ruby
Hash#selectHash#filterHash#each_pairHash#eachHash#include?Hash#has_key?Hash#value?Hash#has_value?Array#pushArray#appendArray#collectArray#mapArray#find_indexArray#indexI looked for existing alias cops, and it seems there are no alias cops for Ruby and 2 alias cops for RoR Rails/ActiveRecordAliases and Rails/ActiveSupportAliases.
Note: Style/Alias is for enforcing the use of either
#aliasor#alias_methodnot to enforce the style of aliases usage.It would be nice to have one or several aliases style cops for the ones who want to implement a consistent naming convention.
But then, a new question arises: are we going to make a group cop with all aliases (maybe too large), one cop per group / class / module (how to split that?) or one cop per alias (probably not, that would be too much)?
Style/Aliasesfor all Ruby standard library aliases (same withRSpec/Aliases,Minitest/Aliases)Style/ArrayAliases,Style/HashAliases, etc. aliases grouped by class / moduleStyle/ArrayPushAlias,Style/ArrayCollectAlias, etc. one cop per aliasThen I see one parameter so that it would be configurable:
EnforceAliases:never(default): using aliases is forbidden, must use only original method namealways: using original method name is forbidden, must use only aliasesmixed: allow using both aliases and original method namesThe depending on the grouping chosen:
AllowedClassesparameter to disable the cop for a specific classAllowedClasses: [Hash].AllowedMethodsparameter to disable the cop for a specific methodAllowedMethods: [push, collect].Beta Was this translation helpful? Give feedback.
All reactions