Skip to content

Commit

Permalink
Use Rufo to format all files in a consistent way (AlchemyCMS#1799)
Browse files Browse the repository at this point in the history
* Rubocop -a

* Fix rubocop config

* [Rufo] Add trailing commas

* [Rufo] Use double quotes for strings

* Add Rufo as local dev dependency
  • Loading branch information
tvdeyen authored Apr 29, 2020
1 parent 7a79235 commit 1e95b31
Show file tree
Hide file tree
Showing 331 changed files with 4,816 additions and 4,796 deletions.
18 changes: 15 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Relaxed.Ruby.Style

AllCops:
TargetRubyVersion: 2.3
TargetRubyVersion: 2.4
Exclude:
- 'bin/rspec'
- 'vendor/**/*'
- 'spec/dummy/db/**/*'
- 'spec/dummy/config/**/*'
- 'alchemy_cms.gemspec'
- 'Rakefile'
- 'node_modules/**/*'

# Really, rubocop?
Bundler/OrderedGems:
Expand Down Expand Up @@ -220,8 +221,19 @@ Style/SpecialGlobalVars:
StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars

Style/StringLiterals:
Enabled: false
StyleGuide: http://relaxed.ruby.style/#stylestringliterals
EnforcedStyle: double_quotes

Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes

Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: comma

Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: comma

Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: consistent_comma

Style/WhileUntilModifier:
Enabled: false
Expand Down
45 changes: 23 additions & 22 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
# frozen_string_literal: true
source 'https://rubygems.org'
source "https://rubygems.org"

gemspec

rails_version = ENV.fetch('RAILS_VERSION', 6.0).to_f
gem 'rails', "~> #{rails_version}.0"
rails_version = ENV.fetch("RAILS_VERSION", 6.0).to_f
gem "rails", "~> #{rails_version}.0"

if ENV['DB'].nil? || ENV['DB'] == 'sqlite'
gem 'sqlite3', rails_version > 5.0 ? '~> 1.4.1' : '~> 1.3.6'
if ENV["DB"].nil? || ENV["DB"] == "sqlite"
gem "sqlite3", rails_version > 5.0 ? "~> 1.4.1" : "~> 1.3.6"
end
gem 'mysql2', '~> 0.5.1' if ENV['DB'] == 'mysql'
gem 'pg', '~> 1.0' if ENV['DB'] == 'postgresql'
gem "mysql2", "~> 0.5.1" if ENV["DB"] == "mysql"
gem "pg", "~> 1.0" if ENV["DB"] == "postgresql"

group :development, :test do
if ENV['GITHUB_ACTIONS']
gem 'sassc', '~> 2.3.0' # https://github.com/sass/sassc-ruby/issues/146
if ENV["GITHUB_ACTIONS"]
gem "sassc", "~> 2.3.0" # https://github.com/sass/sassc-ruby/issues/146
else
gem 'launchy'
gem 'annotate'
gem 'bumpy'
gem 'yard'
gem 'redcarpet'
gem 'pry-byebug'
gem 'rubocop', '~> 0.82.0', require: false
gem 'listen'
gem 'localeapp', '~> 3.0', require: false
gem 'dotenv', '~> 2.2'
gem 'github_fast_changelog', require: false
gem 'active_record_query_trace', require: false
gem 'rack-mini-profiler', require: false
gem "launchy"
gem "annotate"
gem "bumpy"
gem "yard"
gem "redcarpet"
gem "pry-byebug"
gem "rubocop", "~> 0.82.0", require: false
gem "listen"
gem "localeapp", "~> 3.0", require: false
gem "dotenv", "~> 2.2"
gem "github_fast_changelog", require: false
gem "active_record_query_trace", require: false
gem "rack-mini-profiler", require: false
gem "rufo", require: false
end
end
16 changes: 8 additions & 8 deletions app/controllers/alchemy/admin/attachments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ class AttachmentsController < ResourcesController
include UploaderResponses
include ArchiveOverlay

helper 'alchemy/admin/tags'
helper "alchemy/admin/tags"

def index
@query = Attachment.ransack(search_filter_params[:q])
@query.sorts = 'name asc' if @query.sorts.empty?
@query.sorts = "name asc" if @query.sorts.empty?
@attachments = @query.result

if search_filter_params[:tagged_with].present?
Expand Down Expand Up @@ -42,13 +42,13 @@ def create

def update
@attachment.update(attachment_attributes)
if attachment_attributes['file'].present?
if attachment_attributes["file"].present?
handle_uploader_response(status: :accepted)
else
render_errors_or_redirect(
@attachment,
admin_attachments_path(search_filter_params),
Alchemy.t("File successfully updated")
Alchemy.t("File successfully updated"),
)
end
end
Expand All @@ -57,14 +57,14 @@ def destroy
name = @attachment.name
@attachment.destroy
@url = admin_attachments_url(search_filter_params)
flash[:notice] = Alchemy.t('File deleted successfully', name: name)
flash[:notice] = Alchemy.t("File deleted successfully", name: name)
end

def download
@attachment = Attachment.find(params[:id])
send_file @attachment.file.path, {
filename: @attachment.file_name,
type: @attachment.file_mime_type
type: @attachment.file_mime_type,
}
end

Expand All @@ -74,8 +74,8 @@ def search_filter_params
@_search_filter_params ||= params.except(*COMMON_SEARCH_FILTER_EXCLUDES + [:attachment]).permit(
*common_search_filter_includes + [
:file_type,
:content_id
]
:content_id,
],
)
end

Expand Down
10 changes: 5 additions & 5 deletions app/controllers/alchemy/admin/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ class BaseController < Alchemy::BaseController

def leave
authorize! :leave, :alchemy_admin
render template: '/alchemy/admin/leave', layout: !request.xhr?
render template: "/alchemy/admin/leave", layout: !request.xhr?
end

private

# Disable layout rendering for xhr requests.
def set_layout
request.xhr? ? false : 'alchemy/admin'
request.xhr? ? false : "alchemy/admin"
end

# Handles exceptions
Expand All @@ -55,7 +55,7 @@ def show_error_notice(error)
if request.xhr?
render action: "error_notice"
else
render '500', status: 500
render "500", status: 500
end
end

Expand Down Expand Up @@ -105,7 +105,7 @@ def render_errors_or_redirect(object, redirect_url, flash_notice)
flash[:notice] = Alchemy.t(flash_notice)
do_redirect_to redirect_url
else
render action: (params[:action] == 'update' ? 'edit' : 'new')
render action: (params[:action] == "update" ? "edit" : "new")
end
end

Expand All @@ -131,7 +131,7 @@ def raise_exception?

# Are we currently in the page edit mode page preview.
def is_page_preview?
controller_path == 'alchemy/admin/pages' && action_name == 'show'
controller_path == "alchemy/admin/pages" && action_name == "show"
end

def load_locked_pages
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/alchemy/admin/clipboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def index

def insert
@item = model_class.find(remarkable_params[:remarkable_id])
unless @clipboard.detect { |item| item['id'] == remarkable_params[:remarkable_id] }
unless @clipboard.detect { |item| item["id"] == remarkable_params[:remarkable_id] }
@clipboard << {
'id' => remarkable_params[:remarkable_id],
'action' => params[:remove] ? 'cut' : 'copy'
"id" => remarkable_params[:remarkable_id],
"action" => params[:remove] ? "cut" : "copy",
}
end
respond_to do |format|
Expand All @@ -30,7 +30,7 @@ def insert

def remove
@item = model_class.find(remarkable_params[:remarkable_id])
@clipboard.delete_if { |item| item['id'] == remarkable_params[:remarkable_id] }
@clipboard.delete_if { |item| item["id"] == remarkable_params[:remarkable_id] }
respond_to do |format|
format.js
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/alchemy/admin/contents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Alchemy
module Admin
class ContentsController < Alchemy::Admin::BaseController
helper 'alchemy/admin/essences'
helper "alchemy/admin/essences"

authorize_resource class: Alchemy::Content

Expand Down
18 changes: 9 additions & 9 deletions app/controllers/alchemy/admin/dashboard_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'net/http'
require 'alchemy/version'
require "net/http"
require "alchemy/version"

module Alchemy
module Admin
Expand All @@ -28,9 +28,9 @@ def info
def update_check
@alchemy_version = Alchemy.version
if @alchemy_version < latest_alchemy_version
render plain: 'true'
render plain: "true"
else
render plain: 'false'
render plain: "false"
end
rescue UpdateServiceUnavailable => e
render plain: e, status: 503
Expand All @@ -41,7 +41,7 @@ def update_check
# Returns latest alchemy version.
def latest_alchemy_version
versions = get_alchemy_versions
return '' if versions.blank?
return "" if versions.blank?

# reject any non release version
versions.reject! { |v| v =~ /[a-z]/ }
Expand All @@ -54,14 +54,14 @@ def get_alchemy_versions
response = query_rubygems
if response.code == "200"
alchemy_versions = JSON.parse(response.body)
alchemy_versions.collect { |h| h['number'] }.sort
alchemy_versions.collect { |h| h["number"] }.sort
else
# rubygems.org not available?
# then we try github
response = query_github
if response.code == "200"
alchemy_tags = JSON.parse(response.body)
alchemy_tags.collect { |h| h['name'].tr('v', '') }.sort
alchemy_tags.collect { |h| h["name"].tr("v", "") }.sort
else
# no luck at all?
raise UpdateServiceUnavailable
Expand All @@ -71,12 +71,12 @@ def get_alchemy_versions

# Query the RubyGems API for Alchemy versions.
def query_rubygems
make_api_request('https://rubygems.org/api/v1/versions/alchemy_cms.json')
make_api_request("https://rubygems.org/api/v1/versions/alchemy_cms.json")
end

# Query the GitHub API for Alchemy tags.
def query_github
make_api_request('https://api.github.com/repos/AlchemyCMS/alchemy_cms/tags')
make_api_request("https://api.github.com/repos/AlchemyCMS/alchemy_cms/tags")
end

# Make a HTTP API request for given request url.
Expand Down
40 changes: 20 additions & 20 deletions app/controllers/alchemy/admin/elements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def new
@parent_element = Element.find_by(id: params[:parent_element_id])
@elements = @page.available_elements_within_current_scope(@parent_element)
@element = @page.elements.build
@clipboard = get_clipboard('elements')
@clipboard = get_clipboard("elements")
@clipboard_items = Element.all_from_clipboard_for_page(@clipboard, @page)
end

Expand All @@ -30,7 +30,7 @@ def create
else
@element = Element.create(create_element_params)
end
if @page.definition['insert_elements_at'] == 'top'
if @page.definition["insert_elements_at"] == "top"
@insert_at_top = true
@element.move_to_top
end
Expand All @@ -40,7 +40,7 @@ def create
else
@element.page = @page
@elements = @page.available_element_definitions
@clipboard = get_clipboard('elements')
@clipboard = get_clipboard("elements")
@clipboard_items = Element.all_from_clipboard_for_page(@clipboard, @page)
render :new
end
Expand All @@ -56,7 +56,7 @@ def update
@element_validated = @element.update(element_params)
else
@element_validated = false
@notice = Alchemy.t('Validation failed')
@notice = Alchemy.t("Validation failed")
@error_message = "<h2>#{@notice}</h2><p>#{Alchemy.t(:content_validations_headline)}</p>".html_safe
end
end
Expand All @@ -81,7 +81,7 @@ def order
Element.where(id: element_id).update_all(
page_id: params[:page_id],
parent_element_id: params[:parent_element_id],
position: idx + 1
position: idx + 1,
)
end
@parent_element.try!(:touch)
Expand All @@ -100,20 +100,20 @@ def element_includes
[
{
contents: {
essence: :ingredient_association
}
essence: :ingredient_association,
},
},
:tags,
{
all_nested_elements: [
{
contents: {
essence: :ingredient_association
}
essence: :ingredient_association,
},
},
:tags
]
}
:tags,
],
},
]
end

Expand All @@ -123,20 +123,20 @@ def load_element

def element_from_clipboard
@element_from_clipboard ||= begin
@clipboard = get_clipboard('elements')
@clipboard.detect { |item| item['id'].to_i == params[:paste_from_clipboard].to_i }
end
@clipboard = get_clipboard("elements")
@clipboard.detect { |item| item["id"].to_i == params[:paste_from_clipboard].to_i }
end
end

def paste_element_from_clipboard
@source_element = Element.find(element_from_clipboard['id'])
@source_element = Element.find(element_from_clipboard["id"])
element = Element.copy(@source_element, {
parent_element_id: create_element_params[:parent_element_id],
page_id: @page.id}
)
if element_from_clipboard['action'] == 'cut'
page_id: @page.id,
})
if element_from_clipboard["action"] == "cut"
@cut_element_id = @source_element.id
@clipboard.delete_if { |item| item['id'] == @source_element.id.to_s }
@clipboard.delete_if { |item| item["id"] == @source_element.id.to_s }
@source_element.destroy
end
element
Expand Down
Loading

0 comments on commit 1e95b31

Please sign in to comment.