locomotivecms/engine

View on GitHub

Showing 169 of 169 total issues

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

      <View
        title={i18n.t('views.pickers.assets.title')}
        subTitle={this.props.blockLabel || this.props.sectionLabel}
        onLeave={this.props.leaveView}
      >
app/javascript/src/locomotive/editor/views/pickers/images/index.js on lines 42..84

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

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

      def render_exception(exception)
        ::Locomotive.log "[ApplicationError] #{exception.inspect}"

        status = (case exception
        when ::Mongoid::Errors::DocumentNotFound  then 404
Severity: Minor
Found in app/controllers/locomotive/concerns/exception_controller.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 update_select_options has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def update_select_options(options)
      return nil if options.blank?

      default_locale      = field._parent.site.default_locale.to_sym
      include_new_options = false
Severity: Minor
Found in app/services/locomotive/custom_field_service.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 fetch_file has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def self.fetch_file(source)
      file = nil

      if source.is_a?(String) || source.is_a?(Hash) # simple string or drop
        source = source['url'] if source.is_a?(Hash)
Severity: Minor
Found in lib/locomotive/dragonfly.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 build_fullpath has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def build_fullpath
      if self.index_or_not_found?
        self.site.each_locale { |locale, current| self.fullpath = self.slug }
      else
        _parent = self.parent # do not hit the database more than once
Severity: Minor
Found in app/models/locomotive/page.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 underscore_keys has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def underscore_keys
    new_hash = {}

    self.each_pair do |key, value|
      if value.respond_to?(:collect!) # Array
Severity: Minor
Found in lib/locomotive/core_ext.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 find_content_type_of_model has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

        def find_content_type_of_model(content_type)
          value = :other

          self.class.content_types.each_pair do |type, rules|
            rules.each do |rule|
Severity: Minor
Found in lib/locomotive/carrierwave/asset.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

Function render has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  render() {
    const { pageId, iframeLoaded, location } = this.props;
    const currentKey      = iframeLoaded ? location.pathname : 'startup';
    const slideDirection  = !iframeLoaded ? 'up' : (location.state || {}).slideDirection || 'up';
    const timeout         = slideDirection === 'none' ? { enter: 1, exit: 1 } : { enter: 150, exit: 100 };
Severity: Minor
Found in app/javascript/src/locomotive/editor/views/action_bar/index.js - About 1 hr to fix

    Function render has 30 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      render() {
        const { sectionDefinition } = this.props;
    
        return (
          <div className="editor-section-blocks--new" ref={el => this.pickerRef = el}>

      Function render has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        render() {
          const { setting, getValue, label, handleChange } = this.props;
          const value = getValue(null);
          const asset = value && typeof(value) === 'object' ? value : { url: value };
      
      
      Severity: Minor
      Found in app/javascript/src/locomotive/editor/inputs/asset_picker.js - About 1 hr to fix

        Method _metafields_schema_schema has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def _metafields_schema_schema
                  {
                    'id' => 'http://locomotive.works/schemas/metafields.json',
                    'definitions' => {
                      'field' => {
        Severity: Minor
        Found in app/models/locomotive/concerns/site/metafields.rb - About 1 hr to fix

          Method to_json has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def to_json
                  add_authenticated_header
          
                  if get?
                    add_pagination_header if resource.respond_to?(:total_pages)
          Severity: Minor
          Found in lib/locomotive/action_controller/responder.rb - About 1 hr to fix

            Function build has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

            export const build = (pageId, contentEntryId, baseUrl) => {
              const _pageId       = compact([pageId, contentEntryId]).join('-');
              const basePath      = `/${_pageId}/content/edit`;
              const sectionsPath  = `${basePath}/sections`;
            
            
            Severity: Minor
            Found in app/javascript/src/locomotive/editor/services/routes_service.js - 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 attributes= has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                def attributes=(values)
                  return unless values
            
                  @_attributes = values # memoize them for the callbacks
            
            
            Severity: Minor
            Found in lib/locomotive/presentable.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 document_stamp has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                def document_stamp(document)
                  distance  = distance_of_time_in_words_to_now(document.updated_at)
                  update    = document.updated_at && document.updated_at != document.created_at
            
                  if account = (document.updated_by || document.created_by)
            Severity: Minor
            Found in app/helpers/locomotive/base_helper.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 as_json has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                def as_json(methods = nil)
                  methods ||= self.getters
                  {}.tap do |hash|
                    methods.each do |meth|
                      _options = self.property_options[meth]
            Severity: Minor
            Found in lib/locomotive/presentable.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

            Function render has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              render() {
                const TabPane = {
                  sections: Sections,
                  settings: Settings,
                  seo:      Seo
            Severity: Minor
            Found in app/javascript/src/locomotive/editor/views/action_bar/main.js - About 1 hr to fix

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

                      <TextInput
                        label={i18n.t('views.seo.meta_description_label')}
                        getValue={() => page.meta_description || ''}
                        handleChange={value => updatePageSetting('meta_description', value)}
                      />
              Severity: Major
              Found in app/javascript/src/locomotive/editor/views/seo/index.js and 1 other location - About 1 hr to fix
              app/javascript/src/locomotive/editor/views/seo/index.js on lines 15..19

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

              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

                      <TextInput
                        label={i18n.t('views.seo.title_label')}
                        getValue={() => page.seo_title || ''}
                        handleChange={value => updatePageSetting('seo_title', value)}
                      />
              Severity: Major
              Found in app/javascript/src/locomotive/editor/views/seo/index.js and 1 other location - About 1 hr to fix
              app/javascript/src/locomotive/editor/views/seo/index.js on lines 28..32

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

              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

              Function render has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                render() {
                  const { input, suggestions, loading } = this.state;
                  const inputProps = {
                    placeholder:  this.props.placeholder,
                    value:        input || '',
                Severity
                Category
                Status
                Source
                Language