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
Add Style/MethodCallWithArgsParentheses cop #3797
Add Style/MethodCallWithArgsParentheses cop #3797
Conversation
456fe7f
to
4eff5e7
Compare
This is a great start! 😀 I opened an issue for this recently, so you can reference that id in the Also, I think we should not release this cop without a whitelisting configuration option, so that when people (inevitably) start posting issues about some methods, we can point them to that. Also some methods (like |
@Drenmi Yes, I fully agree with you. Do we have a default list of Method which needs to be ignored? |
@dominh: Unfortunately not. The ones I can think of, off the top of my head are:
These all live in There are others that are framework specific, like render in Rails, and a bunch of stuff in RSpec, but this is not something RuboCop should know of. Hence the importance for the whitelisting option. 😀 |
Probably they should remain separate cops. And we should probably rename the old cop, as it's name is super misleading.
Sure. If you make it work properly. ;-) There were a few attempts to make a cop that knew where parens were needed and when it was ok to omit them, but none of them got far enough to be merged and used. |
Any progress here? |
For now, I'd to stay with this cop disabled by default and I'd to add possibility of ignoring some methods because I haven't any idea what should be ignored by default. In Ruby, we have a lot of DSL and so on which looks better when method calls haven't parentheses. I'm going to look into code tomorrow on the evening. What do you think? |
4eff5e7
to
de8df2a
Compare
I've just update the commit |
# parameters. | ||
# As in popular Ruby's frameworks a lot of methods should always be | ||
# called without parentheses, | ||
# users can ignore them by passing their names to IgnoredMethods option. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add some code examples here.
As in popular Ruby's frameworks a lot of methods should always be called without parentheses, | ||
users can ignore them by passing their names to IgnoredMethods option. | ||
|
||
### Example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you edit this file manually? I'm surprised to see examples here when there are none in the cop's description.
de8df2a
to
d3787d3
Compare
@bbatsov yeah, it looks like I did these changes manually, strange. Anyway, I've fixed it and updated a commit. |
👍 |
This change improves obsolete warnings in three ways. 1. Show all obsoletes -------- Currently, RuboCop displays first obsolete warning only. ```yaml # two obsolete cops Style/SingleSpaceBeforeFirstArg: Enabled: false Style/SpaceBeforeModifierKeyword: Enabled: false ``` ``` Error: The `Style/SingleSpaceBeforeFirstArg` cop has been renamed to `Style/SpaceBeforeFirstArg. (obsolete configuration found in /tmp/tmp.9T2ers7SW8/.rubocop.yml, please update it) ``` This change makes to display all obsolete warnings. ``` Error: The `Style/SingleSpaceBeforeFirstArg` cop has been renamed to `Style/SpaceBeforeFirstArg.` (obsolete configuration found in /tmp/tmp.9T2ers7SW8/.rubocop.yml, please update it) The `Style/SpaceBeforeModifierKeyword` cop has been removed. Please use `Style/SpaceAroundKeyword` instead. (obsolete configuration found in /tmp/tmp.9T2ers7SW8/.rubocop.yml, please update it) ``` 2. Add obsolete cops --------- `Style/MethodCallParentheses` and `Lint/Eval` are renamed. - rubocop#3797 - rubocop#3820 So, I added the cops to `OBSOLATE_COPS`. 3. Add obsolete parameters In rubocop#3765, some cop's parameters are renamed. So, I added the parameters to `OBSOLATE_PARAMETERS`
This change improves obsolete warnings in three ways. 1. Show all obsoletes -------- Currently, RuboCop displays first obsolete warning only. ```yaml # two obsolete cops Style/SingleSpaceBeforeFirstArg: Enabled: false Style/SpaceBeforeModifierKeyword: Enabled: false ``` ``` Error: The `Style/SingleSpaceBeforeFirstArg` cop has been renamed to `Style/SpaceBeforeFirstArg. (obsolete configuration found in /tmp/tmp.9T2ers7SW8/.rubocop.yml, please update it) ``` This change makes to display all obsolete warnings. ``` Error: The `Style/SingleSpaceBeforeFirstArg` cop has been renamed to `Style/SpaceBeforeFirstArg.` (obsolete configuration found in /tmp/tmp.9T2ers7SW8/.rubocop.yml, please update it) The `Style/SpaceBeforeModifierKeyword` cop has been removed. Please use `Style/SpaceAroundKeyword` instead. (obsolete configuration found in /tmp/tmp.9T2ers7SW8/.rubocop.yml, please update it) ``` 2. Add obsolete cops --------- `Style/MethodCallParentheses` and `Lint/Eval` are renamed. - #3797 - #3820 So, I added the cops to `OBSOLATE_COPS`. 3. Add obsolete parameters In #3765, some cop's parameters are renamed. So, I added the parameters to `OBSOLATE_PARAMETERS`
This cop checks presence of parentheses in method calls containing parameters.
Example
I'm not sure if I should merge it with Style/MethodCallParentheses or something?
Should I make this cop enabled by default?
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
rake generate_cops_documentation
(required only when you've added a new cop or changed the configuration/documentation of an existing cop).