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/TernaryParentheses Not safe when run with "rubocop -a --safe" #7063

Closed
zw963 opened this issue May 21, 2019 · 1 comment
Closed

Style/TernaryParentheses Not safe when run with "rubocop -a --safe" #7063

zw963 opened this issue May 21, 2019 · 1 comment

Comments

@zw963
Copy link

zw963 commented May 21, 2019

image

Following is new code after refactor

@bookings.includes(:comments, :booking_fees).each do |b|
            data << [
              b.reservation_site.present? ? "#{b.source_i18n}(#{b.reservation_site})" : b.source_i18n,
              b.airbnb? or b.airbnb2? ? b.confirm_number : b.uid,
              b.id,
              b.dtstart.to_date,
              b.dtend.to_date,
              b.house.hotel? ? "#{b.house.name}(#{b.room_unit&.room_no})" : b.house,
              b.house.tag_list.to_s,
              b.house.hotel? ? b.room_unit&.room_no : '',
              b.user,
              b.user.try(:phone),
              b.user.try(:email),
              b.user.try(:settings).try(:[], 'location'),
              b.status_i18n,
              b.checkin_status_i18n,
              b.payment_status_i18n,
              b.guestnum,
              (b.dtend.to_date - b.dtstart.to_date).to_i,
              b.confirmed_at.try(:to_date),
              b.currency,
              b.total_fee,
              b.channel_fee_amount,
              b.total_host_paid_out_before_support_fee,
              b.settings[:points].to_f,
              b.ota_collect? ? b.total_fee.to_f - b.settings[:points].to_f : 0,
              b.hotel_collect_credit? or b.hotel_collect? ? b.paid_amount.to_f : 0,
              b.hotel_collect_cash? ? b.paid_amount.to_f : 0,
              b.paid? ? 0 : b.total_fee.to_f - b.channel_fee_amount.to_f,
              b.cleaning_fee_amount,
              b.house.user ? b.total_host_paid_out_before_support_fee.to_i * (b.house.user.commission_rate || 18) / 100 : '',
              b.comments.map {|c| "#{c.user&.username}: #{c.comment}"}.join("\n")
            ]
          end

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:

 ╰─ $ rubocop -V
0.69.0 (using Parser 2.6.3.0, running on ruby 2.6.2 x86_64-linux)
parkerfinch added a commit to parkerfinch/rubocop that referenced this issue Jun 2, 2019
This takes the precedence of operators used into account when deciding
to autocorrect. The issue is that if an operator of precedence below
that of the ternary operator (e.g. "or") is used, then the existing
autocorrect can change the semantics by removing parentheses. With
this change, the autocorrect will no longer attempt to make this
correction.
@bbatsov bbatsov closed this as completed in 3858f28 Jun 6, 2019
@zw963
Copy link
Author

zw963 commented Jun 8, 2019

Cool, thank for hard work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant