Skip to content

Commit

Permalink
Merge pull request #2199 from coopdevs/auto-correct-cops
Browse files Browse the repository at this point in the history
Auto correct cops
  • Loading branch information
sauloperez authored Apr 16, 2018
2 parents b1fc15f + 147a74f commit 1abfe2a
Show file tree
Hide file tree
Showing 38 changed files with 57 additions and 171 deletions.
101 changes: 0 additions & 101 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,6 @@ Layout/AlignParameters:
- 'spec/lib/open_food_network/user_balance_calculator_spec.rb'
- 'spec/support/request/authentication_workflow.rb'

# Offense count: 8
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentOneStep, IndentationWidth.
# SupportedStyles: case, end
Layout/CaseIndentation:
Exclude:
- 'app/models/enterprise.rb'
- 'app/models/product_importer.rb'

# Offense count: 3
# Cop supports --auto-correct.
Layout/ClosingParenthesisIndentation:
Exclude:
- 'app/overrides/add_capture_order_shortcut.rb'
- 'spec/serializers/variant_serializer_spec.rb'

# Offense count: 8
# Cop supports --auto-correct.
Layout/CommentIndentation:
Expand Down Expand Up @@ -261,16 +245,6 @@ Layout/EmptyLines:
- 'spec/support/delayed_job_helper.rb'
- 'spec/support/matchers/table_matchers.rb'

# Offense count: 6
# Cop supports --auto-correct.
Layout/EmptyLinesAroundAccessModifier:
Exclude:
- 'app/controllers/admin/order_cycles_controller.rb'
- 'app/controllers/spree/admin/shipping_methods_controller_decorator.rb'
- 'app/helpers/angular_form_builder.rb'
- 'spec/helpers/products_helper_spec.rb'
- 'spec/support/request/web_helper.rb'

# Offense count: 66
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Expand Down Expand Up @@ -362,44 +336,6 @@ Layout/EmptyLinesAroundClassBody:
- 'lib/open_food_network/rack_request_blocker.rb'
- 'lib/open_food_network/reports/bulk_coop_report.rb'

# Offense count: 7
# Cop supports --auto-correct.
Layout/EmptyLinesAroundExceptionHandlingKeywords:
Exclude:
- 'app/controllers/checkout_controller.rb'
- 'app/controllers/enterprises_controller.rb'
- 'app/controllers/shop_controller.rb'
- 'app/models/spree/adjustment_decorator.rb'
- 'app/models/spree/tax_rate_decorator.rb'
- 'lib/tasks/users.rake'
- 'spec/features/admin/overview_spec.rb'

# Offense count: 4
# Cop supports --auto-correct.
Layout/EmptyLinesAroundMethodBody:
Exclude:
- 'app/controllers/checkout_controller.rb'
- 'app/controllers/spree/admin/reports_controller_decorator.rb'
- 'app/serializers/api/product_serializer.rb'
- 'lib/open_food_network/orders_and_fulfillments_report.rb'

# Offense count: 11
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
Layout/EmptyLinesAroundModuleBody:
Exclude:
- 'app/helpers/add_to_cart_helper.rb'
- 'app/helpers/groups_helper.rb'
- 'lib/open_food_network/column_preference_defaults.rb'
- 'lib/open_food_network/group_buy_report.rb'
- 'lib/open_food_network/order_cycle_form_applicator.rb'
- 'lib/open_food_network/order_grouper.rb'
- 'lib/open_food_network/variant_and_line_item_naming.rb'
- 'spec/models/spree/ability_spec.rb'
- 'spec/support/request/distribution_helper.rb'
- 'spec/support/request/ui_component_helper.rb'

# Offense count: 55
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
Expand Down Expand Up @@ -443,29 +379,13 @@ Layout/ExtraSpacing:
- 'spec/spec_helper.rb'
- 'spec/support/request/web_helper.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: consistent, special_for_inner_method_call, special_for_inner_method_call_in_parentheses
Layout/FirstParameterIndentation:
Exclude:
- 'lib/open_food_network/permissions.rb'
- 'spec/serializers/variant_serializer_spec.rb'

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: SupportedStyles, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
Layout/IndentArray:
EnforcedStyle: consistent

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: IndentationWidth.
Layout/IndentAssignment:
Exclude:
- 'app/controllers/spree/admin/reports_controller_decorator.rb'

# Offense count: 52
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
Expand All @@ -489,14 +409,6 @@ Layout/IndentHash:
- 'spec/lib/open_food_network/order_cycle_form_applicator_spec.rb'
- 'spec/support/request/authentication_workflow.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
Layout/IndentHeredoc:
Exclude:
- 'app/models/content_configuration.rb'

# Offense count: 21
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Expand Down Expand Up @@ -566,19 +478,6 @@ Layout/LeadingCommentSpace:
- 'spec/support/matchers/select2_matchers.rb'
- 'spec/support/request/authentication_workflow.rb'

# Offense count: 10
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: symmetrical, new_line, same_line
Layout/MultilineArrayBraceLayout:
Exclude:
- 'lib/open_food_network/customers_report.rb'
- 'lib/open_food_network/order_cycle_management_report.rb'
- 'lib/open_food_network/orders_and_fulfillments_report.rb'
- 'lib/open_food_network/packing_report.rb'
- 'lib/open_food_network/xero_invoices_report.rb'
- 'spec/archive/features/consumer/checkout_spec.rb'

# Offense count: 44
# Cop supports --auto-correct.
Layout/MultilineBlockLayout:
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/order_cycles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def notify_producers


protected

def collection
return Enterprise.where("1=0") unless json_request?
return order_cycles_from_set if params[:order_cycle_set]
Expand All @@ -130,6 +131,7 @@ def collection_actions
end

private

def load_data_for_index
if json_request?
# Split ransack params into all those that currently exist and new ones to limit returned ocs to recent or undated
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/checkout_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def set_default_bill_address
customer_bill_address_id = @order.customer.bill_address.andand.id
@order.customer.update_attributes(bill_address_attributes: new_bill_address.merge('id' => customer_bill_address_id))
end

end

def set_default_ship_address
Expand Down Expand Up @@ -133,7 +132,6 @@ def object_params
def advance_order_state(order)
tries ||= 3
order.next

rescue ActiveRecord::StaleObjectError
retry unless (tries -= 1).zero?
false
Expand Down
1 change: 0 additions & 1 deletion app/controllers/enterprises_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def check_permalink
begin
Rails.application.routes.recognize_path( "/#{ params[:permalink].to_s }" )
render text: params[:permalink], status: 409

rescue ActionController::RoutingError
render text: params[:permalink], status: 200
end
Expand Down
1 change: 0 additions & 1 deletion app/controllers/shop_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def products
products_json = filter(renderer.products_json)

render json: products_json

rescue OpenFoodNetwork::CachedProductsRenderer::NoProducts
render status: 404, json: ''
end
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/spree/admin/reports_controller_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ def orders_and_fulfillment
csv_file_name = "#{params[:report_type]}_#{timestamp}.csv"

render_report(@report.header, @table, params[:csv], csv_file_name)

end

def products_and_inventory
Expand Down Expand Up @@ -320,9 +319,9 @@ def authorized_reports
reports[:order_cycle_management][:description] =
render_to_string(partial: 'order_cycle_management_description', layout: false, locals: {report_types: report_types[:order_cycle_management]}).html_safe
reports[:packing][:description] =
render_to_string(partial: 'packing_description', layout: false, locals: {report_types: report_types[:packing]}).html_safe
render_to_string(partial: 'packing_description', layout: false, locals: {report_types: report_types[:packing]}).html_safe
reports[:sales_tax][:description] =
render_to_string(partial: 'sales_tax_description', layout: false, locals: {report_types: report_types[:sales_tax]}).html_safe
render_to_string(partial: 'sales_tax_description', layout: false, locals: {report_types: report_types[:sales_tax]}).html_safe

# Return only reports the user is authorized to view.
reports.select { |action| can? action, :report }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def do_not_destroy_referenced_shipping_methods
end

private

def load_hubs
@hubs = Enterprise.managed_by(spree_current_user).is_distributor.sort_by!{ |d| [(@shipping_method.has_distributor? d) ? 0 : 1, d.name] }
end
Expand Down
1 change: 0 additions & 1 deletion app/helpers/add_to_cart_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ def available_distributors_for(order, product)
def available_order_cycles_for(order, product)
DistributionChangeValidator.new(order).available_order_cycles_for(product)
end

end
1 change: 1 addition & 0 deletions app/helpers/angular_form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def ng_collection_select(method, collection, value_method, text_method, angular_
end

private

def angular_name(method)
"#{@object_name}[#{@fields_for_record_name}_attributes][{{ $index }}][#{method}]"
end
Expand Down
2 changes: 0 additions & 2 deletions app/helpers/groups_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module GroupsHelper

def link_to_service(baseurl, name, html_options = {})
return if name.blank?
html_options = html_options.merge target: '_blank'
Expand All @@ -19,5 +18,4 @@ def ext_url(prefix, url)
def strip_url(url)
url.andand.sub(/^https?:\/\//i, '')
end

end
8 changes: 4 additions & 4 deletions app/models/content_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ class ContentConfiguration < Spree::Preferences::FileConfiguration
preference :footer_pinterest_url, :string, default: ""
preference :footer_email, :string, default: "[email protected]"
preference :community_forum_url, :string, default: "http://community.openfoodnetwork.org"
preference :footer_links_md, :text, default: <<-EOS
[Newsletter sign-up](/)
preference :footer_links_md, :text, default: <<-EOS.strip_heredoc
[Newsletter sign-up](/)
[News](/)
[News](/)
[Calendar](/)
[Calendar](/)
EOS

preference :footer_about_url, :string, default: "http://www.openfoodnetwork.org/ofn-local/open-food-network-australia/"
Expand Down
24 changes: 12 additions & 12 deletions app/models/enterprise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,18 +289,18 @@ def category

# Map backend cases to front end cases.
case cat
when "producer_sells_any"
:producer_hub # Producer hub who sells own and others produce and supplies other hubs.
when "producer_sells_own"
:producer_shop # Producer with shopfront and supplies other hubs.
when "producer_sells_none"
:producer # Producer only supplies through others.
when "non_producer_sells_any"
:hub # Hub selling others products in order cycles.
when "non_producer_sells_own"
:hub # Wholesaler selling through own shopfront? Does this need a separate name? Should it exist?
when "non_producer_sells_none"
:hub_profile # Hub selling outside the system.
when "producer_sells_any"
:producer_hub # Producer hub who sells own and others produce and supplies other hubs.
when "producer_sells_own"
:producer_shop # Producer with shopfront and supplies other hubs.
when "producer_sells_none"
:producer # Producer only supplies through others.
when "non_producer_sells_any"
:hub # Hub selling others products in order cycles.
when "non_producer_sells_own"
:hub # Wholesaler selling through own shopfront? Does this need a separate name? Should it exist?
when "non_producer_sells_none"
:hub_profile # Hub selling outside the system.
end
end

Expand Down
10 changes: 5 additions & 5 deletions app/models/product_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,12 @@ def reset_absent_products
def assign_defaults(object, entry)
@import_settings[entry['supplier_id'].to_s]['defaults'].each do |attribute, setting|
case setting['mode']
when 'overwrite_all'
when 'overwrite_all'
object.assign_attributes(attribute => setting['value'])
when 'overwrite_empty'
if object.send(attribute).blank? or (attribute == 'on_hand' and entry['on_hand_nil'])
object.assign_attributes(attribute => setting['value'])
when 'overwrite_empty'
if object.send(attribute).blank? or (attribute == 'on_hand' and entry['on_hand_nil'])
object.assign_attributes(attribute => setting['value'])
end
end
end
end
end
Expand Down
1 change: 0 additions & 1 deletion app/models/spree/adjustment_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def self.without_callbacks
skip_callback :destroy, :after, :update_adjustable

result = yield

ensure
set_callback :save, :after, :update_adjustable
set_callback :destroy, :after, :update_adjustable
Expand Down
1 change: 0 additions & 1 deletion app/models/spree/tax_rate_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def with_tax_included_in_price
calculator.calculable.included_in_price = true

result = yield

ensure
self.included_in_price = old_included_in_price
calculator.calculable.included_in_price = old_included_in_price
Expand Down
4 changes: 2 additions & 2 deletions app/overrides/add_capture_order_shortcut.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
:name => "add_capture_order_shortcut",
:insert_bottom => "[data-hook='admin_orders_index_row_actions']",
:partial => 'spree/admin/orders/capture'
)
)
# And align actions column (not spree standard, but looks better IMO)
Deface::Override.new(:virtual_path => "spree/admin/orders/index",
:name => "add_capture_order_shortcut_align",
:set_attributes => "[data-hook='admin_orders_index_row_actions']",
:attributes => {:class => "actions", :style => "text-align:left;"} #removes 'align-center' class
)
)
1 change: 0 additions & 1 deletion app/serializers/api/product_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def price
else
object.master.price_with_fees(options[:current_distributor], options[:current_order_cycle])
end

end
end

Expand Down
1 change: 0 additions & 1 deletion lib/open_food_network/column_preference_defaults.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module OpenFoodNetwork
module ColumnPreferenceDefaults

private

# NOTE: These methods define valid column names (via hash keys)
Expand Down
3 changes: 1 addition & 2 deletions lib/open_food_network/customers_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def table
ba.phone,
order.distributor.andand.name,
[da.andand.address1, da.andand.address2, da.andand.city].join(" "),
order.shipping_method.andand.name
]
order.shipping_method.andand.name]
end
end
end
Expand Down
1 change: 0 additions & 1 deletion lib/open_food_network/group_buy_report.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module OpenFoodNetwork

GroupBuyVariantRow = Struct.new(:variant, :sum_quantities, :sum_max_quantities) do
def to_row
[variant.product.supplier.name, variant.product.name, I18n.t('admin.reports.unitsize'), variant.options_text, variant.weight, sum_quantities, sum_max_quantities]
Expand Down
1 change: 0 additions & 1 deletion lib/open_food_network/order_cycle_form_applicator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'open_food_network/order_cycle_permissions'

module OpenFoodNetwork

# There are two translator classes on the boundary between Angular and Rails: On the Angular side,
# there is the OrderCycle#dataForSubmit method, and on the Rails side is this class. I think data
# translation is more a responsibility of Angular, so I'd be inclined to refactor this class to move
Expand Down
Loading

0 comments on commit 1abfe2a

Please sign in to comment.