Skip to content

Commit f6bd596

Browse files
Bump Ruby, update Rubocop and Fix few offenses (#29)
* Bump minimum ruby version to 3.2 * Bump rubocop & rubocop-rspec * Fix: change require_relative path * Update Rubocop versions * Fix rubocop offenses on lib/slither.rb
1 parent c6ccc38 commit f6bd596

File tree

6 files changed

+52
-51
lines changed

6 files changed

+52
-51
lines changed

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ gem "bundler"
99
gem "pry"
1010
gem "rake", "~> 13.0"
1111
gem "rspec", "~> 3.0"
12-
gem "rubocop", "~> 1.21"
13-
gem "rubocop-rspec", "~> 2.22.0", require: false
12+
gem "rubocop", "~> 1.76.1"
13+
gem "rubocop-rspec", "~> 3.6.0", require: false
1414
# Documentation tool
1515
gem "yard"

Gemfile.lock

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
PATH
22
remote: .
33
specs:
4-
slither (0.99.5)
4+
slither (0.99.6)
55

66
GEM
77
remote: https://rubygems.org/
88
specs:
9-
ast (2.4.2)
9+
ast (2.4.3)
1010
coderay (1.1.3)
1111
diff-lcs (1.5.0)
12-
json (2.6.3)
12+
json (2.12.2)
13+
language_server-protocol (3.17.0.5)
14+
lint_roller (1.1.0)
1315
method_source (1.0.0)
14-
parallel (1.22.1)
15-
parser (3.2.0.0)
16+
parallel (1.27.0)
17+
parser (3.3.8.0)
1618
ast (~> 2.4.1)
19+
racc
20+
prism (1.4.0)
1721
pry (0.14.2)
1822
coderay (~> 1.1)
1923
method_source (~> 1.0)
24+
racc (1.8.1)
2025
rainbow (3.1.1)
2126
rake (13.0.6)
22-
regexp_parser (2.7.0)
23-
rexml (3.2.5)
27+
regexp_parser (2.10.0)
2428
rspec (3.12.0)
2529
rspec-core (~> 3.12.0)
2630
rspec-expectations (~> 3.12.0)
@@ -34,28 +38,27 @@ GEM
3438
diff-lcs (>= 1.2.0, < 2.0)
3539
rspec-support (~> 3.12.0)
3640
rspec-support (3.12.0)
37-
rubocop (1.45.1)
41+
rubocop (1.76.1)
3842
json (~> 2.3)
43+
language_server-protocol (~> 3.17.0.2)
44+
lint_roller (~> 1.1.0)
3945
parallel (~> 1.10)
40-
parser (>= 3.2.0.0)
46+
parser (>= 3.3.0.2)
4147
rainbow (>= 2.2.2, < 4.0)
42-
regexp_parser (>= 1.8, < 3.0)
43-
rexml (>= 3.2.5, < 4.0)
44-
rubocop-ast (>= 1.24.1, < 2.0)
48+
regexp_parser (>= 2.9.3, < 3.0)
49+
rubocop-ast (>= 1.45.0, < 2.0)
4550
ruby-progressbar (~> 1.7)
46-
unicode-display_width (>= 2.4.0, < 3.0)
47-
rubocop-ast (1.24.1)
48-
parser (>= 3.1.1.0)
49-
rubocop-capybara (2.18.0)
50-
rubocop (~> 1.41)
51-
rubocop-factory_bot (2.23.1)
52-
rubocop (~> 1.33)
53-
rubocop-rspec (2.22.0)
54-
rubocop (~> 1.33)
55-
rubocop-capybara (~> 2.17)
56-
rubocop-factory_bot (~> 2.22)
57-
ruby-progressbar (1.11.0)
58-
unicode-display_width (2.4.2)
51+
unicode-display_width (>= 2.4.0, < 4.0)
52+
rubocop-ast (1.45.1)
53+
parser (>= 3.3.7.2)
54+
prism (~> 1.4)
55+
rubocop-rspec (3.6.0)
56+
lint_roller (~> 1.1)
57+
rubocop (~> 1.72, >= 1.72.1)
58+
ruby-progressbar (1.13.0)
59+
unicode-display_width (3.1.4)
60+
unicode-emoji (~> 4.0, >= 4.0.4)
61+
unicode-emoji (4.0.4)
5962
yard (0.9.34)
6063

6164
PLATFORMS
@@ -66,8 +69,8 @@ DEPENDENCIES
6669
pry
6770
rake (~> 13.0)
6871
rspec (~> 3.0)
69-
rubocop (~> 1.21)
70-
rubocop-rspec (~> 2.22.0)
72+
rubocop (~> 1.76.1)
73+
rubocop-rspec (~> 3.6.0)
7174
slither!
7275
yard
7376

lib/slither.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,26 @@ class ColumnMismatchError < StandardError; end
1717
class LineWrongSizeError < StandardError; end
1818
class SectionsNotSameLengthError < StandardError; end
1919

20+
class << self
21+
private
22+
23+
def definitions
24+
@@definitions ||= {} # rubocop:disable Style/ClassVars
25+
end
26+
27+
def definition(name)
28+
definitions[name]
29+
end
30+
end
31+
2032
# Define a Slither's definition to parse a file.
2133
#
2234
# name - String name of the definition, this should be unique.
2335
# options - Hash of options to pass to the definition.
2436
# Ex: by_bytes: true, to parse by bytes
2537
# Ex: align: :left, to align the columns to the left
2638
# block - Block to define the sections of the definition. See README.md for more info.
27-
def self.define(name, options = {}, &block)
39+
def self.define(name, options = {}, &block) # rubocop:disable Lint/UnusedMethodArgument
2840
definition = Definition.new(options)
2941
yield(definition)
3042
definitions[name] = definition
@@ -42,33 +54,21 @@ def self.generate(definition_name, data)
4254

4355
# Writes the File
4456
def self.write(filename, definition_name, data)
45-
File.open(filename, "w") do |f|
46-
f.write generate(definition_name, data)
47-
end
57+
File.write(filename, generate(definition_name, data))
4858
end
4959

5060
def self.parse(filename, definition_name)
5161
raise ArgumentError, "File #{filename} does not exist." unless File.exist?(filename)
5262

53-
file_io = File.open(filename, 'r')
63+
file_io = File.open(filename, "r")
5464
parseIo(file_io, definition_name)
5565
end
5666

57-
def self.parseIo(io, definition_name)
67+
def self.parseIo(io, definition_name) # rubocop:disable Naming/MethodName
5868
definition = definition(definition_name)
5969
raise ArgumentError, "Definition name '#{definition_name}' was not found." unless definition
6070

6171
parser = Parser.new(definition, io)
6272
definition.options[:by_bytes] ? parser.parse_by_bytes : parser.parse
6373
end
64-
65-
private
66-
67-
def self.definitions
68-
@@definitions ||= {}
69-
end
70-
71-
def self.definition(name)
72-
definitions[name]
73-
end
7474
end

slither.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
88
spec.authors = ["Ryan Wood"]
99
spec.summary = "A simple, clean DSL for describing, writing, and parsing fixed-width text files."
1010
spec.license = "MIT"
11-
spec.required_ruby_version = ">= 3.0.0"
11+
spec.required_ruby_version = ">= 3.2.0"
1212

1313
spec.homepage = "https://github.com/ryanwood/slither"
1414

spec/slither_spec.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@
5151
it "write a file" do
5252
simple_definition
5353

54-
file = instance_double(File, "file")
55-
56-
allow(File).to receive(:open).with(file_name, "w").and_yield(file)
57-
expect(file).to receive(:write)
54+
allow(File).to receive(:write).with(file_name, anything)
55+
expect(File).to receive(:write)
5856

5957
subject.write(file_name, :simple, simple_definition_test_data)
6058
end

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require "slither"
44
require "pry"
5-
require_relative "./helpers/definition_helper"
5+
require_relative "helpers/definition_helper"
66

77
RSpec.configure do |config|
88
# Enable flags like --only-failures and --next-failure

0 commit comments

Comments
 (0)