From d854f0eabe8b4091193fc034f6233a4497ddd032 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Tue, 19 Nov 2024 22:15:46 +0100 Subject: [PATCH 1/2] voxpupuli-rubocop: Update 2.8.0->3.0.0 --- .rubocop_todo.yml | 11 ++++++++++- json-schema.gemspec | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bcb48d12..28521719 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # 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:15:03 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 @@ -37,6 +37,7 @@ Lint/AssignmentInCondition: - 'lib/json-schema/validator.rb' # Offense count: 8 +# This cop supports safe autocorrection (--autocorrect). Lint/ImplicitStringConcatenation: Exclude: - 'test/all_of_ref_schema_test.rb' @@ -224,6 +225,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. diff --git a/json-schema.gemspec b/json-schema.gemspec index fbc5ca95..cb887cee 100644 --- a/json-schema.gemspec +++ b/json-schema.gemspec @@ -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 From daa9911531ea1f9ae9bc7190bf15abaf7e7e33c8 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Tue, 19 Nov 2024 22:17:19 +0100 Subject: [PATCH 2/2] rubocop: autofix --- .rubocop_todo.yml | 58 +------------------ lib/json-schema/attributes/extends.rb | 2 +- .../attributes/patternproperties.rb | 2 +- lib/json-schema/attributes/properties.rb | 4 +- lib/json-schema/attributes/ref.rb | 4 +- lib/json-schema/attributes/required.rb | 2 +- lib/json-schema/errors/validation_error.rb | 2 +- lib/json-schema/schema.rb | 2 +- lib/json-schema/schema/validator.rb | 2 +- lib/json-schema/util/uuid.rb | 4 +- lib/json-schema/validator.rb | 8 +-- test/all_of_ref_schema_test.rb | 8 +-- test/any_of_ref_schema_test.rb | 4 +- test/common_test_suite_test.rb | 3 +- test/one_of_test.rb | 4 +- 15 files changed, 26 insertions(+), 83 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 28521719..ac0627d0 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,32 +1,11 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-11-19 21:15:03 UTC using RuboCop version 1.67.0. +# 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. @@ -36,14 +15,6 @@ Lint/AssignmentInCondition: - 'lib/json-schema/attributes/disallow.rb' - 'lib/json-schema/validator.rb' -# Offense count: 8 -# This cop supports safe autocorrection (--autocorrect). -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: @@ -63,13 +34,6 @@ 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: @@ -77,26 +41,6 @@ Lint/SuppressedException: - '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. diff --git a/lib/json-schema/attributes/extends.rb b/lib/json-schema/attributes/extends.rb index e695d884..e5f6b9f3 100644 --- a/lib/json-schema/attributes/extends.rb +++ b/lib/json-schema/attributes/extends.rb @@ -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" diff --git a/lib/json-schema/attributes/patternproperties.rb b/lib/json-schema/attributes/patternproperties.rb index 21955baa..27967997 100644 --- a/lib/json-schema/attributes/patternproperties.rb +++ b/lib/json-schema/attributes/patternproperties.rb @@ -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) diff --git a/lib/json-schema/attributes/properties.rb b/lib/json-schema/attributes/properties.rb index d6910100..7895467d 100644 --- a/lib/json-schema/attributes/properties.rb +++ b/lib/json-schema/attributes/properties.rb @@ -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 diff --git a/lib/json-schema/attributes/ref.rb b/lib/json-schema/attributes/ref.rb index cfe52666..ea21ac00 100644 --- a/lib/json-schema/attributes/ref.rb +++ b/lib/json-schema/attributes/ref.rb @@ -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" @@ -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 diff --git a/lib/json-schema/attributes/required.rb b/lib/json-schema/attributes/required.rb index f746fb49..72e18174 100644 --- a/lib/json-schema/attributes/required.rb +++ b/lib/json-schema/attributes/required.rb @@ -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] && diff --git a/lib/json-schema/errors/validation_error.rb b/lib/json-schema/errors/validation_error.rb index b6b728af..4ece8b17 100644 --- a/lib/json-schema/errors/validation_error.rb +++ b/lib/json-schema/errors/validation_error.rb @@ -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 diff --git a/lib/json-schema/schema.rb b/lib/json-schema/schema.rb index 0a2c2464..493d035b 100644 --- a/lib/json-schema/schema.rb +++ b/lib/json-schema/schema.rb @@ -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) diff --git a/lib/json-schema/schema/validator.rb b/lib/json-schema/schema/validator.rb index 1d6ea1dd..3d4c783a 100644 --- a/lib/json-schema/schema/validator.rb +++ b/lib/json-schema/schema/validator.rb @@ -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 diff --git a/lib/json-schema/util/uuid.rb b/lib/json-schema/util/uuid.rb index 4d47793a..1e603bf9 100755 --- a/lib/json-schema/util/uuid.rb +++ b/lib/json-schema/util/uuid.rb @@ -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 @@ -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 diff --git a/lib/json-schema/validator.rb b/lib/json-schema/validator.rb index 0a4d3b87..970b1971 100644 --- a/lib/json-schema/validator.rb +++ b/lib/json-schema/validator.rb @@ -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 @@ -377,7 +377,7 @@ 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) @@ -385,14 +385,14 @@ def register_format_validator(format, validation_proc, versions = (@@validators. 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 diff --git a/test/all_of_ref_schema_test.rb b/test/all_of_ref_schema_test.rb index f37cdee1..0c1133ad 100644 --- a/test/all_of_ref_schema_test.rb +++ b/test/all_of_ref_schema_test.rb @@ -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 diff --git a/test/any_of_ref_schema_test.rb b/test/any_of_ref_schema_test.rb index ffb7dbbf..9de79dd0 100644 --- a/test/any_of_ref_schema_test.rb +++ b/test/any_of_ref_schema_test.rb @@ -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 diff --git a/test/common_test_suite_test.rb b/test/common_test_suite_test.rb index 6a3828df..6f5309f3 100644 --- a/test/common_test_suite_test.rb +++ b/test/common_test_suite_test.rb @@ -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 diff --git a/test/one_of_test.rb b/test/one_of_test.rb index a9a8c4dd..39e09b7c 100644 --- a/test/one_of_test.rb +++ b/test/one_of_test.rb @@ -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