How can I apply triple parentheses with RuboCop?

I have a coding standard that assumes that the initial argument of the triple should always be inside the brackets, regardless of the expression.

eg. foo = (thing.baz?) ? [] : thing.bar

The following should be considered a violation:

eg. foo = thing.baz? ? [] : thing.bar

Is it possible to achieve this with embedded copies of Rubocop, or does this require a special copy. If so, how do I implement it?

+6
source share
1 answer

I saw your question, so I went ahead and implemented a cop for you. The name is Style/TernaryParentheses , and the EnforcedStyle parameter is require_parentheses (not the default).

 # .rubocop.yml Style/TernaryParentheses: Enabled: true EnforcedStyle: require_parentheses 

You can start using it right now by putting it in your Gemfile :

 gem 'rubocop', git: 'git://github.com/bbatsov/rubocop.git' 

or you can wait for the release of 0.42.0 .

+12
source

All Articles