Skip to content

Commit

Permalink
Merge pull request #848 from alexwlchan/rubocop-fixes
Browse files Browse the repository at this point in the history
Make a few more fixes to my RuboCop config
  • Loading branch information
alexwlchan authored May 30, 2024
2 parents 94fa995 + 3d0f48c commit 695134b
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 29 deletions.
6 changes: 2 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ AllCops:
# See https://stackoverflow.com/a/69421161/1558022
- 'vendor/**/*'

Layout/LineLength:
Max: 140

Metrics/AbcSize:
Enabled: false

Expand Down Expand Up @@ -51,4 +48,5 @@ Style/MutableConstant:
Enabled: false

Style/YodaCondition:
Enabled: false
Exclude:
- scripts/create_post.rb
7 changes: 6 additions & 1 deletion src/_plugins/atom_feed_filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ module AtomFeedFilters
def fix_html_for_feed_readers(html)
doc = Nokogiri::HTML.fragment(html)

# Remove all inline <style> tags
doc.xpath('style').remove

# Remove inline attributes from an HTML string that aren't allowed in
# an Atom feed, according to https://github.com/rubys/feedvalidator
doc.xpath('style|@style|.//@style|@data-lang|.//@data-lang|@controls|.//@controls|@aria-hidden|.//@aria-hidden').remove
attribute_names = %w[style data-lang controls aria-hidden]
.flat_map { |name| ["@#{name}", ".//@#{name}"] }
doc.xpath(attribute_names.join('|')).remove

HtmlModifiers.fix_tweets_for_rss(doc)

Expand Down
6 changes: 4 additions & 2 deletions src/_plugins/filter_cleanup_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ def cleanup_text(input)
# Display "LaTeX" in a nice way, if you have CSS enabled
text = text.gsub(
' LaTeX',
' <span class="visually-hidden">LaTeK</span><span class="latex" aria-hidden="true">L<sup>a</sup>T<sub>e</sub>X</span>'
' <span class="visually-hidden">LaTeK</span>' \
'<span class="latex" aria-hidden="true">L<sup>a</sup>T<sub>e</sub>X</span>'
)

text = text.gsub(
' TeX',
' <span class="visually-hidden">TeK</span><span class="latex" aria-hidden="true">T<sub>e</sub>X</span>'
' <span class="visually-hidden">TeK</span>' \
'<span class="latex" aria-hidden="true">T<sub>e</sub>X</span>'
)

# Make sure that footnote markers are rendered as a text
Expand Down
3 changes: 2 additions & 1 deletion src/_plugins/pillow/create_ico_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
require 'open3'

def create_ico_image(png16_path, png32_path, ico_path)
stdout, status = Open3.capture2('python3', 'src/_plugins/pillow/create_ico_image.py', png16_path, png32_path, ico_path)
stdout, status = Open3.capture2('python3', 'src/_plugins/pillow/create_ico_image.py', png16_path, png32_path,
ico_path)
raise "Unable to create ico at #{ico_path}" unless status.success?

stdout
Expand Down
6 changes: 4 additions & 2 deletions src/_plugins/static_file_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ def generate(site)
site.keep_files.each do |dir|
next unless File.directory? "#{src}/_#{dir}"

_, status = Open3.capture2('rsync', '--archive', "#{src}/_#{dir}/", "#{dst}/#{dir}/", '--exclude=twitter/avatars',
'--exclude=icons', '--exclude=*.svg')
_, status = Open3.capture2('rsync', '--archive', "#{src}/_#{dir}/", "#{dst}/#{dir}/",
'--exclude=twitter/avatars',
'--exclude=icons',
'--exclude=*.svg')
raise 'Unable to run static file rsync' unless status.success?
end
end
Expand Down
4 changes: 1 addition & 3 deletions src/_plugins/utils/attrs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def parse_attrs(input)
.filter { |_k, v| v.nil? }
.filter { |k| k != 'data-proofer-ignore' and k != 'link_to_original' }

unless bare_attributes.empty?
raise SyntaxError, "Unescaped attributes in #{input}"
end
raise SyntaxError, "Unescaped attributes in #{input}" unless bare_attributes.empty?

result
end
Expand Down
12 changes: 4 additions & 8 deletions src/_plugins/utils/pictures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ def get_format(image_path, image)

def create_source_elements(sources, source_im_format, options)
format_order = [ImageFormat::AVIF, ImageFormat::WEBP, source_im_format]
.reject { |im_format| sources[im_format].nil? }
.filter { |im_format| options[:desired_formats].include? im_format }

source_elements = format_order.map do |im_format|
if sources[im_format].nil?
next
end

if options[:desired_formats].include?(im_format) && options[:dark_mode]
if options[:dark_mode]
<<~HTML
<source
srcset="#{sources[im_format].join(', ')}"
Expand All @@ -35,16 +33,14 @@ def create_source_elements(sources, source_im_format, options)
media="(prefers-color-scheme: dark)"
>
HTML
elsif options[:desired_formats].include? im_format
else
<<~HTML
<source
srcset="#{sources[im_format].join(', ')}"
sizes="#{options[:sizes]}"
type="#{im_format[:mime_type]}"
>
HTML
else
''
end
end

Expand Down
4 changes: 1 addition & 3 deletions src/_plugins/utils/tint_colors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ def get_css_colors(page)
primary_color_light = colors['css_light']
primary_color_dark = colors['css_dark']

if primary_color_light.nil? && primary_color_dark.nil?
return
end
return if primary_color_light.nil? && primary_color_dark.nil?

{ 'light' => primary_color_light, 'dark' => primary_color_dark }
end
Expand Down
5 changes: 1 addition & 4 deletions src/_tests/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

# Make sure every test file is correctly sourced in this file.
Dir.glob('src/_tests/*.rb')
.reject { |f| f == 'src/_tests/tests.rb' }
.each do |f|
name = File.basename(f, '.rb')

if f == 'src/_tests/tests.rb'
next
end

next if File.open('src/_tests/tests.rb').readlines.include? "require_relative '#{name}'\n"

open('src/_tests/tests.rb', 'a') do |out_file|
Expand Down
2 changes: 1 addition & 1 deletion src/contact.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ nav_section: contact
I love it when people tell me they enjoyed something I made!
A nice message can make my day!

The best way to get in touch with me is by email: **<[email protected]>**.
The best way to get in touch with me is by email: **<{{ site.email | encode_mailto }}>**.
(I'm bad at replying to emails in a timely manner, but I'm trying to get better!)

I use the handle **alexwlchan** fairly consistently on the rest of the web.
Expand Down

2 comments on commit 695134b

@alexwlchan
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://alexwlchan.net as production
🚀 Deployed on https://66581fa4043c34afd704953c--alexwlchan.netlify.app

@alexwlchan
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://alexwlchan.net as production
🚀 Deployed on https://66582c21b69bc2bd5b967a04--alexwlchan.netlify.app

Please sign in to comment.