Skip to content

Commit

Permalink
Added rubocop.yml and corrected simple style warnings
Browse files Browse the repository at this point in the history
* Largely based on the default styles for houndci
  • Loading branch information
Iain Beeston committed Dec 22, 2015
1 parent 0d26205 commit 4f44ad8
Show file tree
Hide file tree
Showing 89 changed files with 1,390 additions and 1,207 deletions.
2 changes: 2 additions & 0 deletions .hound.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ruby:
config_file: .rubocop.yml
253 changes: 253 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
AllCops:
Exclude:
- lib/json-schema/util/uuid.rb
UseCache: false
Style/ClassVars:
Description: Avoid the use of class variables.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-class-vars
Exclude:
- lib/json-schema/validator.rb
Style/CollectionMethods:
Description: Preferred collection methods.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
Enabled: true
PreferredMethods:
collect: map
collect!: map!
find: detect
find_all: select
reduce: inject
Style/DotPosition:
Description: Checks the position of the dot in multi-line method calls.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
Enabled: true
EnforcedStyle: trailing
SupportedStyles:
- leading
- trailing
Style/FileName:
Description: Use snake_case for source file names.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
Enabled: false
Exclude: []
Style/GuardClause:
Description: Check for conditionals that can be replaced with guard clauses
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
Enabled: false
MinBodyLength: 1
Style/IfUnlessModifier:
Description: Favor modifier if/unless usage when you have a single-line body.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
Enabled: false
MaxLineLength: 80
Style/Lambda:
Description: Use the new lambda literal syntax for single-line blocks.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#lambda-multi-line
Enabled: false
Style/OptionHash:
Description: "Don't use option hashes when you can use keyword arguments."
Enabled: false
Style/PredicateName:
Description: Check the names of predicate methods.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
Enabled: true
NamePrefix:
- is_
- has_
- have_
NamePrefixBlacklist:
- is_
Exclude:
- spec/**/*
Style/Proc:
Description: Use proc instead of Proc.new.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#proc
Enabled: false
Style/RaiseArgs:
Description: Checks the arguments passed to raise/fail.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
Enabled: false
EnforcedStyle: exploded
SupportedStyles:
- compact
- exploded
Style/SignalException:
Description: Checks for proper usage of fail and raise.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
Enabled: false
EnforcedStyle: semantic
SupportedStyles:
- only_raise
- only_fail
- semantic
Style/SingleLineBlockParams:
Description: Enforces the names of some block params.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
Enabled: false
Methods:
- reduce:
- a
- e
- inject:
- a
- e
Style/SingleLineMethods:
Description: Avoid single-line methods.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
Enabled: false
AllowIfMethodIsEmpty: true
Style/SpecialGlobalVars:
Description: Avoid Perl-style global variables.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
Enabled: false
Style/StringLiterals:
Description: Checks if uses of quotes match the configured preference.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
Enabled: true
EnforcedStyle: double_quotes
SupportedStyles:
- single_quotes
- double_quotes
Style/StringLiteralsInInterpolation:
Description: Checks if uses of quotes inside expressions in interpolated strings
match the configured preference.
Enabled: true
EnforcedStyle: single_quotes
SupportedStyles:
- single_quotes
- double_quotes
Metrics/AbcSize:
Description: A calculated magnitude based on number of assignments, branches, and
conditions.
Enabled: false
Max: 15
Metrics/BlockNesting:
Description: Avoid excessive block nesting
StyleGuide: https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count
Enabled: false
Max: 3
Metrics/ClassLength:
Description: Avoid classes longer than 100 lines of code.
Enabled: false
CountComments: false
Max: 100
Metrics/LineLength:
Description: Limit lines to 80 characters.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#80-character-limits
Enabled: false
Metrics/ModuleLength:
Description: Avoid modules longer than 100 lines of code.
CountComments: false
Max: 100
Enabled: false
Metrics/CyclomaticComplexity:
Description: A complexity metric that is strongly correlated to the number of test
cases needed to validate a method.
Enabled: false
Max: 6
Metrics/MethodLength:
Description: Avoid methods longer than 10 lines of code.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
Enabled: false
CountComments: false
Max: 10
Metrics/ParameterLists:
Description: Avoid parameter lists longer than three or four parameters.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
Enabled: false
Max: 5
CountKeywordArgs: true
Metrics/PerceivedComplexity:
Description: A complexity metric geared towards measuring complexity for a human
reader.
Enabled: false
Max: 7
Lint/AssignmentInCondition:
Description: "Don't use assignment in conditions."
StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
Enabled: false
AllowSafeAssignment: true
Style/InlineComment:
Description: Avoid inline comments.
Enabled: false
Style/AccessorMethodName:
Description: Check the naming of accessor methods for get_/set_.
Enabled: false
Style/Alias:
Description: Use alias_method instead of alias.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
Enabled: false
Style/BlockDelimiters:
Description: Avoid using {...} for multi-line blocks (multiline chaining is always ugly).
Prefer {...} over do...end for single-line blocks.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#single-line-blocks
Enabled: true
EnforcedStyle: line_count_based
SupportedStyles:
- line_count_based
- semantic
- braces_for_chaining
Style/Documentation:
Description: Document classes and non-namespace modules.
Enabled: false
Style/EachWithObject:
Description: Prefer `each_with_object` over `inject` or `reduce`.
Enabled: false
Style/HashSyntax:
Description: "Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax { :a => 1, :b => 2 }."
EnforcedStyle: hash_rockets
Enabled: true
SupportedStyles:
- ruby19
- ruby19_no_mixed_keys
- hash_rockets
Style/ModuleFunction:
Description: Checks for usage of `extend self` in modules.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
Enabled: false
Style/MultilineBlockChain:
Description: Avoid multi-line chains of blocks.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#single-line-blocks
Enabled: false
Style/OneLineConditional:
Description: Favor the ternary operator(?:) over if/then/else/end constructs.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
Enabled: false
Style/Send:
Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
may overlap with existing methods.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
Enabled: false
Style/SpaceInsideHashLiteralBraces:
Description: "Use spaces inside hash literal braces - or don't."
StyleGuide: https://github.com/bbatsov/ruby-style-guide#spaces-operators
EnforcedStyle: no_space
EnforcedStyleForEmptyBraces: no_space
SupportedStyles:
- space
- no_space
Style/VariableInterpolation:
Description: "Don't interpolate global, instance and class variables directly in strings."
StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
Enabled: false
Style/WhenThen:
Description: Use when x then ... for one-line cases.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
Enabled: false
Style/WordArray:
Description: Use %w or %W for arrays of words.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-w
Enabled: false
Lint/EachWithObjectArgument:
Description: Check for immutable argument given to each_with_object.
Enabled: true
Lint/HandleExceptions:
Description: "Don't suppress exception."
StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
Enabled: false
Lint/LiteralInCondition:
Description: Checks of literals used in conditions.
Enabled: false
Lint/LiteralInInterpolation:
Description: Checks for literals used in interpolation.
Enabled: false
8 changes: 4 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'bundler'
require 'rake'
require 'rake/testtask'
require "bundler"
require "rake"
require "rake/testtask"

Bundler::GemHelper.install_tasks

Expand All @@ -16,7 +16,7 @@ Rake::TestTask.new do |t|
t.libs << "."
t.warning = true
t.verbose = true
t.test_files = FileList.new('test/test*.rb') do |fl|
t.test_files = FileList.new("test/test*.rb") do |fl|
fl.exclude(/test_helper\.rb$/)
end
end
Expand Down
12 changes: 6 additions & 6 deletions json-schema.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'yaml'
require "yaml"

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

Expand All @@ -11,17 +11,17 @@ Gem::Specification.new do |s|
s.email = "[email protected]"
s.homepage = "http://github.com/ruby-json-schema/json-schema/tree/master"
s.summary = "Ruby JSON Schema Validator"
s.files = Dir[ "lib/**/*", "resources/*.json" ]
s.files = Dir["lib/**/*", "resources/*.json"]
s.require_path = "lib"
s.extra_rdoc_files = ["README.textile","LICENSE.md"]
s.extra_rdoc_files = ["README.textile", "LICENSE.md"]
s.required_ruby_version = ">= 1.8.7"
s.license = "MIT"
s.required_rubygems_version = ">= 1.8"

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

s.add_runtime_dependency "addressable", '~> 2.3.8'
s.add_runtime_dependency "addressable", "~> 2.3.8"
end
22 changes: 11 additions & 11 deletions lib/json-schema.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
require 'rubygems'
require "rubygems"

if Gem::Specification::find_all_by_name('multi_json').any?
require 'multi_json'
if Gem::Specification.find_all_by_name("multi_json").any?
require "multi_json"

# Force MultiJson to load an engine before we define the JSON constant here; otherwise,
# it looks for things that are under the JSON namespace that aren't there (since we have defined it here)
MultiJson.respond_to?(:adapter) ? MultiJson.adapter : MultiJson.engine
end

require 'json-schema/util/array_set'
require 'json-schema/util/uri'
require 'json-schema/schema'
require 'json-schema/schema/reader'
require 'json-schema/validator'
require "json-schema/util/array_set"
require "json-schema/util/uri"
require "json-schema/schema"
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/attributes/formats/*.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/attributes/formats/*.rb")].each { |file| require file }
Dir[File.join(File.dirname(__FILE__), "json-schema/validators/*.rb")].sort!.each { |file| require file }
4 changes: 2 additions & 2 deletions lib/json-schema/attribute.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'json-schema/errors/validation_error'
require "json-schema/errors/validation_error"

module JSON
class Schema
class Attribute
def self.validate(current_schema, data, fragments, processor, validator, options = {})
def self.validate(_current_schema, _data, _fragments, _processor, _validator, _options = {})
end

def self.build_fragment(fragments)
Expand Down
12 changes: 6 additions & 6 deletions lib/json-schema/attributes/additionalitems.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'json-schema/attribute'
require "json-schema/attribute"

module JSON
class Schema
Expand All @@ -7,18 +7,18 @@ def self.validate(current_schema, data, fragments, processor, validator, options
return unless data.is_a?(Array)

schema = current_schema.schema
return unless schema['items'].is_a?(Array)
return unless schema["items"].is_a?(Array)

case schema['additionalItems']
case schema["additionalItems"]
when false
if schema['items'].length != data.length
if schema["items"].length != data.length
message = "The property '#{build_fragment(fragments)}' contains additional array elements outside of the schema when none are allowed"
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
end
when Hash
additional_items_schema = JSON::Schema.new(schema['additionalItems'], current_schema.uri, validator)
additional_items_schema = JSON::Schema.new(schema["additionalItems"], current_schema.uri, validator)
data.each_with_index do |item, i|
next if i < schema['items'].length
next if i < schema["items"].length
additional_items_schema.validate(item, fragments + [i.to_s], processor, options)
end
end
Expand Down
Loading

0 comments on commit 4f44ad8

Please sign in to comment.