twitter/twitter-cldr-rb

View on GitHub

Showing 209 of 209 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    class NumberFormatsImporter < Importer

      requirement :cldr, Versions.cldr_version
      output_path 'locales'
      locales TwitterCldr.supported_locales
Severity: Major
Found in lib/twitter_cldr/resources/number_formats_importer.rb and 1 other location - About 3 hrs to fix
lib/twitter_cldr/resources/units_importer.rb on lines 15..56

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 112.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

      def advance_past_suffix(cursor, end_pos, state)
        suffix_length = 0

        if cursor.position < end_pos && state.word_length > 0
          uc = cursor.codepoint
Severity: Minor
Found in lib/twitter_cldr/segmentation/thai_break_engine.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 append_primary_bytes has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

      def append_primary_bytes
        @last_leading_byte = nil

        @collation_elements.each do |collation_element|
          bytes = integer_to_bytes_array(level_weight(collation_element, PRIMARY_LEVEL))
Severity: Minor
Found in lib/twitter_cldr/collation/sort_key_builder.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 process has 73 lines of code (exceeds 25 allowed). Consider refactoring.
Open

def process(str, rule_set)
  # markers depend on what rule set we are using
  buf = str.unpack("U*")

  name = rule_set.name
Severity: Major
Found in lib/twitter_cldr/formatters/numbers/rbnf/post_processors/chinese.rb - About 2 hrs to fix

    Method divide_up_dictionary_range has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

          def divide_up_dictionary_range(cursor, end_pos)
            return to_enum(__method__, cursor, end_pos) unless block_given?
            return if (end_pos - cursor.position) < min_word_span
    
            state = EngineState.new(
    Severity: Minor
    Found in lib/twitter_cldr/segmentation/brahmic_break_engine.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 build_rule_index has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

          def build_rule_index(rules)
            TwitterCldr::Utils::Trie.new.tap do |trie|
              rules.each_with_index do |rule, idx|
                next unless rule.forward?
    
    
    Severity: Minor
    Found in lib/twitter_cldr/transforms/conversion_rule_set.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 should_break? has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

          def should_break?(cursor)
            idx = cursor.position
    
            # consider case when a space follows the '.' (so we handle i.e. "Mr. Brown")
            idx -= 2 if cursor.codepoint(idx - 1) == 32
    Severity: Minor
    Found in lib/twitter_cldr/segmentation/suppressions.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 swapCJK has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

            def swapCJK(code_point)
              if code_point >= CJK_BASE
                return code_point - CJK_BASE                                      if code_point < CJK_LIMIT
                return code_point + NON_CJK_OFFSET                                if code_point < CJK_COMPAT_USED_BASE
                return code_point - CJK_COMPAT_USED_BASE + (CJK_LIMIT - CJK_BASE) if code_point < CJK_COMPAT_USED_LIMIT
    Severity: Minor
    Found in lib/twitter_cldr/collation/implicit_collation_elements.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

    Class DateTimeFormatter has 25 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class DateTimeFormatter < Formatter
    
          WEEKDAY_KEYS = [:sun, :mon, :tue, :wed, :thu, :fri, :sat].freeze
    
          METHODS = { # ignoring u, l, g, j, A
    Severity: Minor
    Found in lib/twitter_cldr/formatters/calendars/date_time_formatter.rb - About 2 hrs to fix

      Method patterns_from has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

            def patterns_from(format_node)
              format_node.xpath('pattern').each_with_object({}) do |pattern_node, pattern_result|
                # CLDR v42 added a few new alt patterns, alphaNextToNumber and noCurrency.
                # See: https://cldr.unicode.org/index/downloads/cldr-42#h.ocxunccgtf28
                next if pattern_node.attribute('alt')
      Severity: Minor
      Found in lib/twitter_cldr/resources/number_formats_importer.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 fractional_rule_for has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

              def fractional_rule_for(number)
                # the obvious way to do this (multiply the value being formatted
                # by each rule's base value until you get an integral result)
                # doesn't work because of rounding error.  This method is more
                # accurate
      Severity: Minor
      Found in lib/twitter_cldr/formatters/numbers/rbnf/rule_set.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 format_offset has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

            def format_offset(offset, is_basic, use_utc_indicator, is_short, ignore_seconds)
              abs_offset = offset.abs
              return UTC if use_utc_indicator && abs_offset == 0
      
              min_fields_idx = is_short ? 0 : 1
      Severity: Minor
      Found in lib/twitter_cldr/timezones/iso8601_location.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 compute_explicit_levels has 66 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def compute_explicit_levels
              current_embedding = @base_embedding
      
              # The directional override is a Character directionality
              # constant.  -1 means there is no override.
      Severity: Major
      Found in lib/twitter_cldr/shared/bidi.rb - About 2 hrs to fix

        Method handle_next has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

              def handle_next(cursor)
                result = initial_position = cursor.position
                state = START_STATE
                row = state * (metadata.category_count + NEXT_STATES)
                category = 3
        Severity: Minor
        Found in lib/twitter_cldr/segmentation/state_machine.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_tailorings has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

              def parse_tailorings(data, locale)
                rules = data && data.at_xpath('rules')
        
                return '' unless rules
        
        
        Severity: Minor
        Found in lib/twitter_cldr/resources/tailoring_importer.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 divide_up_dictionary_range has 63 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def divide_up_dictionary_range(cursor, end_pos, &block)
                return to_enum(__method__, cursor, end_pos) unless block_given?
        
                input_length = end_pos - cursor.position
                best_snlp = Array.new(input_length + 1) { LARGE_NUMBER }
        Severity: Major
        Found in lib/twitter_cldr/segmentation/cj_break_engine.rb - About 2 hrs to fix

          Method resolve_weak_types has 63 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def resolve_weak_types
                  run_count = @runs.size
                  previous_level = @base_embedding
          
                  run_count.times do |run_idx|
          Severity: Major
          Found in lib/twitter_cldr/shared/bidi.rb - About 2 hrs to fix

            Class Loader has 23 methods (exceeds 20 allowed). Consider refactoring.
            Open

                class Loader
            
                  class << self
                    def load_yaml(yaml, permitted_classes: [])
                      if Psych::VERSION >= '4'
            Severity: Minor
            Found in lib/twitter_cldr/resources/loader.rb - About 2 hrs to fix

              Class TransformId has 23 methods (exceeds 20 allowed). Consider refactoring.
              Open

                  class TransformId
                    CHAIN = [
                      :normal_fallback1, :normal_fallback2, :laddered_fallback1,
                      :normal_fallback3, :laddered_fallback2
                    ]
              Severity: Minor
              Found in lib/twitter_cldr/transforms/transform_id.rb - About 2 hrs to fix

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

                      def reorder_visually!
                        raise "No string given!" unless @string_arr
                
                        # Do this explicitly so we can also find the maximum depth at the
                        # same time.
                Severity: Minor
                Found in lib/twitter_cldr/shared/bidi.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

                Severity
                Category
                Status
                Source
                Language