Skip to content

Commit 2aa71c9

Browse files
rubocop updates. add Guardfile
1 parent 8e4ae8a commit 2aa71c9

File tree

12 files changed

+311
-119
lines changed

12 files changed

+311
-119
lines changed

2024/ruby/.rubocop.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
require: rubocop-rspec
1+
require:
2+
- rubocop-rspec
3+
- rubocop-rake
24

35
AllCops:
46
Exclude:
57
- bin/**/*
68
- spec/spec_helper.rb
79
- vendor/**/*
8-
910
Style/Documentation:
1011
Enabled: false
1112
Style/FrozenStringLiteralComment:
1213
Enabled: false
13-
Style/StringLiterals:
14-
Enabled: false
1514
Style/TrailingCommaInHashLiteral:
1615
Enabled: false
1716
Style/NumericPredicate:
@@ -20,4 +19,10 @@ Metrics/BlockLength:
2019
Exclude:
2120
- spec/**/*
2221

22+
23+
RSpec/ExampleLength:
24+
Max: 20
25+
RSpec/MultipleExpectations:
26+
Enabled: false
27+
2328
inherit_from: .rubocop_todo.yml

2024/ruby/.rubocop_todo.yml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,50 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2024-12-01 17:39:10 UTC using RuboCop version 1.69.0.
3+
# on 2024-12-05 02:17:24 UTC using RuboCop version 1.69.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
8+
9+
# Offense count: 1
10+
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
11+
Metrics/AbcSize:
12+
Max: 24
13+
14+
# Offense count: 5
15+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
16+
# AllowedMethods: refine
17+
Metrics/BlockLength:
18+
Max: 161
19+
20+
# Offense count: 1
21+
# Configuration parameters: CountComments, CountAsOne.
22+
Metrics/ClassLength:
23+
Max: 120
24+
25+
# Offense count: 2
26+
# Configuration parameters: EnforcedStyle, AllowedPatterns.
27+
# SupportedStyles: snake_case, camelCase
28+
Naming/MethodName:
29+
Exclude:
30+
- 'lib/advent_04_ceres_search.rb'
31+
- 'test.rb'
32+
33+
# Offense count: 2
34+
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
35+
# SupportedStyles: snake_case, normalcase, non_integer
36+
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
37+
Naming/VariableNumber:
38+
Exclude:
39+
- 'lib/advent_04_ceres_search.rb'
40+
41+
# Offense count: 4
42+
# Configuration parameters: AllowedConstants.
43+
Style/Documentation:
44+
Exclude:
45+
- 'spec/**/*'
46+
- 'test/**/*'
47+
- 'lib/advent_01_hystorian_hysteria.rb'
48+
- 'lib/advent_02_red_nosed_reports.rb'
49+
- 'lib/advent_03_mull_it_over.rb'
50+
- 'lib/advent_04_ceres_search.rb'

2024/ruby/Gemfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ source 'https://rubygems.org'
55
ruby File.open('.ruby-version', 'rb') { |f| f.read.chomp }
66

77
gem 'awesome_print'
8+
9+
gem 'guard'
10+
gem 'guard-rspec', require: false
11+
812
gem 'pry', '~> 0.15.0'
13+
14+
gem 'rake', '~> 13.2'
915
gem 'rspec', '~> 3.13.0'
1016
gem 'rubocop', '~> 1.69.0'
17+
gem 'rubocop-rake', '0.6.0', require: false
1118
gem 'rubocop-rspec', '3.2.0', require: false

2024/ruby/Gemfile.lock

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,34 @@ GEM
55
awesome_print (1.9.2)
66
coderay (1.1.3)
77
diff-lcs (1.5.1)
8+
ffi (1.17.0)
9+
ffi (1.17.0-arm64-darwin)
10+
formatador (1.1.0)
11+
guard (2.19.0)
12+
formatador (>= 0.2.4)
13+
listen (>= 2.7, < 4.0)
14+
lumberjack (>= 1.0.12, < 2.0)
15+
nenv (~> 0.1)
16+
notiffany (~> 0.0)
17+
pry (>= 0.13.0)
18+
shellany (~> 0.0)
19+
thor (>= 0.18.1)
20+
guard-compat (1.2.1)
21+
guard-rspec (4.7.3)
22+
guard (~> 2.1)
23+
guard-compat (~> 1.1)
24+
rspec (>= 2.99.0, < 4.0)
825
json (2.8.2)
926
language_server-protocol (3.17.0.3)
27+
listen (3.9.0)
28+
rb-fsevent (~> 0.10, >= 0.10.3)
29+
rb-inotify (~> 0.9, >= 0.9.10)
30+
lumberjack (1.2.10)
1031
method_source (1.1.0)
32+
nenv (0.3.0)
33+
notiffany (0.1.3)
34+
nenv (~> 0.1)
35+
shellany (~> 0.0)
1136
parallel (1.26.3)
1237
parser (3.3.6.0)
1338
ast (~> 2.4.1)
@@ -17,6 +42,10 @@ GEM
1742
method_source (~> 1.0)
1843
racc (1.8.1)
1944
rainbow (3.1.1)
45+
rake (13.2.1)
46+
rb-fsevent (0.11.2)
47+
rb-inotify (0.11.1)
48+
ffi (~> 1.0)
2049
regexp_parser (2.9.3)
2150
rspec (3.13.0)
2251
rspec-core (~> 3.13.0)
@@ -43,9 +72,13 @@ GEM
4372
unicode-display_width (>= 2.4.0, < 4.0)
4473
rubocop-ast (1.36.2)
4574
parser (>= 3.3.1.0)
75+
rubocop-rake (0.6.0)
76+
rubocop (~> 1.0)
4677
rubocop-rspec (3.2.0)
4778
rubocop (~> 1.61)
4879
ruby-progressbar (1.13.0)
80+
shellany (0.0.1)
81+
thor (1.3.2)
4982
unicode-display_width (3.1.2)
5083
unicode-emoji (~> 4.0, >= 4.0.4)
5184
unicode-emoji (4.0.4)
@@ -56,9 +89,13 @@ PLATFORMS
5689

5790
DEPENDENCIES
5891
awesome_print
92+
guard
93+
guard-rspec
5994
pry (~> 0.15.0)
95+
rake (~> 13.2)
6096
rspec (~> 3.13.0)
6197
rubocop (~> 1.69.0)
98+
rubocop-rake (= 0.6.0)
6299
rubocop-rspec (= 3.2.0)
63100

64101
RUBY VERSION

2024/ruby/Guardfile

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# frozen_string_literal: true
2+
3+
# A sample Guardfile
4+
# More info at https://github.com/guard/guard#readme
5+
6+
## Uncomment and set this to only include directories you want to watch
7+
# directories %w(app lib config test spec features) \
8+
# .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
9+
10+
## Note: if you are using the `directories` clause above and you are not
11+
## watching the project directory ('.'), then you will want to move
12+
## the Guardfile to a watched dir and symlink it back, e.g.
13+
#
14+
# $ mkdir config
15+
# $ mv Guardfile config/
16+
# $ ln -s config/Guardfile .
17+
#
18+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
19+
20+
# NOTE: The cmd option is now required due to the increasing number of ways
21+
# rspec may be run, below are examples of the most common uses.
22+
# * bundler: 'bundle exec rspec'
23+
# * bundler binstubs: 'bin/rspec'
24+
# * spring: 'bin/rspec' (This will use spring if running and you have
25+
# installed the spring binstubs per the docs)
26+
# * zeus: 'zeus rspec' (requires the server to be started separately)
27+
# * 'just' rspec: 'rspec'
28+
29+
guard :rspec, cmd: 'bundle exec rspec' do
30+
require 'guard/rspec/dsl'
31+
dsl = Guard::RSpec::Dsl.new(self)
32+
33+
# Feel free to open issues for suggestions and improvements
34+
35+
# RSpec files
36+
rspec = dsl.rspec
37+
watch(rspec.spec_helper) { rspec.spec_dir }
38+
watch(rspec.spec_support) { rspec.spec_dir }
39+
watch(rspec.spec_files)
40+
41+
# Ruby files
42+
ruby = dsl.ruby
43+
dsl.watch_spec_files_for(ruby.lib_files)
44+
45+
# Rails files
46+
rails = dsl.rails(view_extensions: %w[erb haml slim])
47+
dsl.watch_spec_files_for(rails.app_files)
48+
dsl.watch_spec_files_for(rails.views)
49+
50+
watch(rails.controllers) do |m|
51+
[
52+
rspec.spec.call("routing/#{m[1]}_routing"),
53+
rspec.spec.call("controllers/#{m[1]}_controller"),
54+
rspec.spec.call("acceptance/#{m[1]}")
55+
]
56+
end
57+
58+
# Rails config changes
59+
watch(rails.spec_helper) { rspec.spec_dir }
60+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
61+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
62+
63+
# Capybara features specs
64+
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
65+
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
66+
67+
# Turnip features and steps
68+
watch(%r{^spec/acceptance/(.+)\.feature$})
69+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
70+
Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance'
71+
end
72+
end

2024/ruby/Rakefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
require 'fileutils'
4+
5+
def next_advent_number
6+
latest = Dir['./lib/advent*.rb'].map { |p| p.match(/\d{2}/)&.[](0)&.to_i }.compact.max || 0
7+
latest + 1
8+
end
9+
10+
desc 'create class and spec file for DAY'
11+
task :new do
12+
day = ENV['DAY'].nil? ? next_advent_number : ENV['DAY'].to_i
13+
14+
raise 'invalid DAY' unless day.between?(1, 31)
15+
16+
formatted_day = day.to_s.rjust(2, '0')
17+
18+
FileUtils.touch("./lib/advent_#{formatted_day}.rb")
19+
FileUtils.touch("./spec/advent_#{formatted_day}_spec.rb")
20+
FileUtils.touch("./spec/fixtures/advent-#{formatted_day}.txt")
21+
FileUtils.touch("./spec/fixtures/advent-#{formatted_day}-sample.txt")
22+
end

2024/ruby/lib/advent_02_red_nosed_reports.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def safe_with_dampener?
2626

2727
def safe_levels(direction, levels)
2828
levels.each_index do |i|
29-
next if i == 0
29+
next if i.zero?
3030

3131
current = levels[i]
3232
prev = levels[i - 1]

2024/ruby/lib/advent_03_mull_it_over.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def uncorrupted_pieces
2525
end
2626

2727
def process_piece(str)
28-
splits = str.tr("^0123456789,", "").split(",")
28+
splits = str.tr('^0123456789,', '').split(',')
2929

3030
splits[0].to_i * splits[1].to_i
3131
end

2024/ruby/lib/advent_04_ceres_search.rb

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class WordSearch
22
attr_reader :data, :word
33

4-
def initialize(data, word = "XMAS")
4+
def initialize(data, word = 'XMAS')
55
@data = data
66
@word = word
77
end
@@ -19,14 +19,14 @@ def count_at(row, col)
1919
end
2020

2121
def letter_at(row, col)
22-
in_bounds?(row, col) ? data[row][col] : ""
22+
in_bounds?(row, col) ? data[row][col] : ''
2323
end
2424

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

29-
return "" unless in_bounds?(first, last)
29+
return '' unless in_bounds?(first, last)
3030

3131
data[row][first..last] * ''
3232
end
@@ -36,7 +36,7 @@ def horizontal?(row, col)
3636
end
3737

3838
def vertical_word(row, col)
39-
(row..row+word.length-1).map do |pos|
39+
(row..row + word.length - 1).map do |pos|
4040
letter_at(pos, col)
4141
end * ''
4242
end
@@ -47,25 +47,25 @@ def vertical?(row, col)
4747

4848
def diagonal_top_left_word(row, col)
4949
(0..word.length - 1).map do |pos|
50-
letter_at(row-pos, col-pos)
50+
letter_at(row - pos, col - pos)
5151
end * ''
5252
end
5353

5454
def diagonal_top_right_word(row, col)
5555
(0..word.length - 1).map do |pos|
56-
letter_at(row-pos, col+pos)
57-
end * ""
56+
letter_at(row - pos, col + pos)
57+
end * ''
5858
end
5959

6060
def diagonal_bottom_right_word(row, col)
6161
(0..word.length - 1).map do |pos|
62-
letter_at(row+pos, col+pos)
62+
letter_at(row + pos, col + pos)
6363
end * ''
6464
end
6565

6666
def diagonal_bottom_left_word(row, col)
6767
(0..word.length - 1).map do |pos|
68-
letter_at(row+pos, col-pos)
68+
letter_at(row + pos, col - pos)
6969
end * ''
7070
end
7171

@@ -74,10 +74,10 @@ def match?(str)
7474
end
7575

7676
def cross_word_at?(row, col)
77-
cross_word = "MAS"
77+
cross_word = 'MAS'
7878

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

8282
diag_1_match = [cross_word, cross_word.reverse].any? { |str| str == diag_1 }
8383
diag_2_match = [cross_word, cross_word.reverse].any? { |str| str == diag_2 }
@@ -122,8 +122,8 @@ def diagonal_count_at(row, col)
122122
diagonal_top_right_word(row, col),
123123
diagonal_top_left_word(row, col),
124124
diagonal_bottom_right_word(row, col),
125-
diagonal_bottom_left_word(row, col),
126-
].sum { |str| str == word ? 1 : 0}
125+
diagonal_bottom_left_word(row, col)
126+
].sum { |str| str == word ? 1 : 0 }
127127
end
128128

129129
def diagonal_count
@@ -147,3 +147,9 @@ def render
147147
end
148148
end
149149
end
150+
151+
def badName
152+
return unless something
153+
154+
test
155+
end

0 commit comments

Comments
 (0)