Skip to content

Commit

Permalink
rubocop: Fix Style/StringLiterals
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Feb 17, 2023
1 parent d7cd769 commit 854104d
Show file tree
Hide file tree
Showing 55 changed files with 1,193 additions and 1,200 deletions.
7 changes: 0 additions & 7 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -825,13 +825,6 @@ Style/StringConcatenation:
- 'lib/json-schema/util/uuid.rb'
- 'test/schema_reader_test.rb'

# Offense count: 2208
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Enabled: false

# Offense count: 7
# Cop supports --auto-correct.
# Configuration parameters: MinSize.
Expand Down
18 changes: 9 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ require 'rake/testtask'

Bundler::GemHelper.install_tasks

desc "Updates the json-schema common test suite to the latest version"
desc 'Updates the json-schema common test suite to the latest version'
task :update_common_tests do
unless File.read(".git/config").include?('submodule "test/test-suite"')
sh "git submodule init"
unless File.read('.git/config').include?('submodule "test/test-suite"')
sh 'git submodule init'
end

puts "Updating json-schema common test suite..."
puts 'Updating json-schema common test suite...'

begin
sh "git submodule update --remote --quiet"
sh 'git submodule update --remote --quiet'
rescue StandardError
STDERR.puts "Failed to update common test suite."
STDERR.puts 'Failed to update common test suite.'
end
end

desc "Update meta-schemas to the latest version"
desc 'Update meta-schemas to the latest version'
task :update_meta_schemas do
puts "Updating meta-schemas..."
puts 'Updating meta-schemas...'

id_mappings = {
'http://json-schema.org/draft/schema#' => 'https://raw.githubusercontent.com/json-schema-org/json-schema-spec/master/schema.json',
Expand Down Expand Up @@ -57,7 +57,7 @@ task :update_meta_schemas do
end

Rake::TestTask.new do |t|
t.libs << "."
t.libs << '.'
t.warning = true
t.verbose = true
t.test_files = FileList.new('test/*_test.rb')
Expand Down
32 changes: 16 additions & 16 deletions json-schema.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ require 'yaml'

version_yaml = YAML.load(File.open(File.expand_path('../VERSION.yml', __FILE__)).read)
version = "#{version_yaml['major']}.#{version_yaml['minor']}.#{version_yaml['patch']}"
gem_name = "json-schema"
gem_name = 'json-schema'

Gem::Specification.new do |s|
s.name = gem_name
s.version = version
s.authors = ["Kenny Hoxworth", "Vox Pupuli"]
s.email = "[email protected]"
s.homepage = "http://github.com/voxpupuli/json-schema/"
s.summary = "Ruby JSON Schema Validator"
s.files = Dir[ "lib/**/*", "resources/*.json" ]
s.require_path = "lib"
s.extra_rdoc_files = ["README.md", "LICENSE.md"]
s.required_ruby_version = ">= 2.5"
s.license = "MIT"
s.required_rubygems_version = ">= 2.5"
s.authors = ['Kenny Hoxworth', 'Vox Pupuli']
s.email = '[email protected]'
s.homepage = 'http://github.com/voxpupuli/json-schema/'
s.summary = 'Ruby JSON Schema Validator'
s.files = Dir[ 'lib/**/*', 'resources/*.json' ]
s.require_path = 'lib'
s.extra_rdoc_files = ['README.md', 'LICENSE.md']
s.required_ruby_version = '>= 2.5'
s.license = 'MIT'
s.required_rubygems_version = '>= 2.5'

s.add_development_dependency "bundler"
s.add_development_dependency "minitest", '~> 5.0'
s.add_development_dependency "rake"
s.add_development_dependency "webmock"
s.add_development_dependency 'bundler'
s.add_development_dependency 'minitest', '~> 5.0'
s.add_development_dependency 'rake'
s.add_development_dependency 'webmock'

s.add_runtime_dependency "addressable", '>= 2.8'
s.add_runtime_dependency 'addressable', '>= 2.8'
end
4 changes: 2 additions & 2 deletions lib/json-schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
require 'json-schema/schema/reader'
require 'json-schema/validator'

Dir[File.join(File.dirname(__FILE__), "json-schema/attributes/**/*.rb")].each {|file| require file }
Dir[File.join(File.dirname(__FILE__), "json-schema/validators/*.rb")].sort!.each {|file| require file }
Dir[File.join(File.dirname(__FILE__), 'json-schema/attributes/**/*.rb')].each {|file| require file }
Dir[File.join(File.dirname(__FILE__), 'json-schema/validators/*.rb')].sort!.each {|file| require file }
16 changes: 8 additions & 8 deletions lib/json-schema/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ def self.validation_errors(validator)
end

TYPE_CLASS_MAPPINGS = {
"string" => String,
"number" => Numeric,
"integer" => Integer,
"boolean" => [TrueClass, FalseClass],
"object" => Hash,
"array" => Array,
"null" => NilClass,
"any" => Object,
'string' => String,
'number' => Numeric,
'integer' => Integer,
'boolean' => [TrueClass, FalseClass],
'object' => Hash,
'array' => Array,
'null' => NilClass,
'any' => Object,
}

def self.data_valid_for_type?(data, type)
Expand Down
2 changes: 1 addition & 1 deletion lib/json-schema/attributes/formats/date_time.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
if data.is_a?(String)
error_message = "The property '#{build_fragment(fragments)}' must be a date/time in the ISO-8601 format of YYYY-MM-DDThh:mm:ssZ or YYYY-MM-DDThh:mm:ss.ssZ"
if (m = REGEXP.match(data))
parts = data.split("T")
parts = data.split('T')

begin
Date.parse(parts[0])
Expand Down
2 changes: 1 addition & 1 deletion lib/json-schema/attributes/limits/numeric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def self.acceptable_type

def self.error_message(schema)
exclusivity = exclusive?(schema) ? 'exclusively' : 'inclusively'
format("did not have a %s value of %s, %s", limit_name, limit(schema), exclusivity)
format('did not have a %s value of %s, %s', limit_name, limit(schema), exclusivity)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/json-schema/attributes/maxdecimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def self.validate(current_schema, data, fragments, processor, validator, options
return unless data.is_a?(Numeric)

max_decimal_places = current_schema.schema['maxDecimal']
s = data.to_s.split(".")[1]
s = data.to_s.split('.')[1]
if s && s.length > max_decimal_places
message = "The property '#{build_fragment(fragments)}' had more decimal places than the allowed #{max_decimal_places}"
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
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 @@ -25,14 +25,14 @@ def self.get_referenced_uri_and_schema(s, current_schema, validator)
temp_uri = JSON::Util::URI.normalize_ref(s['$ref'], current_schema.uri)

# Grab the parent schema from the schema list
schema_key = temp_uri.to_s.split("#")[0] + "#"
schema_key = temp_uri.to_s.split('#')[0] + '#'

ref_schema = JSON::Validator.schema_for_uri(schema_key)

if ref_schema
# Perform fragment resolution to retrieve the appropriate level for the schema
target_schema = ref_schema.schema
fragments = JSON::Util::URI.parse(JSON::Util::URI.unescape_uri(temp_uri)).fragment.split("/")
fragments = JSON::Util::URI.parse(JSON::Util::URI.unescape_uri(temp_uri)).fragment.split('/')
fragment_path = ''
fragments.each do |fragment|
if fragment && fragment != ''
Expand Down
4 changes: 2 additions & 2 deletions lib/json-schema/attributes/required.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def self.validate(current_schema, data, fragments, processor, validator, options
prop_defaults = options[:insert_defaults] &&
defined_properties &&
defined_properties[property] &&
!defined_properties[property]["default"].nil? &&
!defined_properties[property]["readonly"]
!defined_properties[property]['default'].nil? &&
!defined_properties[property]['readonly']

if !prop_defaults
message = "The property '#{build_fragment(fragments)}' did not contain a required property of '#{property}'"
Expand Down
4 changes: 2 additions & 2 deletions lib/json-schema/errors/validation_error.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module JSON
class Schema
class ValidationError < StandardError
INDENT = " "
INDENT = ' '
attr_accessor :fragments, :schema, :failed_attribute, :sub_errors, :message

def initialize(message, fragments, failed_attribute, schema)
Expand All @@ -27,7 +27,7 @@ def to_string(subschema_level = 0)
end

def to_hash
base = {:schema => @schema.uri, :fragment => ::JSON::Schema::Attribute.build_fragment(fragments), :message => message_with_schema, :failed_attribute => @failed_attribute.to_s.split(":").last.split("Attribute").first}
base = {:schema => @schema.uri, :fragment => ::JSON::Schema::Attribute.build_fragment(fragments), :message => message_with_schema, :failed_attribute => @failed_attribute.to_s.split(':').last.split('Attribute').first}
if !@sub_errors.empty?
base[:errors] = @sub_errors.inject({}) do |hsh, (subschema, errors)|
subschema_sym = subschema.downcase.gsub(/\W+/, '_').to_sym
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 @@ -14,7 +14,7 @@ def initialize()
end

def extend_schema_definition(schema_uri)
warn "[DEPRECATION NOTICE] The preferred way to extend a Validator is by subclassing, rather than #extend_schema_definition. This method will be removed in version >= 3."
warn '[DEPRECATION NOTICE] The preferred way to extend a Validator is by subclassing, rather than #extend_schema_definition. This method will be removed in version >= 3.'
validator = JSON::Validator.validator_for_uri(schema_uri)
@attributes.merge!(validator.attributes)
end
Expand Down
10 changes: 5 additions & 5 deletions lib/json-schema/util/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def self.normalized_uri(uri, base_path = Dir.pwd)
# Check for absolute path
if normalized_uri.relative?
data = normalized_uri
data = File.join(base_path, data) if data.path[0, 1] != "/"
data = File.join(base_path, data) if data.path[0, 1] != '/'
normalized_uri = file_uri(data)
end
@normalize_cache[uri] = normalized_uri.freeze
Expand Down Expand Up @@ -42,10 +42,10 @@ def self.normalize_ref(ref, base)
ref_uri.merge!(base_uri)

# Check for absolute path
path, fragment = ref.to_s.split("#")
path, fragment = ref.to_s.split('#')
if path.nil? || path == ''
ref_uri.path = base_uri.path
elsif path[0, 1] == "/"
elsif path[0, 1] == '/'
ref_uri.path = Pathname.new(path).cleanpath.to_s
else
ref_uri.join!(path)
Expand All @@ -54,7 +54,7 @@ def self.normalize_ref(ref, base)
ref_uri.fragment = fragment
end

ref_uri.fragment = "" if ref_uri.fragment.nil? || ref_uri.fragment.empty?
ref_uri.fragment = '' if ref_uri.fragment.nil? || ref_uri.fragment.empty?
end

ref_uri
Expand All @@ -81,7 +81,7 @@ def self.strip_fragment(uri)
if parsed_uri.fragment.nil? || parsed_uri.fragment.empty?
parsed_uri
else
parsed_uri.merge(:fragment => "")
parsed_uri.merge(:fragment => '')
end
end

Expand Down
28 changes: 14 additions & 14 deletions lib/json-schema/util/uuid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def mask18 v, str # :nodoc
end

def mask v, str
if RUBY_VERSION >= "1.9.0"
if RUBY_VERSION >= '1.9.0'
return mask19 v, str
else
return mask18 v, str
Expand Down Expand Up @@ -106,7 +106,7 @@ def create_random
rand(0x100000000),
rand(0x100000000),
rand(0x100000000),
].pack "N4"
].pack 'N4'
raw = mask 4, rnd
ret = new raw
ret.freeze
Expand Down Expand Up @@ -145,13 +145,13 @@ def create clock=nil, time=nil, mac_addr=nil
# see Section 4.5 of RFC4122 for details.
sha1 = Digest::SHA1.new
256.times do
r = [rand(0x100000000)].pack "N"
r = [rand(0x100000000)].pack 'N'
sha1.update r
end
str = sha1.digest
r = rand 14 # 20-6
node = str[r, 6] || str
if RUBY_VERSION >= "1.9.0"
if RUBY_VERSION >= '1.9.0'
nnode = node.bytes.to_a
nnode[0] |= 0x01
node = ''
Expand Down Expand Up @@ -210,7 +210,7 @@ def parse obj
# The 'primitive constructor' of this class
# Note UUID.pack(uuid.unpack) == uuid
def pack tl, tm, th, ch, cl, n
raw = [tl, tm, th, ch, cl, n].pack "NnnCCa6"
raw = [tl, tm, th, ch, cl, n].pack 'NnnCCa6'
ret = new raw
ret.freeze
ret
Expand All @@ -220,27 +220,27 @@ def pack tl, tm, th, ch, cl, n
# The 'primitive deconstructor', or the dual to pack.
# Note UUID.pack(uuid.unpack) == uuid
def unpack
raw_bytes.unpack "NnnCCa6"
raw_bytes.unpack 'NnnCCa6'
end

# Generate the string representation (a.k.a GUID) of this UUID
def to_s
a = unpack
tmp = a[-1].unpack 'C*'
a[-1] = sprintf '%02x%02x%02x%02x%02x%02x', *tmp
"%08x-%04x-%04x-%02x%02x-%s" % a
'%08x-%04x-%04x-%02x%02x-%s' % a
end
alias guid to_s

# Convert into a RFC4122-comforming URN representation
def to_uri
"urn:uuid:" + self.to_s
'urn:uuid:' + self.to_s
end
alias urn to_uri

# Convert into 128-bit unsigned integer
def to_int
tmp = self.raw_bytes.unpack "C*"
tmp = self.raw_bytes.unpack 'C*'
tmp.inject do |r, i|
r * 256 | i
end
Expand Down Expand Up @@ -271,13 +271,13 @@ def <=> other
end

# Pre-defined UUID Namespaces described in RFC4122 Appendix C.
NameSpace_DNS = parse "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
NameSpace_URL = parse "6ba7b811-9dad-11d1-80b4-00c04fd430c8"
NameSpace_OID = parse "6ba7b812-9dad-11d1-80b4-00c04fd430c8"
NameSpace_X500 = parse "6ba7b814-9dad-11d1-80b4-00c04fd430c8"
NameSpace_DNS = parse '6ba7b810-9dad-11d1-80b4-00c04fd430c8'
NameSpace_URL = parse '6ba7b811-9dad-11d1-80b4-00c04fd430c8'
NameSpace_OID = parse '6ba7b812-9dad-11d1-80b4-00c04fd430c8'
NameSpace_X500 = parse '6ba7b814-9dad-11d1-80b4-00c04fd430c8'

# The Nil UUID in RFC4122 Section 4.1.7
Nil = parse "00000000-0000-0000-0000-000000000000"
Nil = parse '00000000-0000-0000-0000-000000000000'
end
end
end
Loading

0 comments on commit 854104d

Please sign in to comment.