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

Style/NestedParenthesizedCalls rspec whitelist is non-exhaustive #2976

Closed
ncanning opened this issue Mar 22, 2016 · 4 comments
Closed

Style/NestedParenthesizedCalls rspec whitelist is non-exhaustive #2976

ncanning opened this issue Mar 22, 2016 · 4 comments

Comments

@ncanning
Copy link

RuboCop triggers a violation on some rspec methods that are left out of the list of rspec matchers. In my case, this specifically occurs with be_an:

FNG145099:tmp nathan$ cat test.rb 
should((be nil).or(be_an Integer))
FNG145099:tmp nathan$ rubocop -V
0.38.0 (using Parser 2.3.0.6, running on ruby 2.1.5 x86_64-darwin14.0)
FNG145099:tmp nathan$ rubocop
Inspecting 1 file
C

Offenses:

test.rb:1:20: C: Style/NestedParenthesizedCalls: Add parentheses to nested method call be_an Integer.
should((be nil).or(be_an Integer))
                   ^^^^^^^^^^^^^

1 file inspected, 1 offense detected
@tejasbubane
Copy link
Contributor

There are a lot of matchers which are missing in the list (eg. exist, throw_symbol, etc) and the list will keep growing as rspec grows. I think we should not make our core cop logic dependent on some other gem. Let the user disable the cop whenever required. Thoughts?

@ncanning
Copy link
Author

I agree in principle, but by including some rspec matchers, it seems rubocop is somewhat dependent on rspec already, but still produces inconsistent behavior depending on which rspec matchers you're using. Yes, you can just disable the cop if you run into that issue, but I feel that you're sweeping the problem under the rug at that point. Perhaps it's better to remove any rspec dependent logic from the core of rubocop, and put that logic in an rspec-specific cop, e.g. Rubocop-Rspec.

@bbatsov
Copy link
Collaborator

bbatsov commented Jun 20, 2016

Why do you think that is RuboCop dependent on rspec?

Probably it'd be best to drop this functionality and just leave it to people to configure the cop. Hardcoded config is bad, but the option to add/alter config is great.

@ncanning
Copy link
Author

Maybe "dependent" isn't exactly the word, but the correctness of this cop relies on the current state of Rspec. I agree though, having some ability to configure this whitelist would be super helpful.

Drenmi added a commit to Drenmi/rubocop that referenced this issue Jul 10, 2017
…tedParenthesizedCalls` cop

This cop was using hard coded RSpec methods for whitelisting. This change
moves the whitelist into a configuration option.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants