twitter/twitter-cldr-rb

View on GitHub

Showing 209 of 209 total issues

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

      def parent_locales
        @parent_locales ||= supplemental_data.xpath('//parentLocales/parentLocale').each_with_object({}) do |node, ret|
          parent = node.attr('parent')
          locales = node.attr('locales').split(' ')

Severity: Minor
Found in lib/twitter_cldr/resources/cldr_locale.rb and 1 other location - About 25 mins to fix
lib/twitter_cldr/resources/parent_locales_importer.rb on lines 24..33

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 31.

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

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

      def execute
        output_file = File.join(output_path, 'validity_data.yml')
        FileUtils.mkdir_p(output_path)

        File.open(output_file, 'w:utf-8') do |output|
Severity: Minor
Found in lib/twitter_cldr/resources/validity_data_importer.rb and 1 other location - About 25 mins to fix
lib/twitter_cldr/resources/aliases_importer.rb on lines 20..29

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 31.

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

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

      def parent_locales
        @parent_locales ||= supplemental_data.xpath('//parentLocales/parentLocale').each_with_object({}) do |node, ret|
          parent = node.attr('parent')
          locales = node.attr('locales').split(' ')

Severity: Minor
Found in lib/twitter_cldr/resources/parent_locales_importer.rb and 1 other location - About 25 mins to fix
lib/twitter_cldr/resources/cldr_locale.rb on lines 60..69

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 31.

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

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

  module DataReaders
    class TimeDataReader < CalendarDataReader

      def tokenizer
        @tokenizer ||= TwitterCldr::Tokenizers::TimeTokenizer.new(self)
Severity: Minor
Found in lib/twitter_cldr/data_readers/time_data_reader.rb and 1 other location - About 25 mins to fix
lib/twitter_cldr/data_readers/date_data_reader.rb on lines 7..21

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 31.

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

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

  module DataReaders
    class DateDataReader < CalendarDataReader

      def tokenizer
        @tokenizer ||= TwitterCldr::Tokenizers::DateTokenizer.new(self)
Severity: Minor
Found in lib/twitter_cldr/data_readers/date_data_reader.rb and 1 other location - About 25 mins to fix
lib/twitter_cldr/data_readers/time_data_reader.rb on lines 7..21

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 31.

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 to_a has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def to_a(compress = false)
        if compress
          ranges.map do |range|
            if range.first == range.last
              range.first
Severity: Minor
Found in lib/twitter_cldr/utils/range_set.rb - About 25 mins 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 character_class has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def character_class
        operator_stack = []
        operand_stack = []
        open_count = 0

Severity: Minor
Found in lib/twitter_cldr/parsers/unicode_regex_parser.rb - About 25 mins 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 property_values_for has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def property_values_for(property_name)
        if property_values.include?(property_name)
          return property_values[property_name]
        end

Severity: Minor
Found in lib/twitter_cldr/shared/properties_database.rb - About 25 mins 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 import_iso_639 has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def import_iso_639(result = {})
        File.open(source_path_for(ISO_639_FILE)) do |file|
          lines = file.each_line
          lines.next # skip header

Severity: Minor
Found in lib/twitter_cldr/resources/language_codes_importer.rb - About 25 mins 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 alias_for has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def alias_for(alias_tag)
        doc.xpath("//alias/#{alias_tag}").inject({}) do |ret, alias_data|
          if replacement_attr = alias_data.attribute('replacement')
            replacement = replacement_attr.value

Severity: Minor
Found in lib/twitter_cldr/resources/aliases_importer.rb - About 25 mins 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 eras has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def eras
        return {} unless calendar

        ERA_TAGS.each_with_object({}) do |era_tag, result|
          key  = era_tag.gsub('era', '').gsub(/s$/, '').downcase.to_sym
Severity: Minor
Found in lib/twitter_cldr/resources/calendars_importer.rb - About 25 mins 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 subtract has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def subtract(range_set)
        return self if range_set.empty?
        remaining = range_set.ranges.dup
        current_ranges = ranges.dup
        new_ranges = []
Severity: Minor
Found in lib/twitter_cldr/utils/range_set.rb - About 25 mins 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 break_weights_for has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def break_weights_for(text)
        break_weights = Array.new(text.size - 1, 0)

        text.each_char.with_index do |char, idx|
          subtrie = trie.root
Severity: Minor
Found in lib/twitter_cldr/shared/hyphenator.rb - About 25 mins 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 normalize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def normalize(property_name, property_value = nil)
        candidates = find_property_name_candidates(property_name)

        if property_value
          name, value = resolve_candidates(candidates, property_value)
Severity: Minor
Found in lib/twitter_cldr/shared/property_normalizer.rb - About 25 mins 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 precision_from has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def precision_from(num)
        return 0 if num.is_a?(BigDecimal) && num.fix == num
        parts = (num.is_a?(BigDecimal) ? num.to_s("F") : num.to_s ).split(".")
        parts.size == 2 ? parts[1].size : 0
      end
Severity: Minor
Found in lib/twitter_cldr/formatters/numbers/number_formatter.rb - About 25 mins 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 each_property_pair has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def each_property_pair
        if block_given?
          property_names.each do |property_name|
            if property_values = property_values_for(property_name)
              property_values.each do |property_value|
Severity: Minor
Found in lib/twitter_cldr/shared/properties_database.rb - About 25 mins 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 match has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def match(cursor)
          if before_match = match_before(cursor)
            if key_match = match_key(cursor, before_match)
              if after_match = match_after(cursor, key_match)
                SideMatch.new(
Severity: Minor
Found in lib/twitter_cldr/transforms/conversions/side.rb - About 25 mins 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 find_prefix has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def find_prefix(key)
        last_prefix_size = 0
        last_with_value  = @root

        key.each_with_index.inject(@root) do |node, (key_element, index)|
Severity: Minor
Found in lib/twitter_cldr/utils/trie.rb - About 25 mins 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 union has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def self.union(*tokenizers)
        recognizers = tokenizers.inject([]) do |ret, tokenizer|
          ret + tokenizer.recognizers.inject([]) do |recog_ret, recognizer|
            if (block_given? && yield(recognizer)) || !block_given?
              recog_ret << recognizer
Severity: Minor
Found in lib/twitter_cldr/tokenizers/tokenizer.rb - About 25 mins 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 import_dictionary_file has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def import_dictionary_file(dictionary_file)
        source_url = url_for(dictionary_file)
        source = URI.open(source_url).read
        lines = source.split("\n")
        trie = TwitterCldr::Utils::Trie.new
Severity: Minor
Found in lib/twitter_cldr/resources/segment_dictionaries_importer.rb - About 25 mins 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