Skip to content

Commit

Permalink
rubocop updates. add Guardfile
Browse files Browse the repository at this point in the history
  • Loading branch information
invalidusrname committed Dec 5, 2024
1 parent 8e4ae8a commit 2aa71c9
Show file tree
Hide file tree
Showing 12 changed files with 311 additions and 119 deletions.
13 changes: 9 additions & 4 deletions 2024/ruby/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
require: rubocop-rspec
require:
- rubocop-rspec
- rubocop-rake

AllCops:
Exclude:
- bin/**/*
- spec/spec_helper.rb
- vendor/**/*

Style/Documentation:
Enabled: false
Style/FrozenStringLiteralComment:
Enabled: false
Style/StringLiterals:
Enabled: false
Style/TrailingCommaInHashLiteral:
Enabled: false
Style/NumericPredicate:
Expand All @@ -20,4 +19,10 @@ Metrics/BlockLength:
Exclude:
- spec/**/*


RSpec/ExampleLength:
Max: 20
RSpec/MultipleExpectations:
Enabled: false

inherit_from: .rubocop_todo.yml
45 changes: 44 additions & 1 deletion 2024/ruby/.rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,50 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-12-01 17:39:10 UTC using RuboCop version 1.69.0.
# on 2024-12-05 02:17:24 UTC using RuboCop version 1.69.0.
# 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
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 24

# Offense count: 5
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 161

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 120

# Offense count: 2
# Configuration parameters: EnforcedStyle, AllowedPatterns.
# SupportedStyles: snake_case, camelCase
Naming/MethodName:
Exclude:
- 'lib/advent_04_ceres_search.rb'
- 'test.rb'

# Offense count: 2
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
# SupportedStyles: snake_case, normalcase, non_integer
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
Naming/VariableNumber:
Exclude:
- 'lib/advent_04_ceres_search.rb'

# Offense count: 4
# Configuration parameters: AllowedConstants.
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'lib/advent_01_hystorian_hysteria.rb'
- 'lib/advent_02_red_nosed_reports.rb'
- 'lib/advent_03_mull_it_over.rb'
- 'lib/advent_04_ceres_search.rb'
7 changes: 7 additions & 0 deletions 2024/ruby/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ source 'https://rubygems.org'
ruby File.open('.ruby-version', 'rb') { |f| f.read.chomp }

gem 'awesome_print'

gem 'guard'
gem 'guard-rspec', require: false

gem 'pry', '~> 0.15.0'

gem 'rake', '~> 13.2'
gem 'rspec', '~> 3.13.0'
gem 'rubocop', '~> 1.69.0'
gem 'rubocop-rake', '0.6.0', require: false
gem 'rubocop-rspec', '3.2.0', require: false
37 changes: 37 additions & 0 deletions 2024/ruby/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,34 @@ GEM
awesome_print (1.9.2)
coderay (1.1.3)
diff-lcs (1.5.1)
ffi (1.17.0)
ffi (1.17.0-arm64-darwin)
formatador (1.1.0)
guard (2.19.0)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
lumberjack (>= 1.0.12, < 2.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.13.0)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-compat (1.2.1)
guard-rspec (4.7.3)
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
json (2.8.2)
language_server-protocol (3.17.0.3)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
lumberjack (1.2.10)
method_source (1.1.0)
nenv (0.3.0)
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
parallel (1.26.3)
parser (3.3.6.0)
ast (~> 2.4.1)
Expand All @@ -17,6 +42,10 @@ GEM
method_source (~> 1.0)
racc (1.8.1)
rainbow (3.1.1)
rake (13.2.1)
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
regexp_parser (2.9.3)
rspec (3.13.0)
rspec-core (~> 3.13.0)
Expand All @@ -43,9 +72,13 @@ GEM
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.36.2)
parser (>= 3.3.1.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (3.2.0)
rubocop (~> 1.61)
ruby-progressbar (1.13.0)
shellany (0.0.1)
thor (1.3.2)
unicode-display_width (3.1.2)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
Expand All @@ -56,9 +89,13 @@ PLATFORMS

DEPENDENCIES
awesome_print
guard
guard-rspec
pry (~> 0.15.0)
rake (~> 13.2)
rspec (~> 3.13.0)
rubocop (~> 1.69.0)
rubocop-rake (= 0.6.0)
rubocop-rspec (= 3.2.0)

RUBY VERSION
Expand Down
72 changes: 72 additions & 0 deletions 2024/ruby/Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# frozen_string_literal: true

# A sample Guardfile
# More info at https://github.com/guard/guard#readme

## Uncomment and set this to only include directories you want to watch
# directories %w(app lib config test spec features) \
# .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}

## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), then you will want to move
## the Guardfile to a watched dir and symlink it back, e.g.
#
# $ mkdir config
# $ mv Guardfile config/
# $ ln -s config/Guardfile .
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"

# NOTE: The cmd option is now required due to the increasing number of ways
# rspec may be run, below are examples of the most common uses.
# * bundler: 'bundle exec rspec'
# * bundler binstubs: 'bin/rspec'
# * spring: 'bin/rspec' (This will use spring if running and you have
# installed the spring binstubs per the docs)
# * zeus: 'zeus rspec' (requires the server to be started separately)
# * 'just' rspec: 'rspec'

guard :rspec, cmd: 'bundle exec rspec' do
require 'guard/rspec/dsl'
dsl = Guard::RSpec::Dsl.new(self)

# Feel free to open issues for suggestions and improvements

# RSpec files
rspec = dsl.rspec
watch(rspec.spec_helper) { rspec.spec_dir }
watch(rspec.spec_support) { rspec.spec_dir }
watch(rspec.spec_files)

# Ruby files
ruby = dsl.ruby
dsl.watch_spec_files_for(ruby.lib_files)

# Rails files
rails = dsl.rails(view_extensions: %w[erb haml slim])
dsl.watch_spec_files_for(rails.app_files)
dsl.watch_spec_files_for(rails.views)

watch(rails.controllers) do |m|
[
rspec.spec.call("routing/#{m[1]}_routing"),
rspec.spec.call("controllers/#{m[1]}_controller"),
rspec.spec.call("acceptance/#{m[1]}")
]
end

# Rails config changes
watch(rails.spec_helper) { rspec.spec_dir }
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }

# Capybara features specs
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }

# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance'
end
end
22 changes: 22 additions & 0 deletions 2024/ruby/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require 'fileutils'

def next_advent_number
latest = Dir['./lib/advent*.rb'].map { |p| p.match(/\d{2}/)&.[](0)&.to_i }.compact.max || 0
latest + 1
end

desc 'create class and spec file for DAY'
task :new do
day = ENV['DAY'].nil? ? next_advent_number : ENV['DAY'].to_i

raise 'invalid DAY' unless day.between?(1, 31)

formatted_day = day.to_s.rjust(2, '0')

FileUtils.touch("./lib/advent_#{formatted_day}.rb")
FileUtils.touch("./spec/advent_#{formatted_day}_spec.rb")
FileUtils.touch("./spec/fixtures/advent-#{formatted_day}.txt")
FileUtils.touch("./spec/fixtures/advent-#{formatted_day}-sample.txt")
end
2 changes: 1 addition & 1 deletion 2024/ruby/lib/advent_02_red_nosed_reports.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def safe_with_dampener?

def safe_levels(direction, levels)
levels.each_index do |i|
next if i == 0
next if i.zero?

current = levels[i]
prev = levels[i - 1]
Expand Down
2 changes: 1 addition & 1 deletion 2024/ruby/lib/advent_03_mull_it_over.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def uncorrupted_pieces
end

def process_piece(str)
splits = str.tr("^0123456789,", "").split(",")
splits = str.tr('^0123456789,', '').split(',')

splits[0].to_i * splits[1].to_i
end
Expand Down
34 changes: 20 additions & 14 deletions 2024/ruby/lib/advent_04_ceres_search.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class WordSearch
attr_reader :data, :word

def initialize(data, word = "XMAS")
def initialize(data, word = 'XMAS')
@data = data
@word = word
end
Expand All @@ -19,14 +19,14 @@ def count_at(row, col)
end

def letter_at(row, col)
in_bounds?(row, col) ? data[row][col] : ""
in_bounds?(row, col) ? data[row][col] : ''
end

def horizontal_word(row, col)
first = col
last = col + word.length - 1

return "" unless in_bounds?(first, last)
return '' unless in_bounds?(first, last)

data[row][first..last] * ''
end
Expand All @@ -36,7 +36,7 @@ def horizontal?(row, col)
end

def vertical_word(row, col)
(row..row+word.length-1).map do |pos|
(row..row + word.length - 1).map do |pos|
letter_at(pos, col)
end * ''
end
Expand All @@ -47,25 +47,25 @@ def vertical?(row, col)

def diagonal_top_left_word(row, col)
(0..word.length - 1).map do |pos|
letter_at(row-pos, col-pos)
letter_at(row - pos, col - pos)
end * ''
end

def diagonal_top_right_word(row, col)
(0..word.length - 1).map do |pos|
letter_at(row-pos, col+pos)
end * ""
letter_at(row - pos, col + pos)
end * ''
end

def diagonal_bottom_right_word(row, col)
(0..word.length - 1).map do |pos|
letter_at(row+pos, col+pos)
letter_at(row + pos, col + pos)
end * ''
end

def diagonal_bottom_left_word(row, col)
(0..word.length - 1).map do |pos|
letter_at(row+pos, col-pos)
letter_at(row + pos, col - pos)
end * ''
end

Expand All @@ -74,10 +74,10 @@ def match?(str)
end

def cross_word_at?(row, col)
cross_word = "MAS"
cross_word = 'MAS'

diag_1 = letter_at(row-1, col-1) + letter_at(row, col) + letter_at(row+1, col+1)
diag_2 = letter_at(row+1, col-1) + letter_at(row, col) + letter_at(row-1, col+1)
diag_1 = letter_at(row - 1, col - 1) + letter_at(row, col) + letter_at(row + 1, col + 1)
diag_2 = letter_at(row + 1, col - 1) + letter_at(row, col) + letter_at(row - 1, col + 1)

diag_1_match = [cross_word, cross_word.reverse].any? { |str| str == diag_1 }
diag_2_match = [cross_word, cross_word.reverse].any? { |str| str == diag_2 }
Expand Down Expand Up @@ -122,8 +122,8 @@ def diagonal_count_at(row, col)
diagonal_top_right_word(row, col),
diagonal_top_left_word(row, col),
diagonal_bottom_right_word(row, col),
diagonal_bottom_left_word(row, col),
].sum { |str| str == word ? 1 : 0}
diagonal_bottom_left_word(row, col)
].sum { |str| str == word ? 1 : 0 }
end

def diagonal_count
Expand All @@ -147,3 +147,9 @@ def render
end
end
end

def badName
return unless something

test
end
Loading

0 comments on commit 2aa71c9

Please sign in to comment.