Skip to content

Commit 7f74ed9

Browse files
authored
Merge pull request #549 from voxpupuli/ruby322
Require Ruby 3.2 or newer
2 parents 7054527 + 1949b91 commit 7f74ed9

26 files changed

+112
-255
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ jobs:
2020
- ruby: truffleruby
2121
- ruby: truffleruby+graalvm
2222
- ruby: jruby
23-
- ruby: "2.7"
24-
rake_task: "rubocop test"
25-
- ruby: "3.0"
26-
- ruby: "3.1"
2723
- ruby: "3.2"
24+
rake_task: "rubocop test"
2825
- ruby: "3.3"
2926
- ruby: "3.3"
3027
rubyopt: "--enable-frozen-string-literal"

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ plugins:
88
- rubocop-rspec
99
- rubocop-performance
1010
- rubocop-minitest
11+
12+
AllCops:
13+
TargetRubyVersion: 3.2

.rubocop_todo.yml

Lines changed: 11 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config --no-auto-gen-timestamp`
3-
# using RuboCop version 1.75.8.
3+
# using RuboCop version 1.79.2.
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.
88

9+
# Offense count: 1
10+
# This cop supports unsafe autocorrection (--autocorrect-all).
11+
# Configuration parameters: RequireParenthesesForMethodChains.
12+
Lint/AmbiguousRange:
13+
Exclude:
14+
- 'test/common_test_suite_test.rb'
15+
916
# Offense count: 4
1017
# This cop supports unsafe autocorrection (--autocorrect-all).
1118
# Configuration parameters: AllowSafeAssignment.
@@ -21,13 +28,6 @@ Lint/MissingSuper:
2128
Exclude:
2229
- 'lib/json-schema/attributes/formats/custom.rb'
2330

24-
# Offense count: 2
25-
# This cop supports unsafe autocorrection (--autocorrect-all).
26-
Lint/NonDeterministicRequireOrder:
27-
Exclude:
28-
- 'lib/json-schema.rb'
29-
- 'test/support/test_helper.rb'
30-
3131
# Offense count: 2
3232
# Configuration parameters: AllowComments, AllowNil.
3333
Lint/SuppressedException:
@@ -146,7 +146,7 @@ Style/FormatString:
146146
Style/FormatStringToken:
147147
EnforcedStyle: unannotated
148148

149-
# Offense count: 117
149+
# Offense count: 118
150150
# This cop supports unsafe autocorrection (--autocorrect-all).
151151
# Configuration parameters: EnforcedStyle.
152152
# SupportedStyles: always, always_true, never
@@ -183,109 +183,31 @@ Style/IfUnlessModifier:
183183
- 'lib/json-schema/schema/validator.rb'
184184
- 'lib/json-schema/validator.rb'
185185

186-
# Offense count: 1
187-
# This cop supports unsafe autocorrection (--autocorrect-all).
188-
# Configuration parameters: AllowedMethods.
189-
# AllowedMethods: nonzero?
190-
Style/IfWithBooleanLiteralBranches:
191-
Exclude:
192-
- 'lib/json-schema/validator.rb'
193-
194-
# Offense count: 6
195-
# This cop supports safe autocorrection (--autocorrect).
196-
# Configuration parameters: EnforcedStyle.
197-
# SupportedStyles: line_count_dependent, lambda, literal
198-
Style/Lambda:
199-
Exclude:
200-
- 'lib/json-schema/validator.rb'
201-
- 'test/custom_format_test.rb'
202-
203186
# Offense count: 1
204187
# This cop supports unsafe autocorrection (--autocorrect-all).
205188
Style/MapToHash:
206189
Exclude:
207190
- 'lib/json-schema/schema.rb'
208191

209-
# Offense count: 12
210-
# This cop supports safe autocorrection (--autocorrect).
211-
# Configuration parameters: EnforcedStyle.
212-
# SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline
213-
Style/MethodDefParentheses:
214-
Exclude:
215-
- 'lib/json-schema/util/uuid.rb'
216-
- 'lib/json-schema/validator.rb'
217-
218192
# Offense count: 1
219193
Style/MultilineBlockChain:
220194
Exclude:
221195
- 'lib/json-schema/attribute.rb'
222196

223-
# Offense count: 2
224-
# This cop supports safe autocorrection (--autocorrect).
225-
Style/MultilineIfThen:
226-
Exclude:
227-
- 'lib/json-schema/util/uuid.rb'
228-
229-
# Offense count: 3
230-
# This cop supports safe autocorrection (--autocorrect).
231-
Style/MultilineWhenThen:
232-
Exclude:
233-
- 'lib/json-schema/schema.rb'
234-
235-
# Offense count: 11
197+
# Offense count: 8
236198
# This cop supports unsafe autocorrection (--autocorrect-all).
237199
# Configuration parameters: EnforcedStyle.
238200
# SupportedStyles: literals, strict
239201
Style/MutableConstant:
240202
Exclude:
241203
- 'lib/json-schema/attribute.rb'
242-
- 'lib/json-schema/attributes/formats/date.rb'
243-
- 'lib/json-schema/attributes/formats/date_time.rb'
244-
- 'lib/json-schema/attributes/formats/time.rb'
245204
- 'lib/json-schema/errors/validation_error.rb'
246205
- 'lib/json-schema/util/uri.rb'
247206
- 'lib/json-schema/util/uuid.rb'
248207
- 'test/extends_nested_test.rb'
249208
- 'test/schema_reader_test.rb'
250209
- 'test/support/type_validation.rb'
251210

252-
# Offense count: 10
253-
# This cop supports safe autocorrection (--autocorrect).
254-
# Configuration parameters: EnforcedStyle.
255-
# SupportedStyles: both, prefix, postfix
256-
Style/NegatedIf:
257-
Exclude:
258-
- 'lib/json-schema/attributes/anyof.rb'
259-
- 'lib/json-schema/attributes/extends.rb'
260-
- 'lib/json-schema/attributes/oneof.rb'
261-
- 'lib/json-schema/attributes/required.rb'
262-
- 'lib/json-schema/attributes/type.rb'
263-
- 'lib/json-schema/attributes/type_v4.rb'
264-
- 'lib/json-schema/errors/validation_error.rb'
265-
- 'lib/json-schema/util/array_set.rb'
266-
- 'lib/json-schema/validator.rb'
267-
268-
# Offense count: 1
269-
# This cop supports safe autocorrection (--autocorrect).
270-
Style/NegatedIfElseCondition:
271-
Exclude:
272-
- 'lib/json-schema/validator.rb'
273-
274-
# Offense count: 2
275-
# This cop supports safe autocorrection (--autocorrect).
276-
# Configuration parameters: EnforcedStyle, MinBodyLength, AllowConsecutiveConditionals.
277-
# SupportedStyles: skip_modifier_ifs, always
278-
Style/Next:
279-
Exclude:
280-
- 'lib/json-schema/attributes/ref.rb'
281-
- 'lib/json-schema/validator.rb'
282-
283-
# Offense count: 3
284-
# This cop supports safe autocorrection (--autocorrect).
285-
# Configuration parameters: Strict, AllowedNumbers, AllowedPatterns.
286-
Style/NumericLiterals:
287-
MinDigits: 23
288-
289211
# Offense count: 10
290212
# This cop supports unsafe autocorrection (--autocorrect-all).
291213
# Configuration parameters: EnforcedStyle, AllowedMethods, AllowedPatterns.
@@ -308,21 +230,6 @@ Style/OptionalBooleanParameter:
308230
Exclude:
309231
- 'lib/json-schema/validator.rb'
310232

311-
# Offense count: 3
312-
# This cop supports safe autocorrection (--autocorrect).
313-
Style/ParallelAssignment:
314-
Exclude:
315-
- 'lib/json-schema/attributes/extends.rb'
316-
- 'lib/json-schema/attributes/ref.rb'
317-
318-
# Offense count: 2
319-
# This cop supports safe autocorrection (--autocorrect).
320-
# Configuration parameters: PreferredDelimiters.
321-
Style/PercentLiteralDelimiters:
322-
Exclude:
323-
- 'Rakefile'
324-
- 'lib/json-schema/util/uri.rb'
325-
326233
# Offense count: 10
327234
# This cop supports unsafe autocorrection (--autocorrect-all).
328235
# Configuration parameters: EnforcedStyle.
@@ -335,37 +242,6 @@ Style/PreferredHashMethods:
335242
- 'lib/json-schema/attributes/required.rb'
336243
- 'lib/json-schema/schema/validator.rb'
337244

338-
# Offense count: 2
339-
# This cop supports safe autocorrection (--autocorrect).
340-
Style/RedundantBegin:
341-
Exclude:
342-
- 'lib/json-schema/attributes/formats/custom.rb'
343-
- 'lib/json-schema/validator.rb'
344-
345-
# Offense count: 1
346-
# This cop supports safe autocorrection (--autocorrect).
347-
Style/RedundantConditional:
348-
Exclude:
349-
- 'lib/json-schema/validator.rb'
350-
351-
# Offense count: 2
352-
# This cop supports safe autocorrection (--autocorrect).
353-
Style/RedundantSelfAssignmentBranch:
354-
Exclude:
355-
- 'lib/json-schema/validator.rb'
356-
357-
# Offense count: 11
358-
# This cop supports safe autocorrection (--autocorrect).
359-
Style/SelfAssignment:
360-
Exclude:
361-
- 'lib/json-schema/attributes/additionalproperties.rb'
362-
- 'lib/json-schema/attributes/allof.rb'
363-
- 'lib/json-schema/attributes/anyof.rb'
364-
- 'lib/json-schema/attributes/oneof.rb'
365-
- 'lib/json-schema/attributes/ref.rb'
366-
- 'lib/json-schema/attributes/type.rb'
367-
- 'lib/json-schema/util/uuid.rb'
368-
369245
# Offense count: 4
370246
# This cop supports unsafe autocorrection (--autocorrect-all).
371247
# Configuration parameters: Mode.
@@ -375,12 +251,6 @@ Style/StringConcatenation:
375251
- 'lib/json-schema/util/uuid.rb'
376252
- 'test/schema_reader_test.rb'
377253

378-
# Offense count: 1
379-
# This cop supports safe autocorrection (--autocorrect).
380-
Style/SuperArguments:
381-
Exclude:
382-
- 'lib/json-schema/util/uri.rb'
383-
384254
# Offense count: 3
385255
# This cop supports unsafe autocorrection (--autocorrect-all).
386256
# Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments.
@@ -390,20 +260,9 @@ Style/SymbolProc:
390260
- 'lib/json-schema/errors/validation_error.rb'
391261
- 'lib/json-schema/validator.rb'
392262

393-
# Offense count: 5
394-
# This cop supports safe autocorrection (--autocorrect).
395-
# Configuration parameters: EnforcedStyle, AllowSafeAssignment.
396-
# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex
397-
Style/TernaryParentheses:
398-
Exclude:
399-
- 'lib/json-schema/attributes/formats/ip.rb'
400-
- 'lib/json-schema/errors/validation_error.rb'
401-
- 'lib/json-schema/schema/reader.rb'
402-
- 'lib/json-schema/validator.rb'
403-
404263
# Offense count: 71
405264
# This cop supports safe autocorrection (--autocorrect).
406-
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
265+
# Configuration parameters: AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
407266
# URISchemes: http, https
408267
Layout/LineLength:
409268
Max: 235

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ begin
7171
rescue LoadError
7272
else
7373
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
74-
config.exclude_labels = %w{duplicate question invalid wontfix wont-fix skip-changelog dependencies}
74+
config.exclude_labels = %w[duplicate question invalid wontfix wont-fix skip-changelog dependencies]
7575
config.user = 'voxpupuli'
7676
config.project = 'json-schema'
7777
gem_version = Gem::Specification.load("#{config.project}.gemspec").version

json-schema.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ Gem::Specification.new do |s|
1414
s.files = Dir['lib/**/*', 'resources/*.json']
1515
s.require_path = 'lib'
1616
s.extra_rdoc_files = ['README.md', 'LICENSE.md']
17-
s.required_ruby_version = '>= 2.7'
17+
s.required_ruby_version = '>= 3.2'
1818
s.license = 'MIT'
1919

2020
s.add_development_dependency 'minitest', '~> 5.0'
2121
s.add_development_dependency 'rake', '~> 13.0'
22-
s.add_development_dependency 'voxpupuli-rubocop', '~> 3.1.0'
22+
s.add_development_dependency 'voxpupuli-rubocop', '~> 4.2.0'
2323
s.add_development_dependency 'webmock', '~> 3.23'
2424

2525
s.add_dependency 'addressable', '~> 2.8'

lib/json-schema/attributes/additionalproperties.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def self.remove_valid_properties(extra_properties, current_schema, validator)
3030
schema = current_schema.schema
3131

3232
if schema['properties']
33-
extra_properties = extra_properties - schema['properties'].keys
33+
extra_properties -= schema['properties'].keys
3434
end
3535

3636
schema['patternProperties']&.each_key do |key|

lib/json-schema/attributes/allof.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def self.validate(current_schema, data, fragments, processor, validator, options
3232
diff = validation_errors(processor).count - pre_validation_error_count
3333

3434
while diff > 0
35-
diff = diff - 1
35+
diff -= 1
3636
errors["allOf ##{schema_index}"].push(validation_errors(processor).pop)
3737
end
3838
end
@@ -44,7 +44,7 @@ def self.validate(current_schema, data, fragments, processor, validator, options
4444
common_missing_properties = (all_property_errors.first || []).to_set
4545

4646
all_property_errors[1..].each do |curr_property_errors|
47-
common_missing_properties = common_missing_properties & curr_property_errors.to_set
47+
common_missing_properties &= curr_property_errors.to_set
4848
end
4949
end
5050

lib/json-schema/attributes/anyof.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def self.validate(current_schema, data, fragments, processor, validator, options
2727
diff = validation_errors(processor).count - pre_validation_error_count
2828
valid = false if diff > 0
2929
while diff > 0
30-
diff = diff - 1
30+
diff -= 1
3131
errors["anyOf ##{schema_index}"].push(validation_errors(processor).pop)
3232
end
3333

@@ -36,7 +36,7 @@ def self.validate(current_schema, data, fragments, processor, validator, options
3636
data = original_data
3737
end
3838

39-
if !valid
39+
unless valid
4040
message = "The property '#{build_fragment(fragments)}' of type #{type_of_data(data)} did not match one or more of the required schemas"
4141
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
4242
validation_errors(processor).last.sub_errors = errors

lib/json-schema/attributes/extends.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Schema
66
class ExtendsAttribute < Attribute
77
def self.validate(current_schema, data, fragments, processor, validator, options = {})
88
schemas = current_schema.schema['extends']
9-
schemas = [schemas] if !schemas.is_a?(Array)
9+
schemas = [schemas] unless schemas.is_a?(Array)
1010
schemas.each do |s|
1111
uri, schema = get_extended_uri_and_schema(s, current_schema, validator)
1212
if schema
@@ -22,15 +22,17 @@ def self.validate(current_schema, data, fragments, processor, validator, options
2222
end
2323

2424
def self.get_extended_uri_and_schema(s, current_schema, validator)
25-
uri, schema = nil, nil
25+
uri = nil
26+
schema = nil
2627

2728
if s.is_a?(Hash)
2829
uri = current_schema.uri
2930
if s['$ref']
3031
ref_uri, ref_schema = JSON::Schema::RefAttribute.get_referenced_uri_and_schema(s, current_schema, validator)
3132
if ref_schema
3233
if s.size == 1 # Check if anything else apart from $ref
33-
uri, schema = ref_uri, ref_schema
34+
uri = ref_uri
35+
schema = ref_schema
3436
else
3537
s = s.dup
3638
s.delete '$ref'

lib/json-schema/attributes/formats/custom.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ def initialize(validation_proc)
99
end
1010

1111
def validate(current_schema, data, fragments, processor, _validator, options = {})
12-
begin
13-
@validation_proc.call data
14-
rescue JSON::Schema::CustomFormatError => e
15-
message = "The property '#{self.class.build_fragment(fragments)}' #{e.message}"
16-
self.class.validation_error(processor, message, fragments, current_schema, self.class, options[:record_errors])
17-
end
12+
@validation_proc.call data
13+
rescue JSON::Schema::CustomFormatError => e
14+
message = "The property '#{self.class.build_fragment(fragments)}' #{e.message}"
15+
self.class.validation_error(processor, message, fragments, current_schema, self.class, options[:record_errors])
1816
end
1917
end
2018
end

0 commit comments

Comments
 (0)