ubcsanskrit/sanscript.rb

View on GitHub

Showing 22 of 22 total issues

Method transliterate_roman has a Cognitive Complexity of 58 (exceeds 5 allowed). Consider refactoring.
Open

      def transliterate_roman(data, map, options = {})
        data = data.to_str.chars
        buf = []
        token_buffer = []
        had_consonant = false
Severity: Minor
Found in lib/sanscript/transliterate.rb - About 1 day 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 transliterate_brahmic has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
Open

      def transliterate_brahmic(data, map)
        data = data.to_str.chars
        buf = []
        had_roman_consonant = false
        transliteration_enabled = true
Severity: Minor
Found in lib/sanscript/transliterate.rb - About 5 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 transliterate_roman has 59 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def transliterate_roman(data, map, options = {})
        data = data.to_str.chars
        buf = []
        token_buffer = []
        had_consonant = false
Severity: Major
Found in lib/sanscript/transliterate.rb - About 2 hrs to fix

    Method transliterate_brahmic has 57 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def transliterate_brahmic(data, map)
            data = data.to_str.chars
            buf = []
            had_roman_consonant = false
            transliteration_enabled = true
    Severity: Major
    Found in lib/sanscript/transliterate.rb - About 2 hrs to fix

      Method make_map has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def make_map(from, to)
              @cache[:"#{from}_#{to}"] ||= begin
                alternates = @all_alternates[from] || {}
                consonants = {}
                from_scheme = @schemes[from]
      Severity: Minor
      Found in lib/sanscript/transliterate.rb - About 1 hr to fix

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

          module Detect
            # Module implementing `detect_scheme` method using Ruby 2.4's faster Regexp#match? method
            # (Note: This module will only load if chosen by {Sanscript::Detect}.)
            module Ruby24
              # Attempts to detect the encoding scheme of the provided string.
        Severity: Major
        Found in lib/sanscript/detect/ruby24.rb and 1 other location - About 1 hr to fix
        lib/sanscript/detect/ruby2x.rb on lines 4..35

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

        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 Detect
            # Module implementing `detect_scheme` method using Ruby 2.x-compatible syntax.
            # (Note: This module will only load if chosen by {Sanscript::Detect}.)
            module Ruby2x
              # Attempts to detect the encoding scheme of the provided string.
        Severity: Major
        Found in lib/sanscript/detect/ruby2x.rb and 1 other location - About 1 hr to fix
        lib/sanscript/detect/ruby24.rb on lines 4..34

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

        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 transliterate_brahmic!(time = 2, warmup = 1)
              ::Benchmark.ips do |x|
                x.config(time: time, warmup: warmup)
                TEST_STRINGS[:brahmic].to_a.product(TEST_STRINGS_FLAT.keys).each do |(ak, av), bk|
                  next if ak == bk
        Severity: Major
        Found in lib/sanscript/benchmark.rb and 1 other location - About 1 hr to fix
        lib/sanscript/benchmark.rb on lines 65..76

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

        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 transliterate_roman!(time = 2, warmup = 1)
              ::Benchmark.ips do |x|
                x.config(time: time, warmup: warmup)
                TEST_STRINGS[:roman].to_a.product(TEST_STRINGS_FLAT.keys).each do |(ak, av), bk|
                  next if ak == bk
        Severity: Major
        Found in lib/sanscript/benchmark.rb and 1 other location - About 1 hr to fix
        lib/sanscript/benchmark.rb on lines 80..91

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

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

            def transliterate(data, from, to, **opts)
              from = from.to_sym
              to = to.to_sym
              return data if from == to
              raise SchemeNotSupportedError, from unless @schemes.key?(from)
        Severity: Minor
        Found in lib/sanscript/transliterate.rb - About 55 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 ruby_detect_scheme has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

              def ruby_detect_scheme(text) # rubocop:disable AbcSize, PerceivedComplexity
                text = text.to_str.gsub(RE_CONTROL_BLOCK, "")
        
                # Brahmic schemes are all within a specific range of code points.
                brahmic_char = text[RE_BRAHMIC_RANGE]
        Severity: Minor
        Found in lib/sanscript/detect/ruby2x.rb - About 55 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 ruby_detect_scheme has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

              def ruby_detect_scheme(text) # rubocop:disable AbcSize, PerceivedComplexity
                text = text.to_str.gsub(RE_CONTROL_BLOCK, "")
        
                # Brahmic schemes are all within a specific range of code points.
                brahmic_char = text[RE_BRAHMIC_RANGE]
        Severity: Minor
        Found in lib/sanscript/detect/ruby24.rb - About 55 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

        Avoid deeply nested control flow statements.
        Open

                        buf << map[:virama] unless options[:syncope]
        Severity: Major
        Found in lib/sanscript/transliterate.rb - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                            if (temp_mark = map[:marks][token])
                              buf << temp_mark
                            elsif token != "a"
                              buf.push(map[:virama], temp_letter)
                            end
          Severity: Major
          Found in lib/sanscript/transliterate.rb - About 45 mins to fix

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

              def rust_load!
                # :nocov:
                return RUST_AVAILABLE if defined?(RUST_AVAILABLE)
                require "thermite/fiddle"
                Thermite::Fiddle.load_module("init_rusty_sanscript",
            Severity: Minor
            Found in lib/sanscript/rust.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

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

                  bengali: {
                    vowels: "অ আ ই ঈ উ ঊ ঋ ৠ ঌ ৡ  এ ঐ  ও ঔ".split(/\s/),
                    vowel_marks: "া ি ী ু ূ ৃ ৄ ৢ ৣ  ে ৈ  ো ৌ".split(/\s/),
                    other_marks: "ং ঃ ঁ".split(/\s/),
                    virama: ["্"],
            Severity: Major
            Found in lib/sanscript/transliterate/schemes.rb and 6 other locations - About 20 mins to fix
            lib/sanscript/transliterate/schemes.rb on lines 106..114
            lib/sanscript/transliterate/schemes.rb on lines 121..129
            lib/sanscript/transliterate/schemes.rb on lines 136..144
            lib/sanscript/transliterate/schemes.rb on lines 151..159
            lib/sanscript/transliterate/schemes.rb on lines 167..175
            lib/sanscript/transliterate/schemes.rb on lines 182..190

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

            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 7 locations. Consider refactoring.
            Open

                  kannada: {
                    vowels: "ಅ ಆ ಇ ಈ ಉ ಊ ಋ ೠ ಌ ೡ ಎ ಏ ಐ ಒ ಓ ಔ".split(/\s/),
                    vowel_marks: "ಾ ಿ ೀ ು ೂ ೃ ೄ ೢ ೣ ೆ ೇ ೈ ೊ ೋ ೌ".split(/\s/),
                    other_marks: "ಂ ಃ ँ".split(/\s/),
                    virama: ["್"],
            Severity: Major
            Found in lib/sanscript/transliterate/schemes.rb and 6 other locations - About 20 mins to fix
            lib/sanscript/transliterate/schemes.rb on lines 25..33
            lib/sanscript/transliterate/schemes.rb on lines 106..114
            lib/sanscript/transliterate/schemes.rb on lines 136..144
            lib/sanscript/transliterate/schemes.rb on lines 151..159
            lib/sanscript/transliterate/schemes.rb on lines 167..175
            lib/sanscript/transliterate/schemes.rb on lines 182..190

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

            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 7 locations. Consider refactoring.
            Open

                  gurmukhi: {
                    vowels: "ਅ ਆ ਇ ਈ ਉ ਊ      ਏ ਐ  ਓ ਔ".split(/\s/),
                    vowel_marks: "ਾ ਿ ੀ ੁ ੂ      ੇ ੈ  ੋ ੌ".split(/\s/),
                    other_marks: "ਂ ਃ ਁ".split(/\s/),
                    virama: ["੍"],
            Severity: Major
            Found in lib/sanscript/transliterate/schemes.rb and 6 other locations - About 20 mins to fix
            lib/sanscript/transliterate/schemes.rb on lines 25..33
            lib/sanscript/transliterate/schemes.rb on lines 121..129
            lib/sanscript/transliterate/schemes.rb on lines 136..144
            lib/sanscript/transliterate/schemes.rb on lines 151..159
            lib/sanscript/transliterate/schemes.rb on lines 167..175
            lib/sanscript/transliterate/schemes.rb on lines 182..190

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

            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 7 locations. Consider refactoring.
            Open

                  tamil: {
                    vowels: "அ ஆ இ ஈ உ ஊ     எ ஏ ஐ ஒ ஓ ஔ".split(/\s/),
                    vowel_marks: "ா ி ீ ு ூ     ெ ே ை ொ ோ ௌ".split(/\s/),
                    other_marks: "ஂ ஃ ".split(/\s/),
                    virama: ["்"],
            Severity: Major
            Found in lib/sanscript/transliterate/schemes.rb and 6 other locations - About 20 mins to fix
            lib/sanscript/transliterate/schemes.rb on lines 25..33
            lib/sanscript/transliterate/schemes.rb on lines 106..114
            lib/sanscript/transliterate/schemes.rb on lines 121..129
            lib/sanscript/transliterate/schemes.rb on lines 136..144
            lib/sanscript/transliterate/schemes.rb on lines 151..159
            lib/sanscript/transliterate/schemes.rb on lines 182..190

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

            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 7 locations. Consider refactoring.
            Open

                  oriya: {
                    vowels: "ଅ ଆ ଇ ଈ ଉ ଊ ଋ ୠ ଌ ୡ  ଏ ଐ  ଓ ଔ".split(/\s/),
                    vowel_marks: "ା ି ୀ ୁ ୂ ୃ ୄ ୢ ୣ  େ ୈ  ୋ ୌ".split(/\s/),
                    other_marks: "ଂ ଃ ଁ".split(/\s/),
                    virama: ["୍"],
            Severity: Major
            Found in lib/sanscript/transliterate/schemes.rb and 6 other locations - About 20 mins to fix
            lib/sanscript/transliterate/schemes.rb on lines 25..33
            lib/sanscript/transliterate/schemes.rb on lines 106..114
            lib/sanscript/transliterate/schemes.rb on lines 121..129
            lib/sanscript/transliterate/schemes.rb on lines 136..144
            lib/sanscript/transliterate/schemes.rb on lines 167..175
            lib/sanscript/transliterate/schemes.rb on lines 182..190

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

            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

            Severity
            Category
            Status
            Source
            Language