locomotivecms/wagon

View on GitHub

Showing 42 of 42 total issues

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

module.exports = merge(common, {
  plugins: [
    new OptimizeCssAssetsPlugin({
      assetNameRegExp: /\.css$/,
      cssProcessorOptions: { discardComments: { removeAll: true } }
Severity: Minor
Found in generators/webpack/app/assets/webpack.prod.js and 1 other location - About 50 mins to fix
generators/blank/app/assets/webpack.prod.js on lines 5..12

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

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

    def fetch_content_types(&block)
      api_client.content_types.all.each do |content_type|
        content_type.attributes['localized_names'] = content_type.fields.map { |f| f['localized'] ? f['name'] : nil }.compact
        content_type.attributes['urls_names'] = content_type.fields.map { |f| %w(file string text).include?(f['type']) ? f['name'] : nil }.compact
        yield(content_type)

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

    def select_options_yaml(options)
      return if options.blank?

      ordered_options = options.sort { |option| option['position'] }

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 scalar has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def scalar value, anchor, tag, plain, quoted, style
Severity: Minor
Found in lib/locomotive/wagon/tools/styled_yaml.rb - About 45 mins to fix

    Method list_templates has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

            def list_templates
              force_color_if_asked(options)
              require 'locomotive/wagon/generators/site'
              require File.expand_path(options[:lib]) if options[:lib]
              if Locomotive::Wagon::Generators::Site.empty?
    Severity: Minor
    Found in lib/locomotive/wagon/cli.rb - About 45 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 delete has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def self.delete(env, path, resource, slug, shell)
    Severity: Minor
    Found in lib/locomotive/wagon.rb - About 35 mins to fix

      Method push has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def push
            require 'haml'
      
            Locomotive::Wagon.require_misc_gems
      
      
      Severity: Minor
      Found in lib/locomotive/wagon/commands/push_command.rb - About 35 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 init has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

              def init(name, path = '.', *generator_options)
                force_color_if_asked(options)
                require 'locomotive/wagon/generators/site'
                require File.expand_path(options[:lib]) if options[:lib]
                generator = Locomotive::Wagon::Generators::Site.get(:blank)
      Severity: Minor
      Found in lib/locomotive/wagon/cli.rb - About 35 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_resource has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def each_resource
            RESOURCES.each do |name|
              next if !options[:resources].blank? && !options[:resources].include?(name)
      
              next if RESOURCES_WITH_CONTENT.include?(name) && !options[:data]
      Severity: Minor
      Found in lib/locomotive/wagon/commands/push_command.rb - About 35 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 yaml_attributes has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def yaml_attributes(content_type, entry)
            fields            = %w(_slug) + content_type.fields.map { |f| f['name'] } + %w(seo_title meta_description meta_keywords)
            localized_fields  = (content_type.attributes['localized_names'] || []) + %w(_slug seo_title meta_description meta_keywords)
      
            attributes = {}

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

          def _push(api_client)
            validate!
      
            content_assets_pusher = Locomotive::Wagon::PushContentAssetsCommand.new(api_client, steam_services)
      
      
      Severity: Minor
      Found in lib/locomotive/wagon/commands/push_command.rb - About 35 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 write_to_file has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def write_to_file(filepath, content = nil, mode = 'w+', &block)
            _filepath = File.join(path, filepath)
      
            folder = File.dirname(_filepath)
      
      
      Severity: Minor
      Found in lib/locomotive/wagon/commands/pull_sub_commands/pull_base_command.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 value_of has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def value_of(content_type, entry, locale, name)
            # attribute not translated
            return nil if entry[locale].nil?
      
            if value = entry[locale].attributes[name]

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

              def extra_blocks
                # build block settings
                _settings = settings.map do |raw_setting|
                  next unless raw_setting.starts_with?('block:') # block setting
                  _, block_type, id, type = raw_setting.split(':')
      Severity: Minor
      Found in lib/locomotive/wagon/generators/section.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 2 locations. Consider refactoring.
      Open

          def each_resource
            RESOURCES.each do |name|
              next if !options[:resources].blank? && !options[:resources].include?(name)
      
              klass = "Locomotive::Wagon::Pull#{name.camelcase}Command".constantize
      Severity: Minor
      Found in lib/locomotive/wagon/commands/pull_command.rb and 1 other location - About 25 mins to fix
      lib/locomotive/wagon/commands/sync_command.rb on lines 52..59

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

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

          def subscribe_to_notifications
            # Page not found
            ActiveSupport::Notifications.subscribe('steam.render.page_not_found') do |name, start, finish, id, payload|
              fullpath, locale, default_locale = payload[:path], payload[:locale], payload[:default_locale]
      
      
      Severity: Minor
      Found in lib/locomotive/wagon/commands/serve_command.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 transform has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def self.transform(hash, &block)
              return if hash.blank? || !hash.respond_to?(:has_key?)
      
              hash.each do |key, value|
                case value
      Severity: Minor
      Found in lib/locomotive/wagon/tools/yaml_ext.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 2 locations. Consider refactoring.
      Open

          def each_resource
            RESOURCES.each do |name|
              next if !options[:resources].blank? && !options[:resources].include?(name)
      
              klass = "Locomotive::Wagon::Sync#{name.camelcase}Command".constantize
      Severity: Minor
      Found in lib/locomotive/wagon/commands/sync_command.rb and 1 other location - About 25 mins to fix
      lib/locomotive/wagon/commands/pull_command.rb on lines 50..57

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

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

              def deploy(env, path = '.')
                force_color_if_asked(options)
      
                if check_path!(path)
                  begin
      Severity: Minor
      Found in lib/locomotive/wagon/cli.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_unique_filepath has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def find_unique_filepath(filepath, binary_file, index = 1)
            if File.exist?(filepath) && File.file?(filepath)
              # required because we need to make sure we use the content of file from its start
              binary_file.rewind
      
      

      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