translation/rails

View on GitHub

Showing 30 of 32 total issues

Method build_hash_with_flat has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
Open

      def build_hash_with_flat(hash, key_string, value)
        current_object = hash
        splitted       = key_string.split(/\.|\[/, 2)
        current_key    = splitted[0] # first is always a hash
        key_string     = splitted[1]
Severity: Minor
Found in lib/translation_io/flat_hash.rb - About 7 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 display_unused_segments has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

      def display_unused_segments(parsed_response, show_purgeable, purge)
        unused_segments         = parsed_response['unused_segments'] || []
        yaml_unused_segments    = unused_segments.select { |unused_segment| unused_segment['kind'] == 'yaml' }
        gettext_unused_segments = unused_segments.select { |unused_segment| unused_segment['kind'] == 'gettext' }

Severity: Minor
Found in lib/translation_io/client/sync_operation.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 run has 48 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def run(options = {})
        purge          = options.fetch(:purge,          false)
        show_purgeable = options.fetch(:show_purgeable, false)
        readonly       = options.fetch(:readonly,       false)

Severity: Minor
Found in lib/translation_io/client/sync_operation.rb - About 1 hr to fix

    Method display_unused_segments has 48 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def display_unused_segments(parsed_response, show_purgeable, purge)
            unused_segments         = parsed_response['unused_segments'] || []
            yaml_unused_segments    = unused_segments.select { |unused_segment| unused_segment['kind'] == 'yaml' }
            gettext_unused_segments = unused_segments.select { |unused_segment| unused_segment['kind'] == 'gettext' }
    
    
    Severity: Minor
    Found in lib/translation_io/client/sync_operation.rb - About 1 hr to fix

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

              def run
                TranslationIO.info "Saving new localization YAML files (with non-string values)."
                all_flat_translations = {}
      
                @yaml_file_paths.each do |file_path|

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

              def build_hash_with_flat(hash, key_string, value)
                current_object = hash
                splitted       = key_string.split(/\.|\[/, 2)
                current_key    = splitted[0] # first is always a hash
                key_string     = splitted[1]
        Severity: Minor
        Found in lib/translation_io/flat_hash.rb - About 1 hr to fix

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

                  def run
                    TranslationIO.info "Saving new localization YAML files (with non-string values)."
                    all_flat_translations = {}
          
                    @yaml_file_paths.each do |file_path|

          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 run has 42 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def run
                  config = TranslationIO.config
          
                  source_files      = config.source_files
                  erb_source_files  = config.erb_source_files
          Severity: Minor
          Found in lib/translation_io/client/init_operation.rb - About 1 hr to fix

            Method run has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                    def run
                      @yaml_file_paths.each do |locale_file_path|
                        if locale_file_removable?(locale_file_path)
                          content_hash        = TranslationIO.yaml_load(File.read(locale_file_path)) || {}
                          source_content_hash = content_hash.reject { |k| k.to_s.in?(@target_locales.collect(&:to_s)) }
            Severity: Minor
            Found in lib/translation_io/client/init_operation/cleanup_yaml_files_step.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 run has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    def run(params)
                      TranslationIO.info "Importing translations from YAML files."
            
                      all_translations = {}
            
            

              Method source_files_for_formats has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  def source_files_for_formats(formats)
                    file_paths = []
                    root_paths = ['.']
              
                    # Add gem paths that need to be parsed by GetText ("parsed_gem" option)
              Severity: Minor
              Found in lib/translation_io/config.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 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def initialize
              
                    #######
                    # Global options
                    #######
              Severity: Minor
              Found in lib/translation_io/config.rb - About 1 hr to fix

                Method run has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                      def run(options = {})
                        purge          = options.fetch(:purge,          false)
                        show_purgeable = options.fetch(:show_purgeable, false)
                        readonly       = options.fetch(:readonly,       false)
                
                
                Severity: Minor
                Found in lib/translation_io/client/sync_operation.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 perform_request has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      def self.perform_request(uri, params)
                        begin
                          params.merge!({
                            'client'             => 'rails',
                            'version'            => TranslationIO.version,
                Severity: Minor
                Found in lib/translation_io/client/base_operation.rb - About 1 hr to fix

                  Method warn_wrong_locales has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                        def warn_wrong_locales(source_locale, target_locales)
                          if target_locales.uniq != target_locales
                            duplicate_locale = target_locales.detect { |locale| target_locales.count(locale) > 1 }
                  
                            puts
                  Severity: Minor
                  Found in lib/translation_io/client/base_operation.rb - About 1 hr to fix

                    Method sort_by_project_locales_first has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                            def sort_by_project_locales_first(yaml_file_paths)
                              yaml_file_paths.sort do |x, y|
                                a = locale_file_path_in_project?(x)
                                b = locale_file_path_in_project?(y)
                                (!a && b) ? 1 : ((a && !b) ? -1 : 0)
                    Severity: Minor
                    Found in lib/translation_io/client/sync_operation/apply_yaml_source_edits_step.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 run has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                            def run(params)
                              TranslationIO.info "Downloading YAML source editions."
                    
                              params.merge!({ :timestamp => metadata_timestamp })
                              parsed_response = perform_source_edits_request(params)
                    Severity: Minor
                    Found in lib/translation_io/client/sync_operation/apply_yaml_source_edits_step.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 gsub_keys! has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                          def gsub_keys!(h, from_1, from_2, to_1, to_2)
                            if h.is_a?(Hash)
                              h.keys.each do |key|
                                if key.to_s.include?(from_1) || key.to_s.include?(from_2)
                                  new_key = key.to_s.gsub(from_1, to_1).gsub(from_2, to_2)
                    Severity: Minor
                    Found in lib/translation_io/flat_hash.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 metadata_timestamp has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                            def metadata_timestamp
                              if File.exist?(TranslationIO.config.metadata_path)
                                metadata_content = File.read(TranslationIO.config.metadata_path)
                    
                                # If any conflicts in file, take the lowest timestamp and potentially reapply some source edits
                    Severity: Minor
                    Found in lib/translation_io/client/sync_operation/apply_yaml_source_edits_step.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

                                  if no_key?(current_object, current_key)
                                    current_object[current_key] = {}
                                  end
                    Severity: Major
                    Found in lib/translation_io/flat_hash.rb - About 45 mins to fix
                      Severity
                      Category
                      Status
                      Source
                      Language