ruby-json-schema/json-schema

View on GitHub

Showing 91 of 97 total issues

File validator.rb has 507 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'open-uri'
require 'pathname'
require 'bigdecimal'
require 'digest/sha1'
require 'date'
Severity: Major
Found in lib/json-schema/validator.rb - About 1 day to fix

    Class Validator has 47 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Validator
        @@schemas = {}
        @@cache_schemas = true
        @@default_opts = {
          list: false,
    Severity: Minor
    Found in lib/json-schema/validator.rb - About 6 hrs to fix

      Method validate has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

            def self.validate(current_schema, data, fragments, processor, validator, options = {})
              return unless data.is_a?(Hash)
      
              schema = current_schema.schema
              schema['properties'].each do |property, property_schema|
      Severity: Minor
      Found in lib/json-schema/attributes/properties.rb - About 3 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method validate has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

            def self.validate(current_schema, data, fragments, processor, validator, options = {})
              union = true
              if options[:disallow]
                types = current_schema.schema['disallow']
              else
      Severity: Minor
      Found in lib/json-schema/attributes/type.rb - About 3 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method validate has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

            def self.validate(current_schema, data, fragments, processor, validator, options = {})
              # Timestamp in restricted ISO-8601 YYYY-MM-DDThh:mm:ssZ with optional decimal fraction of the second
              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))
      Severity: Minor
      Found in lib/json-schema/attributes/formats/date_time.rb - About 3 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method build_schemas has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

          def build_schemas(parent_schema)
            schema = parent_schema.schema
      
            # Build ref schemas if they exist
            if schema['$ref']
      Severity: Minor
      Found in lib/json-schema/validator.rb - About 3 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method initialize_schema has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          def initialize_schema(schema, default_validator)
            if schema.is_a?(String)
              begin
                # Build a fake URI for this
                schema_uri = JSON::Util::URI.parse(fake_uuid(schema))
      Severity: Minor
      Found in lib/json-schema/validator.rb - About 3 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method validate has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

            def self.validate(current_schema, data, fragments, processor, validator, options = {})
              errors = Hash.new { |hsh, k| hsh[k] = [] }
      
              validation_error_count = 0
              one_of = current_schema.schema['oneOf']
      Severity: Minor
      Found in lib/json-schema/attributes/oneof.rb - About 2 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method initialize_data has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          def initialize_data(data)
            if @options[:parse_data]
              if @options[:json]
                data = self.class.parse(data)
              elsif @options[:uri]
      Severity: Minor
      Found in lib/json-schema/validator.rb - About 2 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method create has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

              def create clock = nil, time = nil, mac_addr = nil
                c = t = m = nil
                Dir.chdir Dir.tmpdir do
                  unless FileTest.exist? STATE_FILE then
                    # Generate a pseudo MAC address because we have no pure-ruby way
      Severity: Minor
      Found in lib/json-schema/util/uuid.rb - About 2 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method parse has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

            def parse(s)
              if defined?(MultiJson)
                begin
                  MultiJson.respond_to?(:adapter) ? MultiJson.load(s) : MultiJson.decode(s)
                rescue MultiJson::ParseError => e
      Severity: Minor
      Found in lib/json-schema/validator.rb - About 2 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method create has 51 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              def create clock = nil, time = nil, mac_addr = nil
                c = t = m = nil
                Dir.chdir Dir.tmpdir do
                  unless FileTest.exist? STATE_FILE then
                    # Generate a pseudo MAC address because we have no pure-ruby way
      Severity: Major
      Found in lib/json-schema/util/uuid.rb - About 2 hrs to fix

        Method validate has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

              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 time in the format of hh:mm:ss"
                  if (m = REGEXP.match(data))
                    validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors]) and return if m[1].to_i > 23
        Severity: Minor
        Found in lib/json-schema/attributes/formats/time.rb - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method build_schemas has 47 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def build_schemas(parent_schema)
              schema = parent_schema.schema
        
              # Build ref schemas if they exist
              if schema['$ref']
        Severity: Minor
        Found in lib/json-schema/validator.rb - About 1 hr to fix

          Method validate has 46 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def self.validate(current_schema, data, fragments, processor, validator, options = {})
                  union = true
                  if options[:disallow]
                    types = current_schema.schema['disallow']
                  else
          Severity: Minor
          Found in lib/json-schema/attributes/type.rb - About 1 hr to fix

            Method get_referenced_uri_and_schema has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

                  def self.get_referenced_uri_and_schema(s, current_schema, validator)
                    uri, schema = nil, nil
            
                    temp_uri = JSON::Util::URI.normalize_ref(s['$ref'], current_schema.uri)
            
            
            Severity: Minor
            Found in lib/json-schema/attributes/ref.rb - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method initialize has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

                def initialize(schema_data, opts = {})
                  @options = @@default_opts.clone.merge(opts)
                  @errors = []
            
                  configured_validator = self.class.validator_for_name(@options[:version])
            Severity: Minor
            Found in lib/json-schema/validator.rb - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method initialize has 43 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  def initialize
                    super
                    @attributes = {
                      'type' => JSON::Schema::TypeV4Attribute,
                      'allOf' => JSON::Schema::AllOfAttribute,
            Severity: Minor
            Found in lib/json-schema/validators/draft6.rb - About 1 hr to fix

              Method validate has 42 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    def self.validate(current_schema, data, fragments, processor, validator, options = {})
                      return unless data.is_a?(Hash)
              
                      schema = current_schema.schema
                      schema['properties'].each do |property, property_schema|
              Severity: Minor
              Found in lib/json-schema/attributes/properties.rb - About 1 hr to fix

                Method initialize has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      def initialize
                        super
                        @attributes = {
                          'type' => JSON::Schema::TypeV4Attribute,
                          'allOf' => JSON::Schema::AllOfAttribute,
                Severity: Minor
                Found in lib/json-schema/validators/draft4.rb - About 1 hr to fix
                  Severity
                  Category
                  Status
                  Source
                  Language