Skip to content

Commit

Permalink
[Rubocop] Layout/LineLength (#3781)
Browse files Browse the repository at this point in the history
# What does this pull request do?

Debiggens long lines to fall under the default value for
`Layout/LineLength` of `120`
  • Loading branch information
veganstraightedge authored Feb 26, 2024
1 parent b7fe901 commit 9d87b05
Show file tree
Hide file tree
Showing 28 changed files with 302 additions and 83 deletions.
3 changes: 1 addition & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Layout/HashAlignment:
EnforcedColonStyle: table

Layout/LineLength:
Max: 186
Exclude:
- 'db/**/*'

Expand Down Expand Up @@ -67,7 +66,7 @@ RSpec/DescribeClass:
- 'spec/system/*'

RSpec/ExampleLength:
Max: 9
Max: 14
Exclude:
- 'spec/system/*'

Expand Down
4 changes: 3 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-09-10 21:58:05 UTC using RuboCop version 1.56.2.
# on 2024-02-26 03:07:03 UTC using RuboCop version 1.60.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -96,6 +96,8 @@ Rails/Present:

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowedReceivers.
# AllowedReceivers: ActionMailer::Preview, ActiveSupport::TimeZone
Rails/RedundantActiveRecordAllMethod:
Exclude:
- 'app/models/support_session.rb'
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/admin/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ def prepare_article_for_translation

def set_article
if params[:year] && params[:slug]
@article = Article.where(year: params[:year]).where(month: params[:month]).where(day: params[:day]).where(slug: params[:slug]).first
@article = Article.where(year: params[:year])
.where(month: params[:month])
.where(day: params[:day])
.where(slug: params[:slug])
.first

redirect_to([:edit, :admin, @article])
elsif params[:draft_code].present?
Expand Down
22 changes: 12 additions & 10 deletions app/controllers/admin/books_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,18 @@ def set_book
end

def book_params
params.require(:book).permit(:title, :subtitle, :content, :tweet, :summary, :publication_status, :locale,
:description, :buy_url, :buy_info, :slug, :series, :published_at, :gallery_images_count,
:price_in_cents, :height, :width, :depth, :weight, :pages, :words, :illustrations,
:photographs, :printing, :ink, :definitions, :recipes, :has_index, :cover_style,
:binding_style, :table_of_contents, :back_image_present, :gallery_images_count,
:lite_download_present, :epub_download_present, :mobi_download_present,
:print_black_and_white_a4_download_present, :print_color_a4_download_present,
:print_color_download_present, :print_black_and_white_download_present,
:screen_single_page_view_download_present, :screen_two_page_view_download_present,
:featured_status, :featured_at, :canonical_id, :position, :hide_from_index)
params.require(:book).permit(
:title, :subtitle, :content, :tweet, :summary, :publication_status, :locale,
:description, :buy_url, :buy_info, :slug, :series, :published_at, :gallery_images_count,
:price_in_cents, :height, :width, :depth, :weight, :pages, :words, :illustrations,
:photographs, :printing, :ink, :definitions, :recipes, :has_index, :cover_style,
:binding_style, :table_of_contents, :back_image_present, :gallery_images_count,
:lite_download_present, :epub_download_present, :mobi_download_present,
:print_black_and_white_a4_download_present, :print_color_a4_download_present,
:print_color_download_present, :print_black_and_white_download_present,
:screen_single_page_view_download_present, :screen_two_page_view_download_present,
:featured_status, :featured_at, :canonical_id, :position, :hide_from_index
)
end
end
end
22 changes: 12 additions & 10 deletions app/controllers/admin/zines_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,18 @@ def set_zine
end

def zine_params
params.require(:zine).permit(:title, :subtitle, :content, :tweet, :summary, :locale,
:description, :buy_url, :buy_info, :slug, :series, :published_at, :gallery_images_count,
:price_in_cents, :height, :width, :depth, :weight, :pages, :words, :illustrations,
:photographs, :printing, :ink, :definitions, :recipes, :has_index, :cover_style,
:binding_style, :table_of_contents, :back_image_present, :canonical_id,
:lite_download_present, :epub_download_present, :mobi_download_present,
:print_black_and_white_a4_download_present, :print_color_a4_download_present,
:print_color_download_present, :print_black_and_white_download_present,
:screen_single_page_view_download_present, :screen_two_page_view_download_present,
:publication_status, :featured_status, :featured_at, :position, :hide_from_index)
params.require(:zine).permit(
:title, :subtitle, :content, :tweet, :summary, :locale,
:description, :buy_url, :buy_info, :slug, :series, :published_at, :gallery_images_count,
:price_in_cents, :height, :width, :depth, :weight, :pages, :words, :illustrations,
:photographs, :printing, :ink, :definitions, :recipes, :has_index, :cover_style,
:binding_style, :table_of_contents, :back_image_present, :canonical_id,
:lite_download_present, :epub_download_present, :mobi_download_present,
:print_black_and_white_a4_download_present, :print_color_a4_download_present,
:print_color_download_present, :print_black_and_white_download_present,
:screen_single_page_view_download_present, :screen_two_page_view_download_present,
:publication_status, :featured_status, :featured_at, :position, :hide_from_index
)
end
end
end
3 changes: 2 additions & 1 deletion app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ def library

# TODO: Delete and all of its views and translation locale YAMLs
def post_order_success
@title = PageTitle.new title_for I18n.t('page_titles.about.store'), I18n.t('page_titles.about.post_order_success')
@order_id = params[:ordernum]
@title = PageTitle.new title_for(I18n.t('page_titles.about.store')),
I18n.t('page_titles.about.post_order_success')

render "#{Current.theme}/pages/post_order_success"
end
Expand Down
44 changes: 39 additions & 5 deletions app/helpers/articles_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,22 @@ def social_link_for article, site
when :facebook
"https://www.facebook.com/sharer?u=#{url_encode article_url}"
when :tumblr
"http://tumblr.com/widgets/share/tool?canonicalUrl=#{article_url}&caption=#{url_encode article.title}&content=#{article.image}"
[
'http://tumblr.com/widgets/share/tool?canonicalUrl=',
article_url,
'&caption=',
url_encode(article.title),
'&content=',
article.image
]
end

tag.li class: 'social-link' do
link_to "Share on #{site.capitalize}", url, class: "link-domain-#{site}", target: '_blank', rel: 'noopener'
link_to "Share on #{site.capitalize}",
url,
class: "link-domain-#{site}",
target: '_blank',
rel: 'noopener'
end
end

Expand Down Expand Up @@ -79,9 +90,32 @@ def link_to_dates year: nil, month: nil, day: nil, show_year: true, show_month:
month = month.to_s.rjust(2, '0') unless month.nil?
day = day.to_s.rjust(2, '0') unless day.nil?

links << link_to_unless_current(year, article_archives_path(year), rel: 'archives', class: 'year') if year && show_year
links << link_to_unless_current(month, article_archives_path(year, month), rel: 'archives', class: 'month') if month && show_month
links << link_to_unless_current(day, article_archives_path(year, month, day), rel: 'archives', class: 'day') if day && show_day
if year && show_year
links << link_to_unless_current(
year,
article_archives_path(year),
rel: 'archives',
class: 'year'
)
end

if month && show_month
links << link_to_unless_current(
month,
article_archives_path(year, month),
rel: 'archives',
class: 'month'
)
end

if day && show_day
links << link_to_unless_current(
day,
article_archives_path(year, month, day),
rel: 'archives',
class: 'day'
)
end

links.join('-').html_safe
end
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/to_change_everything_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module ToChangeEverythingHelper
outro: %w[anarchy outro takeflight next].freeze
}.freeze

# rubocop:disable Layout/LineLength
LANGUAGE_LINKS = {
first: {
'العربية' => '/2016/09/21/to-change-everything-in-11-more-languages#arabic',
Expand All @@ -26,6 +27,7 @@ module ToChangeEverythingHelper
'Français' => '/2016/01/25/to-change-everything-in-ten-more-languages#french',
'Français (Québec)' => '/tce/quebecois'
}.freeze,
# rubocop:enable Layout/LineLength

last: {
'ελληνικά' => '/2016/01/25/to-change-everything-in-ten-more-languages#greek',
Expand Down
3 changes: 2 additions & 1 deletion app/lib/code_archiver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ def pages_prefix

def download_article_images
files = `grep -hrioE '"http[s]?:\/\/cloudfront\.crimethinc\.com.*"' website-content/articles/ | sort | uniq`
count = `grep -hrioE '"http[s]?:\/\/cloudfront\.crimethinc\.com.*"' website-content/articles/ | sort | uniq| wc -l`.to_i
count = `grep -hrioE '"http[s]?:\/\/cloudfront\.crimethinc\.com.*"' website-content/articles/ | sort | uniq| wc -l`
.to_i

files = files.tr('\"', '').split("\n")

Expand Down
9 changes: 7 additions & 2 deletions app/middlewares/rack/domain_redirect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ module Rack
class DomainRedirect
# subdomain (optional), path prefix (optional), URL regex to match (required)
REDIRECT_CONFIGS = [
['', '/steal-something-from-work-day', /stealfromwork.crimethinc.com|stealfromworkday.com|stealsomethingfromworkday.com$/],
['', '/tce', /tochangeeverything.com/],
[
'',
'/steal-something-from-work-day',
/stealfromwork.crimethinc.com|stealfromworkday.com|stealsomethingfromworkday.com$/
],

['', '/tce', /tochangeeverything.com/],

['', '', /crimethinc.herokuapp.com$/],
['es.', '', /crimethinc.es/],
Expand Down
5 changes: 4 additions & 1 deletion app/models/active_storage_mirror_syncer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ def run

# Open the local file (if one exists)
if services.any?(ActiveStorage::Service::DiskService)
local_file_path = services.find { |service| service.is_a? ActiveStorage::Service::DiskService }.path_for blob.key
local_file_path = services.find do |service|
service.is_a? ActiveStorage::Service::DiskService
end.path_for blob.key

local_file = File.open(local_file_path)
end

Expand Down
18 changes: 15 additions & 3 deletions app/models/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@ class Article < ApplicationRecord
has_many :categories, through: :categorizations

# Collections / Nested Articles, used for live blogs
has_many :collection_posts, foreign_key: :collection_id, class_name: 'Article', inverse_of: :collection, dependent: :destroy
belongs_to :collection, foreign_key: :collection_id, class_name: 'Article', inverse_of: :collection_posts, touch: true, optional: true
has_many :collection_posts,
foreign_key: :collection_id,
class_name: 'Article',
inverse_of: :collection,
dependent: :destroy

belongs_to :collection,
foreign_key: :collection_id,
class_name: 'Article',
inverse_of: :collection_posts,
touch: true,
optional: true

before_validation :generate_published_dates, on: %i[create update]
before_validation :normalize_newlines, on: %i[create update]
Expand Down Expand Up @@ -117,7 +127,9 @@ def normalize_newlines
def update_or_create_redirect
return if short_path.blank?

if redirect.present? && (short_path_changed? || slug_changed? || published_at_changed? || publication_status_changed?)
# TODO: name this conditional's concept, extract to a private method
if redirect.present? &&
(short_path_changed? || slug_changed? || published_at_changed? || publication_status_changed?)
redirect.update(source_path: absolute_short_path, target_path: path)
elsif Redirect.where(source_path: absolute_short_path).exists?
errors.add(:short_path, ' is a path that already points to a redirect')
Expand Down
27 changes: 24 additions & 3 deletions app/models/concerns/publishable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,30 @@ module Publishable
scope :root, -> { where(collection_id: nil) }
scope :live, -> { where('published_at < ?', Time.now.utc) }
scope :recent, -> { where('published_at BETWEEN ? AND ?', Time.now.utc - 2.days, Time.now.utc) }
scope :on, ->(date) { where('published_at BETWEEN ? AND ?', date.try(:beginning_of_day), date.try(:end_of_day)) }
scope :next, ->(article) { unscoped.root.where('published_at > ?', article.published_at).live.published.order(published_at: :asc).limit(1) }
scope :previous, ->(article) { root.where('published_at < ?', article.published_at).live.published.chronological.limit(1) }

scope :on,
lambda { |date|
where('published_at BETWEEN ? AND ?', date.try(:beginning_of_day), date.try(:end_of_day))
}

scope :next,
lambda { |article|
unscoped.root
.where('published_at > ?', article.published_at)
.live
.published
.order(published_at: :asc)
.limit(1)
}

scope :previous,
lambda { |article|
root.where('published_at < ?', article.published_at)
.live
.published
.chronological
.limit(1)
}
end

def dated?
Expand Down
7 changes: 5 additions & 2 deletions app/models/concerns/single_page_tool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ def url_of side:, color:, kind:
end

def preferred_front_image_color
return :color if image_front_color_image.attached? || image_front_color_download.attached?
return :black_and_white if image_front_black_and_white_image.attached? || image_front_black_and_white_download.attached?
return :color if image_front_color_image.attached? || image_front_color_download.attached?

if image_front_black_and_white_image.attached? || image_front_black_and_white_download.attached?
return :black_and_white
end

:color
end
Expand Down
7 changes: 5 additions & 2 deletions app/models/redirect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,17 @@ def crimethinc_apex_domain_url? url
end

def noncircular_redirect
errors.add(:target_path, I18n.t('activerecord.errors.models.article.target_path.uniqueness')) if source_path == target_path
return unless source_path == target_path

errors.add(:target_path, I18n.t('activerecord.errors.models.article.target_path.uniqueness'))
end

def article_short_path_unique
aa = Article.where(short_path: source_path[/\w+/])

return if aa.blank?
return if aa.first.id == article_id

errors.add(:source_path, I18n.t('activerecord.errors.models.article.source_path.uniqueness')) unless aa.first.id == article_id
errors.add(:source_path, I18n.t('activerecord.errors.models.article.source_path.uniqueness'))
end
end
2 changes: 2 additions & 0 deletions app/views/2017/tools/show.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ json.locale @tool.locale
json.description @tool.description
json.summary @tool.summary

# rubocop:disable Layout/LineLength
json.attachments do
json.front_color_image @tool.image_front_color_image.attached? ? root_url + url_for(@tool.image_front_color_image) : nil
json.front_black_and_white_image @tool.image_front_black_and_white_image.attached? ? root_url + url_for(@tool.image_front_black_and_white_image) : nil
Expand All @@ -26,3 +27,4 @@ json.attachments do
json.back_color_download @tool.image_back_color_download.attached? ? root_url + url_for(@tool.image_back_color_download) : nil
json.back_black_and_white_download @tool.image_back_black_and_white_download.attached? ? root_url + url_for(@tool.image_back_black_and_white_download) : nil
end
# rubocop:enable Layout/LineLength
2 changes: 1 addition & 1 deletion config/initializers/new_framework_defaults_7_1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
# and you have no plans to rollback.
# When you're ready to change format, add this to `config/application.rb` (NOT
# this file):
# config.active_support.cache_format_version = 7.1
# config.active_support.cache_format_version = 7.1

###
# Configure Action View to use HTML5 standards-compliant sanitizers when they are supported on your
Expand Down
14 changes: 11 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,17 @@
get 'tags/:slug/feed(/:lang)', to: 'tags#feed', defaults: { format: 'atom' }, as: :tag_feed

# Podcast
get 'podcast/feed(/:lang)', to: 'podcasts#feed', as: :podcast_feed, defaults: { format: 'rss' }
get 'podcast/feed(/:lang)',
to: 'podcasts#feed',
as: :podcast_feed,
defaults: { format: 'rss' }

get 'podcasts', to: 'podcasts#index', as: :podcasts
get 'podcasts/:slug', to: 'podcasts#show', as: :podcast
get 'podcasts/:slug/episodes', to: redirect { |path_params, _| "/podcasts/#{path_params[:slug]}" }

get 'podcasts/:slug/episodes',
to: redirect { |path_params, _| "/podcasts/#{path_params[:slug]}" }

get 'podcasts/:slug/episodes/:episode_number', to: 'episodes#show', as: :episode
get 'podcasts/:slug/episodes/:episode_number/transcript', to: 'episodes#transcript', as: :episode_transcript

Expand Down Expand Up @@ -152,7 +159,8 @@
post 'support/cancel/:token/:subscription_id', to: 'support#cancel_subscription', as: :support_cancel_subscription
post 'support/update/:token/:subscription_id', to: 'support#update_subscription', as: :support_update_subscription

post 'support/stripe_subscription_payment_succeeded_webhook', to: 'support#stripe_subscription_payment_succeeded_webhook'
post 'support/stripe_subscription_payment_succeeded_webhook',
to: 'support#stripe_subscription_payment_succeeded_webhook'

# Admin Dashboard
get :admin, to: redirect('/admin/dashboard'), as: 'admin'
Expand Down
Loading

0 comments on commit 9d87b05

Please sign in to comment.