From a7c65a30acbce7acd764c8799c65800e7c8ff821 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Tue, 10 Jan 2017 15:23:26 +1030 Subject: [PATCH] Rubocop: Spacing around operators etc --- .rubocop_todo.yml | 69 ------------------- app/controllers/application_controller.rb | 2 +- .../entities/contacts_controller.rb | 2 +- app/helpers/application_helper.rb | 8 +-- app/helpers/tasks_helper.rb | 6 +- app/helpers/versions_helper.rb | 2 +- app/models/fields/field.rb | 2 +- config/environments/test.rb | 2 +- config/initializers/assets.rb | 2 +- lib/fat_free_crm/core_ext/string.rb | 2 +- lib/gravatar_image_tag.rb | 2 +- spec/controllers/tasks_controller_spec.rb | 2 +- spec/models/entities/opportunity_spec.rb | 2 +- spec/models/fields/custom_field_pair_spec.rb | 4 +- spec/support/auth_macros.rb | 4 +- spec/views/tasks/index.haml_spec.rb | 2 +- spec/views/tasks/update.js.haml_spec.rb | 14 ++-- 17 files changed, 29 insertions(+), 98 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a61bde5017..35a787a4b2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -666,75 +666,6 @@ Style/SingleLineBlockParams: Exclude: - 'spec/support/macros.rb' -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleInsidePipes, SupportedStyles. -# SupportedStyles: space, no_space -Style/SpaceAroundBlockParameters: - Exclude: - - 'spec/controllers/tasks_controller_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/SpaceAroundKeyword: - Exclude: - - 'lib/fat_free_crm/core_ext/string.rb' - -# Offense count: 15 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment. -Style/SpaceAroundOperators: - Exclude: - - 'app/controllers/entities/contacts_controller.rb' - - 'app/helpers/versions_helper.rb' - - 'app/models/fields/field.rb' - - 'config/environments/test.rb' - - 'spec/models/entities/opportunity_spec.rb' - - 'spec/models/fields/custom_field_pair_spec.rb' - - 'spec/views/tasks/index.haml_spec.rb' - - 'spec/views/tasks/update.js.haml_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: space, no_space -Style/SpaceBeforeBlockBraces: - Exclude: - - 'app/controllers/application_controller.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. -# SupportedStyles: space, no_space -Style/SpaceInsideBlockBraces: - Exclude: - - 'app/controllers/application_controller.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles. -# SupportedStyles: space, no_space, compact -Style/SpaceInsideHashLiteralBraces: - Exclude: - - 'app/helpers/application_helper.rb' - - 'spec/support/auth_macros.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/SpaceInsidePercentLiteralDelimiters: - Exclude: - - 'config/initializers/assets.rb' - -# Offense count: 8 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: space, no_space -Style/SpaceInsideStringInterpolation: - Exclude: - - 'app/helpers/application_helper.rb' - - 'app/helpers/tasks_helper.rb' - - 'lib/gravatar_image_tag.rb' - # Offense count: 7 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, AllowSafeAssignment. diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0600b502b7..7fd7bc9268 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -45,7 +45,7 @@ def auto_complete respond_to do |format| format.any(:js, :html) { render partial: 'auto_complete' } format.json do - render json: @auto_complete.each_with_object({}){|a, h| + render json: @auto_complete.each_with_object({}) { |a, h| h[a.id] = a.respond_to?(:full_name) ? h(a.full_name) : h(a.name); h } end diff --git a/app/controllers/entities/contacts_controller.rb b/app/controllers/entities/contacts_controller.rb index c245334512..bb7d8baf22 100644 --- a/app/controllers/entities/contacts_controller.rb +++ b/app/controllers/entities/contacts_controller.rb @@ -153,7 +153,7 @@ def get_accounts def set_options super - @naming = (current_user.pref[:contacts_naming] || Contact.first_name_position) unless params[:cancel].true? + @naming = (current_user.pref[:contacts_naming] || Contact.first_name_position) unless params[:cancel].true? end #---------------------------------------------------------------------------- diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b2ec94913b..c3e9d4bc8e 100755 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -36,7 +36,7 @@ def show_flash(options = { sticky: false }) #---------------------------------------------------------------------------- def subtitle(id, hidden = true, text = id.to_s.split("_").last.capitalize) content_tag("div", - link_to("#{ hidden ? '►' : '▼' } #{sanitize text}".html_safe, + link_to("#{hidden ? '►' : '▼'} #{sanitize text}".html_safe, url_for(controller: :home, action: :toggle, id: id), remote: true, onclick: "crm.flip_subtitle(this)" @@ -244,7 +244,7 @@ def refresh_sidebar(action = nil, shake = nil) #---------------------------------------------------------------------------- def refresh_sidebar_for(view, action = nil, shake = nil) text = "" - text << "$('#sidebar').html('#{ j render(partial: 'layouts/sidebar', locals: { view: view, action: action }) }');" + text << "$('#sidebar').html('#{j render(partial: 'layouts/sidebar', locals: { view: view, action: action })}');" text << "$('##{j shake.to_s}').effect('shake', { duration:200, distance: 3 });" if shake text.html_safe end @@ -439,7 +439,7 @@ def col(title, value = nil, last = false, email = false, &_block) def section_title(id, hidden = true, text = nil, info_text = nil) text = id.to_s.split("_").last.capitalize if text.nil? content_tag("div", class: "subtitle show_attributes") do - content = link_to("#{ hidden ? '►' : '▼' } #{sanitize text}".html_safe, + content = link_to("#{hidden ? '►' : '▼'} #{sanitize text}".html_safe, url_for(controller: :home, action: :toggle, id: id), remote: true, onclick: "crm.flip_subtitle(this)" @@ -520,7 +520,7 @@ def get_icon(name) # options = { renderer: {...} , params: {...} def paginate(options = {}) collection = options.delete(:collection) - options = { params: { action: 'index'}}.merge(options) if params['action'] == 'filter' + options = { params: { action: 'index' } }.merge(options) if params['action'] == 'filter' options = { renderer: RemoteLinkPaginationHelper::LinkRenderer }.merge(options) will_paginate(collection, options) end diff --git a/app/helpers/tasks_helper.rb b/app/helpers/tasks_helper.rb index 786c0b99e5..a3eac7d27a 100644 --- a/app/helpers/tasks_helper.rb +++ b/app/helpers/tasks_helper.rb @@ -94,21 +94,21 @@ def hide_task_and_possibly_bucket(task, bucket) def replace_content(task, bucket = nil) partial = (task.assigned_to && task.assigned_to != current_user.id) ? "assigned" : "pending" html = render(partial: "tasks/#{partial}", collection: [task], locals: { bucket: bucket }) - text = "$('##{dom_id(task)}').html('#{ j html }');\n".html_safe + text = "$('##{dom_id(task)}').html('#{j html}');\n".html_safe end #---------------------------------------------------------------------------- def insert_content(task, bucket, view) text = "$('#list_#{bucket}').show();\n" html = render(partial: view, collection: [task], locals: { bucket: bucket }) - text << "$('##{h bucket.to_s}').prepend('#{ j html }');\n" + text << "$('##{h bucket.to_s}').prepend('#{j html}');\n" text << "$('##{dom_id(task)}').effect('highlight', { duration:1500 });\n" text.html_safe end #---------------------------------------------------------------------------- def tasks_flash(message) - text = "$('#flash').html('#{ sanitize(message) }');\n" + text = "$('#flash').html('#{sanitize(message)}');\n" text << "crm.flash('notice', true)\n" text.html_safe end diff --git a/app/helpers/versions_helper.rb b/app/helpers/versions_helper.rb index d7f9d88154..a783b8c561 100644 --- a/app/helpers/versions_helper.rb +++ b/app/helpers/versions_helper.rb @@ -23,7 +23,7 @@ def parse_version(attr_name, change) first = link_to(h(account.name), account_path(account)) end if second.present? && (account = Account.find_by_id(second)) - second = link_to(h(account.name), account_path(account)) + second = link_to(h(account.name), account_path(account)) end end diff --git a/app/models/fields/field.rb b/app/models/fields/field.rb index 4ab45234f2..ce1c959bed 100644 --- a/app/models/fields/field.rb +++ b/app/models/fields/field.rb @@ -46,7 +46,7 @@ class Field < ActiveRecord::Base 'url' => { klass: 'CustomField', type: 'string' }, 'tel' => { klass: 'CustomField', type: 'string' }, 'select' => { klass: 'CustomField', type: 'string' }, - 'radio_buttons' => { klass: 'CustomField', type: 'string' }, + 'radio_buttons' => { klass: 'CustomField', type: 'string' }, 'check_boxes' => { klass: 'CustomField', type: 'text' }, 'boolean' => { klass: 'CustomField', type: 'boolean' }, 'date' => { klass: 'CustomField', type: 'date' }, diff --git a/config/environments/test.rb b/config/environments/test.rb index 8284cbc914..700f655d05 100755 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -28,7 +28,7 @@ config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment - config.action_controller.allow_forgery_protection = false + config.action_controller.allow_forgery_protection = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 5578b2bcda..a9f8a3237e 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -8,7 +8,7 @@ # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. -Rails.application.config.assets.precompile += %w( print.css chosen-sprite.png jquery-ui/* jquery_ui_datepicker/*.js ) +Rails.application.config.assets.precompile += %w(print.css chosen-sprite.png jquery-ui/* jquery_ui_datepicker/*.js) # Don't initialize Rails environment Rails.application.config.assets.initialize_on_precompile = false diff --git a/lib/fat_free_crm/core_ext/string.rb b/lib/fat_free_crm/core_ext/string.rb index 9bc137ab9c..4fec15ddfb 100644 --- a/lib/fat_free_crm/core_ext/string.rb +++ b/lib/fat_free_crm/core_ext/string.rb @@ -34,7 +34,7 @@ def false? # A query with 4 words will generate 6 permutations def name_permutations parts = split(" ") - (parts.size - 1).times.map do|i| + (parts.size - 1).times.map do |i| # ["A", "B", "C", "D"] => [["A B C", "D"], ["A B", "C D"], ["A", "B C D"]] [parts[(0..i)].join(" "), parts[(i + 1)..-1].join(" ")] end.each_with_object([]) do |perm, arr| diff --git a/lib/gravatar_image_tag.rb b/lib/gravatar_image_tag.rb index b84f9fc6bc..6b844a31b1 100644 --- a/lib/gravatar_image_tag.rb +++ b/lib/gravatar_image_tag.rb @@ -46,7 +46,7 @@ def self.gravatar_url_base(secure = false) end def self.gravatar_id(email, filetype = nil) - "#{ Digest::MD5.hexdigest(email) }#{ ".#{filetype}" unless filetype.nil? }" unless email.nil? + "#{Digest::MD5.hexdigest(email)}#{".#{filetype}" unless filetype.nil?}" unless email.nil? end def self.url_params(gravatar_params) diff --git a/spec/controllers/tasks_controller_spec.rb b/spec/controllers/tasks_controller_spec.rb index aff10d4739..b17ba5b836 100644 --- a/spec/controllers/tasks_controller_spec.rb +++ b/spec/controllers/tasks_controller_spec.rb @@ -14,7 +14,7 @@ def update_sidebar def produce_tasks(user, view) settings = (view != "completed" ? Setting.task_bucket : Setting.task_completed) - settings.each_with_object({}) do | due, hash | + settings.each_with_object({}) do |due, hash| hash[due] ||= [] if Date.tomorrow == Date.today.end_of_week && due == :due_tomorrow due = :due_this_week diff --git a/spec/models/entities/opportunity_spec.rb b/spec/models/entities/opportunity_spec.rb index 7e9ce3663e..7a25373e07 100644 --- a/spec/models/entities/opportunity_spec.rb +++ b/spec/models/entities/opportunity_spec.rb @@ -35,7 +35,7 @@ end it "should be possible to create opportunity with the same name" do - first = FactoryGirl.create(:opportunity, name: "Hello", user: current_user) + first = FactoryGirl.create(:opportunity, name: "Hello", user: current_user) expect { FactoryGirl.create(:opportunity, name: "Hello", user: current_user) }.to_not raise_error end diff --git a/spec/models/fields/custom_field_pair_spec.rb b/spec/models/fields/custom_field_pair_spec.rb index bea114b2e4..0fbe44d7fd 100644 --- a/spec/models/fields/custom_field_pair_spec.rb +++ b/spec/models/fields/custom_field_pair_spec.rb @@ -18,7 +18,7 @@ class CustomFieldFooPair @field = { 'as' => 'foopair', 'field_group_id' => 1, 'label' => 'Event' } @pair1 = { 'name' => 'pair1' } @pair2 = { 'name' => 'pair2' } - @params = { 'field' => @field, 'pair' => { '0' => @pair1, '1' => @pair2 } } + @params = { 'field' => @field, 'pair' => { '0' => @pair1, '1' => @pair2 } } end it "should create the pair" do @@ -38,7 +38,7 @@ class CustomFieldFooPair @field = { 'as' => 'foopair', 'field_group_id' => 1, 'label' => 'Event' } @pair1 = { 'name' => 'pair1' } @pair2 = { 'name' => 'pair2' } - @params = { 'id' => '3', 'field' => @field, 'pair' => { '0' => @pair1, '1' => @pair2 } } + @params = { 'id' => '3', 'field' => @field, 'pair' => { '0' => @pair1, '1' => @pair2 } } end it "should update the pair" do diff --git a/spec/support/auth_macros.rb b/spec/support/auth_macros.rb index b7c0b192f4..584b82efcf 100755 --- a/spec/support/auth_macros.rb +++ b/spec/support/auth_macros.rb @@ -17,7 +17,7 @@ def activate_authlogic #---------------------------------------------------------------------------- def login(user_stubs = {}, session_stubs = {}) User.current_user = @current_user = FactoryGirl.create(:user, user_stubs) - @current_user_session = double(Authentication, {record: current_user}.merge(session_stubs)) + @current_user_session = double(Authentication, { record: current_user }.merge(session_stubs)) allow(Authentication).to receive(:find).and_return(@current_user_session) #set_timezone end @@ -26,7 +26,7 @@ def login(user_stubs = {}, session_stubs = {}) #---------------------------------------------------------------------------- def login_and_assign(user_stubs = {}, session_stubs = {}) User.current_user = @current_user = FactoryGirl.build_stubbed(:user, user_stubs) - @current_user_session = double(Authentication, {record: current_user}.merge(session_stubs)) + @current_user_session = double(Authentication, { record: current_user }.merge(session_stubs)) allow(Authentication).to receive(:find).and_return(@current_user_session) #set_timezone assigns[:current_user] = current_user diff --git a/spec/views/tasks/index.haml_spec.rb b/spec/views/tasks/index.haml_spec.rb index c3c93ebc5b..bb16ded194 100644 --- a/spec/views/tasks/index.haml_spec.rb +++ b/spec/views/tasks/index.haml_spec.rb @@ -16,7 +16,7 @@ before do user = FactoryGirl.build_stubbed(:user) account = FactoryGirl.build_stubbed(:account) - @due = FactoryGirl.build_stubbed(:task, asset: account, bucket: "due_asap", assignee: user) + @due = FactoryGirl.build_stubbed(:task, asset: account, bucket: "due_asap", assignee: user) @completed = FactoryGirl.build_stubbed(:task, asset: account, bucket: "completed_today", assignee: user, completed_at: 1.hour.ago, completor: user) end diff --git a/spec/views/tasks/update.js.haml_spec.rb b/spec/views/tasks/update.js.haml_spec.rb index 2f84dc936f..5980ed3a0f 100644 --- a/spec/views/tasks/update.js.haml_spec.rb +++ b/spec/views/tasks/update.js.haml_spec.rb @@ -15,7 +15,7 @@ describe "Changing due date" do before do assign(:task_before_update, FactoryGirl.build_stubbed(:task, bucket: "due_asap")) - assign(:task, @task = FactoryGirl.build_stubbed(:task, bucket: "due_tomorrow")) + assign(:task, @task = FactoryGirl.build_stubbed(:task, bucket: "due_tomorrow")) assign(:view, "pending") assign(:task_total, stub_task_total("pending")) end @@ -64,7 +64,7 @@ it "pending task to somebody from Tasks tab: should remove the task and show flash message (assigned)" do assignee = FactoryGirl.build_stubbed(:user) assign(:task_before_update, FactoryGirl.build_stubbed(:task, assignee: nil)) - assign(:task, @task = FactoryGirl.build_stubbed(:task, assignee: assignee)) + assign(:task, @task = FactoryGirl.build_stubbed(:task, assignee: assignee)) assign(:view, "pending") controller.request.env["HTTP_REFERER"] = "http://localhost/tasks" @@ -78,7 +78,7 @@ it "assigned tasks to me from Tasks tab: should remove the task and show flash message (pending)" do assignee = FactoryGirl.build_stubbed(:user) assign(:task_before_update, FactoryGirl.build_stubbed(:task, assignee: assignee)) - assign(:task, @task = FactoryGirl.build_stubbed(:task, assignee: nil)) + assign(:task, @task = FactoryGirl.build_stubbed(:task, assignee: nil)) assign(:view, "assigned") controller.request.env["HTTP_REFERER"] = "http://localhost/tasks?view=assigned" @@ -91,7 +91,7 @@ it "assigned tasks to somebody else from Tasks tab: should re-render task partial" do assign(:task_before_update, FactoryGirl.build_stubbed(:task, assignee: FactoryGirl.build_stubbed(:user))) - assign(:task, @task = FactoryGirl.build_stubbed(:task, assignee: FactoryGirl.build_stubbed(:user))) + assign(:task, @task = FactoryGirl.build_stubbed(:task, assignee: FactoryGirl.build_stubbed(:user))) assign(:view, "assigned") controller.request.env["HTTP_REFERER"] = "http://localhost/tasks?view=assigned" @@ -101,7 +101,7 @@ it "from Tasks tab: should update tasks sidebar" do assign(:task_before_update, FactoryGirl.build_stubbed(:task, assignee: nil)) - assign(:task, @task = FactoryGirl.build_stubbed(:task, assignee: FactoryGirl.build_stubbed(:user))) + assign(:task, @task = FactoryGirl.build_stubbed(:task, assignee: FactoryGirl.build_stubbed(:user))) assign(:view, "assigned") controller.request.env["HTTP_REFERER"] = "http://localhost/tasks?view=assigned" render @@ -114,7 +114,7 @@ it "from asset page: should should re-render task partial" do assign(:task_before_update, FactoryGirl.build_stubbed(:task, assignee: nil)) - assign(:task, @task = FactoryGirl.build_stubbed(:task, assignee: FactoryGirl.build_stubbed(:user))) + assign(:task, @task = FactoryGirl.build_stubbed(:task, assignee: FactoryGirl.build_stubbed(:user))) render expect(rendered).to include("$('#task_#{@task.id}').html('