opal/corelib/string.rb

Summary

Maintainability
F
5 days
Test Coverage

File string.rb has 1595 lines of code (exceeds 1000 allowed). Consider refactoring.
Open

require 'corelib/comparable'
require 'corelib/regexp'

class ::String < `String`
  include ::Comparable
Severity: Major
Found in opal/corelib/string.rb - About 2 days to fix

    Method tr_s has 149 lines of code (exceeds 30 allowed). Consider refactoring.
    Open

      def tr_s(from, to)
        %x{
          from = $coerce_to(from, #{::String}, 'to_str').$to_s();
          to = $coerce_to(to, #{::String}, 'to_str').$to_s();
    
    
    Severity: Major
    Found in opal/corelib/string.rb - About 5 hrs to fix

      Method tr has 130 lines of code (exceeds 30 allowed). Consider refactoring.
      Open

        def tr(from, to)
          %x{
            from = $coerce_to(from, #{::String}, 'to_str').$to_s();
            to = $coerce_to(to, #{::String}, 'to_str').$to_s();
      
      
      Severity: Major
      Found in opal/corelib/string.rb - About 5 hrs to fix

        Method split has 77 lines of code (exceeds 30 allowed). Consider refactoring.
        Open

          def split(pattern = undefined, limit = undefined)
            %x{
              if (self.length === 0) {
                return [];
              }
        Severity: Major
        Found in opal/corelib/string.rb - About 2 hrs to fix

          Method next has 67 lines of code (exceeds 30 allowed). Consider refactoring.
          Open

            def next
              %x{
                var i = self.length;
                if (i === 0) {
                  return '';
          Severity: Major
          Found in opal/corelib/string.rb - About 2 hrs to fix

            Method [] has 66 lines of code (exceeds 30 allowed). Consider refactoring.
            Open

              def [](index, length = undefined)
                %x{
                  var size = self.length, exclude, range;
            
                  if (index.$$is_range) {
            Severity: Major
            Found in opal/corelib/string.rb - About 2 hrs to fix

              Method gsub has 61 lines of code (exceeds 30 allowed). Consider refactoring.
              Open

                def gsub(pattern, replacement = undefined, &block)
                  %x{
                    if (replacement === undefined && block === nil) {
                      return #{enum_for :gsub, pattern};
                    }
              Severity: Major
              Found in opal/corelib/string.rb - About 2 hrs to fix

                Method to_i has 51 lines of code (exceeds 30 allowed). Consider refactoring.
                Open

                  def to_i(base = 10)
                    %x{
                      var result,
                          string = self.toLowerCase(),
                          radix = $coerce_to(base, #{::Integer}, 'to_int');
                Severity: Major
                Found in opal/corelib/string.rb - About 1 hr to fix

                  Method sub has 40 lines of code (exceeds 30 allowed). Consider refactoring.
                  Open

                    def sub(pattern, replacement = undefined, &block)
                      %x{
                        if (!pattern.$$is_regexp) {
                          pattern = $coerce_to(pattern, #{::String}, 'to_str');
                          pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
                  Severity: Minor
                  Found in opal/corelib/string.rb - About 1 hr to fix

                    Method index has 39 lines of code (exceeds 30 allowed). Consider refactoring.
                    Open

                      def index(search, offset = undefined)
                        %x{
                          var index,
                              match,
                              regex;
                    Severity: Minor
                    Found in opal/corelib/string.rb - About 1 hr to fix

                      Method oct has 37 lines of code (exceeds 30 allowed). Consider refactoring.
                      Open

                        def oct
                          %x{
                            var result,
                                string = self,
                                radix = 8;
                      Severity: Minor
                      Found in opal/corelib/string.rb - About 1 hr to fix

                        Method rindex has 35 lines of code (exceeds 30 allowed). Consider refactoring.
                        Open

                          def rindex(search, offset = undefined)
                            %x{
                              var i, m, r, _m;
                        
                              if (offset === undefined) {
                        Severity: Minor
                        Found in opal/corelib/string.rb - About 1 hr to fix

                          Method each_line has 35 lines of code (exceeds 30 allowed). Consider refactoring.
                          Open

                            def each_line(separator = $/, chomp: false, &block)
                              return enum_for :each_line, separator, chomp: chomp unless block_given?
                          
                              %x{
                                if (separator === nil) {
                          Severity: Minor
                          Found in opal/corelib/string.rb - About 1 hr to fix

                            Method upto has 35 lines of code (exceeds 30 allowed). Consider refactoring.
                            Open

                              def upto(stop, excl = false, &block)
                                return enum_for :upto, stop, excl unless block_given?
                                %x{
                                  var a, b, s = self.toString();
                            
                            
                            Severity: Minor
                            Found in opal/corelib/string.rb - About 1 hr to fix

                              Method rpartition has 32 lines of code (exceeds 30 allowed). Consider refactoring.
                              Open

                                def rpartition(sep)
                                  %x{
                                    var i, m, r, _m;
                              
                                    if (sep.$$is_regexp) {
                              Severity: Minor
                              Found in opal/corelib/string.rb - About 1 hr to fix

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

                                    width  = `$coerce_to(#{width}, #{::Integer}, 'to_int')`
                                    padstr = `$coerce_to(#{padstr}, #{::String}, 'to_str')`.to_s
                                
                                    if padstr.empty?
                                      ::Kernel.raise ::ArgumentError, 'zero width padding'
                                Severity: Minor
                                Found in opal/corelib/string.rb and 1 other location - About 30 mins to fix
                                opal/corelib/string.rb on lines 702..712

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

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

                                  def ljust(width, padstr = ' ')
                                    width  = `$coerce_to(#{width}, #{::Integer}, 'to_int')`
                                    padstr = `$coerce_to(#{padstr}, #{::String}, 'to_str')`.to_s
                                
                                    if padstr.empty?
                                Severity: Minor
                                Found in opal/corelib/string.rb and 1 other location - About 30 mins to fix
                                opal/corelib/string.rb on lines 964..974

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

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

                                
                                      if (from.length == 0 || from === to) {
                                        return self;
                                      }
                                
                                
                                Severity: Minor
                                Found in opal/corelib/string.rb and 1 other location - About 30 mins to fix
                                opal/corelib/string.rb on lines 1563..1662

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

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

                                
                                      if (from.length == 0) {
                                        return self;
                                      }
                                
                                
                                Severity: Minor
                                Found in opal/corelib/string.rb and 1 other location - About 30 mins to fix
                                opal/corelib/string.rb on lines 1418..1517

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

                                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

                                There are no issues that match your filters.

                                Category
                                Status