Skip to content

Commit

Permalink
Merge pull request #531 from bastelfreak/vp3
Browse files Browse the repository at this point in the history
voxpupuli-rubocop: Update 2.8.0->3.0.0 & rubocop: autofix
  • Loading branch information
bastelfreak authored Nov 20, 2024
2 parents 728c17f + daa9911 commit 898030d
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 84 deletions.
65 changes: 9 additions & 56 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,11 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-08-19 09:50:18 UTC using RuboCop version 1.64.1.
# on 2024-11-19 21:17:06 UTC using RuboCop version 1.67.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
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: symmetrical, new_line, same_line
Layout/MultilineMethodCallBraceLayout:
Exclude:
- 'test/common_test_suite_test.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowedMethods, AllowedPatterns.
Lint/AmbiguousBlockAssociation:
Exclude:
- 'lib/json-schema/errors/validation_error.rb'

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
Lint/AmbiguousOperatorPrecedence:
Exclude:
- 'lib/json-schema/util/uuid.rb'

# Offense count: 4
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowSafeAssignment.
Expand All @@ -36,13 +15,6 @@ Lint/AssignmentInCondition:
- 'lib/json-schema/attributes/disallow.rb'
- 'lib/json-schema/validator.rb'

# Offense count: 8
Lint/ImplicitStringConcatenation:
Exclude:
- 'test/all_of_ref_schema_test.rb'
- 'test/any_of_ref_schema_test.rb'
- 'test/one_of_test.rb'

# Offense count: 1
# Configuration parameters: AllowedParentClasses.
Lint/MissingSuper:
Expand All @@ -62,40 +34,13 @@ Lint/RedundantRequireStatement:
Exclude:
- 'lib/json-schema/validator.rb'

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
Lint/RedundantStringCoercion:
Exclude:
- 'lib/json-schema/attributes/extends.rb'
- 'lib/json-schema/attributes/ref.rb'

# Offense count: 2
# Configuration parameters: AllowComments, AllowNil.
Lint/SuppressedException:
Exclude:
- 'Rakefile'
- 'lib/json-schema/validator.rb'

# Offense count: 4
# This cop supports safe autocorrection (--autocorrect).
Lint/TripleQuotes:
Exclude:
- 'test/all_of_ref_schema_test.rb'
- 'test/any_of_ref_schema_test.rb'
- 'test/one_of_test.rb'

# Offense count: 10
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AutoCorrect, IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
Lint/UnusedBlockArgument:
Exclude:
- 'lib/json-schema/attributes/patternproperties.rb'
- 'lib/json-schema/attributes/properties.rb'
- 'lib/json-schema/attributes/required.rb'
- 'lib/json-schema/schema.rb'
- 'lib/json-schema/schema/validator.rb'
- 'lib/json-schema/validator.rb'

# Offense count: 24
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AutoCorrect, AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods.
Expand Down Expand Up @@ -224,6 +169,14 @@ Security/Open:
- 'lib/json-schema/util/uuid.rb'
- 'lib/json-schema/validator.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle, AllowModifiersOnSymbols, AllowModifiersOnAttrs.
# SupportedStyles: inline, group
Style/AccessModifierDeclarations:
Exclude:
- 'lib/json-schema/util/uuid.rb'

# Offense count: 4
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
Expand Down
4 changes: 2 additions & 2 deletions json-schema.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Gem::Specification.new do |s|

s.add_development_dependency 'minitest', '~> 5.0'
s.add_development_dependency 'rake', '~> 13.0'
s.add_development_dependency 'voxpupuli-rubocop', '~> 2.8.0'
s.add_development_dependency 'voxpupuli-rubocop', '~> 3.0.0'
s.add_development_dependency 'webmock', '~> 3.23'

s.add_runtime_dependency 'addressable', '~> 2.8'
s.add_dependency 'addressable', '~> 2.8'
end
2 changes: 1 addition & 1 deletion lib/json-schema/attributes/extends.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def self.validate(current_schema, data, fragments, processor, validator, options
if schema
schema.validate(data, fragments, processor, options)
elsif uri
message = "The extended schema '#{uri.to_s}' cannot be found"
message = "The extended schema '#{uri}' cannot be found"
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
else
message = "The property '#{build_fragment(fragments)}' was not a valid schema"
Expand Down
2 changes: 1 addition & 1 deletion lib/json-schema/attributes/patternproperties.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.validate(current_schema, data, fragments, processor, validator, options
regexp = Regexp.new(property)

# Check each key in the data hash to see if it matches the regex
data.each do |key, value|
data.each do |key, _value|
next unless regexp.match(key)

schema = JSON::Schema.new(property_schema, current_schema.uri, validator)
Expand Down
4 changes: 2 additions & 2 deletions lib/json-schema/attributes/properties.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ def self.validate(current_schema, data, fragments, processor, validator, options
# When noAdditionalProperties is true, ensure no undefined properties exist in the data
return unless options[:noAdditionalProperties] == true && !schema.key?('additionalProperties')

diff = data.select do |k, v|
diff = data.select do |k, _v|
k = k.to_s

if schema.has_key?('patternProperties')
match = false
schema['patternProperties'].each do |property, property_schema|
schema['patternProperties'].each do |property, _property_schema|
regexp = Regexp.new(property)
if regexp.match(k)
match = true
Expand Down
4 changes: 2 additions & 2 deletions lib/json-schema/attributes/ref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def self.validate(current_schema, data, fragments, processor, validator, options
if schema
schema.validate(data, fragments, processor, options)
elsif uri
message = "The referenced schema '#{uri.to_s}' cannot be found"
message = "The referenced schema '#{uri}' cannot be found"
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
else
message = "The property '#{build_fragment(fragments)}' was not a valid schema"
Expand Down Expand Up @@ -44,7 +44,7 @@ def self.get_referenced_uri_and_schema(s, current_schema, validator)
end
fragment_path = fragment_path + "/#{fragment}"
if target_schema.nil?
raise SchemaError, "The fragment '#{fragment_path}' does not exist on schema #{ref_schema.uri.to_s}"
raise SchemaError, "The fragment '#{fragment_path}' does not exist on schema #{ref_schema.uri}"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/json-schema/attributes/required.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def self.validate(current_schema, data, fragments, processor, validator, options
schema = current_schema.schema
defined_properties = schema['properties']

schema['required'].each do |property, property_schema|
schema['required'].each do |property, _property_schema|
next if data.has_key?(property.to_s)

prop_defaults = options[:insert_defaults] &&
Expand Down
2 changes: 1 addition & 1 deletion lib/json-schema/errors/validation_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def to_string(subschema_level = 0)
messages = ["#{message}. The schema specific errors were:\n"]
@sub_errors.each do |subschema, errors|
messages.push "- #{subschema}:"
messages.concat Array(errors).map { |e| "#{INDENT}- #{e.to_string(subschema_level + 1)}" }
messages.concat(Array(errors).map { |e| "#{INDENT}- #{e.to_string(subschema_level + 1)}" })
end
messages.map { |m| (INDENT * subschema_level) + m }.join("\n")
end
Expand Down
2 changes: 1 addition & 1 deletion lib/json-schema/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def validate(data, fragments, processor, options = {})
def self.stringify(schema)
case schema
when Hash then
schema.map { |key, value| [key.to_s, stringify(schema[key])] }.to_h
schema.map { |key, _value| [key.to_s, stringify(schema[key])] }.to_h
when Array then
schema.map do |schema_item|
stringify(schema_item)
Expand Down
2 changes: 1 addition & 1 deletion lib/json-schema/schema/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def extend_schema_definition(schema_uri)
end

def validate(current_schema, data, fragments, processor, options = {})
current_schema.schema.each do |attr_name, attribute|
current_schema.schema.each do |attr_name, _attribute|
if @attributes.has_key?(attr_name.to_s)
@attributes[attr_name.to_s].validate(current_schema, data, fragments, processor, self, options)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/json-schema/util/uuid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def create clock = nil, time = nil, mac_addr = nil
if t.nil? then
# UUID epoch is 1582/Oct/15
tt = Time.now
t = tt.to_i * 10000000 + tt.tv_usec * 10 + 0x01B21DD213814000
t = (tt.to_i * 10000000) + (tt.tv_usec * 10) + 0x01B21DD213814000
end
c = c.succ # important; increment here
write_state fp, c, m
Expand Down Expand Up @@ -220,7 +220,7 @@ def to_uri
def to_int
tmp = raw_bytes.unpack 'C*'
tmp.inject do |r, i|
r * 256 | i
(r * 256) | i
end
end
alias to_i to_int
Expand Down
8 changes: 4 additions & 4 deletions lib/json-schema/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def build_schemas(parent_schema)
%w[definitions properties patternProperties].each do |key|
next unless value = schema[key]

value.each do |k, inner_schema|
value.each do |_k, inner_schema|
handle_schema(parent_schema, inner_schema)
end
end
Expand Down Expand Up @@ -377,22 +377,22 @@ def register_default_validator(v)
@@default_validator = v
end

def register_format_validator(format, validation_proc, versions = (@@validators.flat_map { |k, v| v.names.first } + [nil]))
def register_format_validator(format, validation_proc, versions = (@@validators.flat_map { |_k, v| v.names.first } + [nil]))
custom_format_validator = JSON::Schema::CustomFormat.new(validation_proc)
versions.each do |version|
validator = validator_for_name(version)
validator.formats[format.to_s] = custom_format_validator
end
end

def deregister_format_validator(format, versions = (@@validators.flat_map { |k, v| v.names.first } + [nil]))
def deregister_format_validator(format, versions = (@@validators.flat_map { |_k, v| v.names.first } + [nil]))
versions.each do |version|
validator = validator_for_name(version)
validator.formats[format.to_s] = validator.default_formats[format.to_s]
end
end

def restore_default_formats(versions = (@@validators.flat_map { |k, v| v.names.first } + [nil]))
def restore_default_formats(versions = (@@validators.flat_map { |_k, v| v.names.first } + [nil]))
versions.each do |version|
validator = validator_for_name(version)
validator.formats = validator.default_formats.clone
Expand Down
8 changes: 4 additions & 4 deletions test/all_of_ref_schema_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ def test_all_of_ref_subschema_errors

def test_all_of_ref_message
errors = JSON::Validator.fully_validate(schema, data)
expected_message = ''"The property '#/' of type object did not match all of the required schemas. The schema specific errors were:
expected_message = "The property '#/' of type object did not match all of the required schemas. The schema specific errors were:
- allOf #0:
- The property '#/name' of type string did not match the following type: integer"''
- The property '#/name' of type string did not match the following type: integer"

assert_equal(expected_message, errors[0])
end

def test_all_of_ref_message_with_one_attribute_wrong
errors = JSON::Validator.fully_validate(schema, data)
expected_message = ''"The property '#/' of type object did not match all of the required schemas. The schema specific errors were:
expected_message = "The property '#/' of type object did not match all of the required schemas. The schema specific errors were:
- allOf #0:
- The property '#/name' of type string did not match the following type: integer"''
- The property '#/name' of type string did not match the following type: integer"

assert_equal(expected_message, errors[0])
end
Expand Down
4 changes: 2 additions & 2 deletions test/any_of_ref_schema_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ def test_any_of_ref_subschema_errors
def test_any_of_ref_message
data = %({"names": ["jack"]})
errors = JSON::Validator.fully_validate(schema, data)
expected_message = ''"The property '#/names/0' of type string did not match one or more of the required schemas. The schema specific errors were:
expected_message = "The property '#/names/0' of type string did not match one or more of the required schemas. The schema specific errors were:
- anyOf #0:
- The property '#/names/0' value \"jack\" did not match the regex 'john'
- anyOf #1:
- The property '#/names/0' value \"jack\" did not match the regex 'jane'
- anyOf #2:
- The property '#/names/0' value \"jack\" did not match the regex 'jimmy'"''
- The property '#/names/0' value \"jack\" did not match the regex 'jimmy'"

assert_equal(expected_message, errors[0])
end
Expand Down
3 changes: 1 addition & 2 deletions test/common_test_suite_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ def self.skip?(current_test, file_path)
t['data'],
parse_data: false,
validate_schema: true,
version: version,
)
version: version)

assert_equal t['valid'], errors.empty?, "Common test suite case failed: #{err_id}"
end
Expand Down
4 changes: 2 additions & 2 deletions test/one_of_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ def test_one_of_sub_errors_message
}

errors = JSON::Validator.fully_validate(schema, { 'a' => 5 })
expected_message = ''"The property '#/' of type object did not match any of the required schemas. The schema specific errors were:
expected_message = "The property '#/' of type object did not match any of the required schemas. The schema specific errors were:
- oneOf #0:
- The property '#/a' of type integer did not match the following type: string
- oneOf #1:
- The property '#/a' of type integer did not match the following type: string
- oneOf #2:
- The property '#/a' did not have a minimum value of 10, inclusively"''
- The property '#/a' did not have a minimum value of 10, inclusively"

assert_equal(expected_message, errors[0])
end
Expand Down

0 comments on commit 898030d

Please sign in to comment.