ifmeorg/ifme

View on GitHub

Showing 74 of 128 total issues

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

      <div
        id="toast-notice"
        aria-label={showNotice ? I18n.t('alert_auto_hide') : ''}
        role="region"
        aria-live="polite"
Severity: Major
Found in client/app/components/Toast/index.jsx and 1 other location - About 1 hr to fix
client/app/components/Toast/index.jsx on lines 73..98

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

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

      <div
        id="toast-alert"
        aria-label={showAlert ? I18n.t('alert_auto_hide') : ''}
        role="alert"
        className={`${
Severity: Major
Found in client/app/components/Toast/index.jsx and 1 other location - About 1 hr to fix
client/app/components/Toast/index.jsx on lines 43..72

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

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

export const Toast = ({ alert, notice, appendDashboardClass }: Props): Node => {
  const [showAlert, setShowAlert] = useState<boolean>(
    alert !== null
      && alert !== ''
      && !document.documentElement?.hasAttribute('data-turbolinks-preview'),
Severity: Minor
Found in client/app/components/Toast/index.jsx - 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 useFocusTrap has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export const useFocusTrap = (
  ref: { current: null | HTMLElement },
  isOpen: boolean,
) => {
  const handleKeyDown = (e: any) => {
Severity: Minor
Found in client/app/hooks/useFocusTrap.js - About 1 hr to fix

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

      def page_title
        t('app_name') +
          if sign_in_path?
            ' | ' + t('account.sign_in')
          elsif join_path?
    Severity: Minor
    Found in app/helpers/application_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

    Function useFocusTrap has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    export const useFocusTrap = (
      ref: { current: null | HTMLElement },
      isOpen: boolean,
    ) => {
      const handleKeyDown = (e: any) => {
    Severity: Minor
    Found in client/app/hooks/useFocusTrap.js - 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

    Parsing error: Unexpected token (4:12)
    Open

    import type { Props as InputProps } from 'components/Input/utils';
    Severity: Minor
    Found in client/app/components/Form/utils.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Remove explicit presence validation for group_id.
    Open

                presence: true
    Severity: Minor
    Found in app/models/meeting.rb by rubocop

    Prefer string interpolation to string concatenation.
    Open

        t('shared.meeting_info.attending') +
          ' ' +
          link_to(
            t('common.actions.leave'),
            leave_meetings_path(meeting_id: id)
    Severity: Minor
    Found in app/helpers/meetings_helper.rb by rubocop

    Checks for places where string concatenation can be replaced with string interpolation.

    The cop can autocorrect simple cases but will skip autocorrecting more complex cases where the resulting code would be harder to read. In those cases, it might be useful to extract statements to local variables or methods which you can then interpolate in a string.

    NOTE: When concatenation between two strings is broken over multiple lines, this cop does not register an offense; instead, Style/LineEndConcatenation will pick up the offense if enabled.

    Two modes are supported: 1. aggressive style checks and corrects all occurrences of + where either the left or right side of + is a string literal. 2. conservative style on the other hand, checks and corrects only if left side (receiver of + method call) is a string literal. This is useful when the receiver is some expression that returns string like Pathname instead of a string literal.

    Safety:

    This cop is unsafe in aggressive mode, as it cannot be guaranteed that the receiver is actually a string, which can result in a false positive.

    Example: Mode: aggressive (default)

    # bad
    email_with_name = user.name + ' <' + user.email + '>'
    Pathname.new('/') + 'test'
    
    # good
    email_with_name = "#{user.name} <#{user.email}>"
    email_with_name = format('%s <%s>', user.name, user.email)
    "#{Pathname.new('/')}test"
    
    # accepted, line-end concatenation
    name = 'First' +
      'Last'

    Example: Mode: conservative

    # bad
    'Hello' + user.name
    
    # good
    "Hello #{user.name}"
    user.name + '!!'
    Pathname.new('/') + 'test'

    Prefer keyword arguments for arguments with a boolean default value; use required: false instead of required = false.
    Open

      def moment_text_input_props(field, type, label, required = false)
    Severity: Minor
    Found in app/helpers/moments_form_helper.rb by rubocop

    Checks for places where keyword arguments can be used instead of boolean arguments when defining methods. respond_to_missing? method is allowed by default. These are customizable with AllowedMethods option.

    Safety:

    This cop is unsafe because changing a method signature will implicitly change behavior.

    Example:

    # bad
    def some_method(bar = false)
      puts bar
    end
    
    # bad - common hack before keyword args were introduced
    def some_method(options = {})
      bar = options.fetch(:bar, false)
      puts bar
    end
    
    # good
    def some_method(bar: false)
      puts bar
    end

    Example: AllowedMethods: ['some_method']

    # good
    def some_method(bar = false)
      puts bar
    end

    Use atomic file operation method FileUtils.rm_f.
    Open

            File.delete(dr.file_path) if File.exist?(dr.file_path)
    Severity: Minor
    Found in app/models/user.rb by rubocop

    Checks for non-atomic file operation. And then replace it with a nearly equivalent and atomic method.

    These can cause problems that are difficult to reproduce, especially in cases of frequent file operations in parallel, such as test runs with parallel_rspec.

    For examples: creating a directory if there is none, has the following problems

    An exception occurs when the directory didn't exist at the time of exist?, but someone else created it before mkdir was executed.

    Subsequent processes are executed without the directory that should be there when the directory existed at the time of exist?, but someone else deleted it shortly afterwards.

    Safety:

    This cop is unsafe, because autocorrection change to atomic processing. The atomic processing of the replacement destination is not guaranteed to be strictly equivalent to that before the replacement.

    Example:

    # bad - race condition with another process may result in an error in `mkdir`
    unless Dir.exist?(path)
      FileUtils.mkdir(path)
    end
    
    # good - atomic and idempotent creation
    FileUtils.mkdir_p(path)
    
    # bad - race condition with another process may result in an error in `remove`
    if File.exist?(path)
      FileUtils.remove(path)
    end
    
    # good - atomic and idempotent removal
    FileUtils.rm_f(path)

    Parsing error: Unexpected token, expected "," (5:5)
    Open

      ref: { current: null | HTMLElement },
    Severity: Minor
    Found in client/app/hooks/useFocusTrap.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Convert if-elsif to case-when.
    Open

        if data_type == 'moods'
          item.moods.pluck(:id)
        elsif data_type == 'categories'
          item.categories.pluck(:id)
        elsif data_type == 'strategies'
    Severity: Minor
    Found in app/helpers/most_focus_helper.rb by rubocop

    Identifies places where if-elsif constructions can be replaced with case-when.

    Safety:

    This cop is unsafe. case statements use === for equality, so if the original conditional used a different equality operator, the behavior may be different.

    Example: MinBranchesCount: 3 (default)

    # bad
    if status == :active
      perform_action
    elsif status == :inactive || status == :hibernating
      check_timeout
    elsif status == :invalid
      report_invalid
    else
      final_action
    end
    
    # good
    case status
    when :active
      perform_action
    when :inactive, :hibernating
      check_timeout
    when :invalid
      report_invalid
    else
      final_action
    end

    Example: MinBranchesCount: 4

    # good
    if status == :active
      perform_action
    elsif status == :inactive || status == :hibernating
      check_timeout
    elsif status == :invalid
      report_invalid
    else
      final_action
    end

    Prefer keyword arguments for arguments with a boolean default value; use include_allies: false instead of include_allies = false.
    Open

      def get_stories(user, include_allies = false)
    Severity: Minor
    Found in app/helpers/stories_helper.rb by rubocop

    Checks for places where keyword arguments can be used instead of boolean arguments when defining methods. respond_to_missing? method is allowed by default. These are customizable with AllowedMethods option.

    Safety:

    This cop is unsafe because changing a method signature will implicitly change behavior.

    Example:

    # bad
    def some_method(bar = false)
      puts bar
    end
    
    # bad - common hack before keyword args were introduced
    def some_method(options = {})
      bar = options.fetch(:bar, false)
      puts bar
    end
    
    # good
    def some_method(bar: false)
      puts bar
    end

    Example: AllowedMethods: ['some_method']

    # good
    def some_method(bar = false)
      puts bar
    end

    Prefer keyword arguments for arguments with a boolean default value; use edit: false instead of edit = false.
    Open

      def strategy_form_inputs(strategy, viewers, edit = false)
    Severity: Minor
    Found in app/helpers/strategies_helper.rb by rubocop

    Checks for places where keyword arguments can be used instead of boolean arguments when defining methods. respond_to_missing? method is allowed by default. These are customizable with AllowedMethods option.

    Safety:

    This cop is unsafe because changing a method signature will implicitly change behavior.

    Example:

    # bad
    def some_method(bar = false)
      puts bar
    end
    
    # bad - common hack before keyword args were introduced
    def some_method(options = {})
      bar = options.fetch(:bar, false)
      puts bar
    end
    
    # good
    def some_method(bar: false)
      puts bar
    end

    Example: AllowedMethods: ['some_method']

    # good
    def some_method(bar = false)
      puts bar
    end

    Redundant all detected.
    Open

        objs = obj.where(user_id: data.user_id).all.order('created_at DESC')
    Severity: Minor
    Found in app/helpers/viewers_helper.rb by rubocop

    Parsing error: Missing semicolon. (5:4)
    Open

    type Options = {
    Severity: Minor
    Found in client/app/libs/i18n/index.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Prefer string interpolation to string concatenation.
    Open

            ' | ' + t('account.sign_in')
    Severity: Minor
    Found in app/helpers/application_helper.rb by rubocop

    Checks for places where string concatenation can be replaced with string interpolation.

    The cop can autocorrect simple cases but will skip autocorrecting more complex cases where the resulting code would be harder to read. In those cases, it might be useful to extract statements to local variables or methods which you can then interpolate in a string.

    NOTE: When concatenation between two strings is broken over multiple lines, this cop does not register an offense; instead, Style/LineEndConcatenation will pick up the offense if enabled.

    Two modes are supported: 1. aggressive style checks and corrects all occurrences of + where either the left or right side of + is a string literal. 2. conservative style on the other hand, checks and corrects only if left side (receiver of + method call) is a string literal. This is useful when the receiver is some expression that returns string like Pathname instead of a string literal.

    Safety:

    This cop is unsafe in aggressive mode, as it cannot be guaranteed that the receiver is actually a string, which can result in a false positive.

    Example: Mode: aggressive (default)

    # bad
    email_with_name = user.name + ' <' + user.email + '>'
    Pathname.new('/') + 'test'
    
    # good
    email_with_name = "#{user.name} <#{user.email}>"
    email_with_name = format('%s <%s>', user.name, user.email)
    "#{Pathname.new('/')}test"
    
    # accepted, line-end concatenation
    name = 'First' +
      'Last'

    Example: Mode: conservative

    # bad
    'Hello' + user.name
    
    # good
    "Hello #{user.name}"
    user.name + '!!'
    Pathname.new('/') + 'test'

    Rename is_checked to checked?.
    Open

      def is_checked(value)
    Severity: Minor
    Found in app/helpers/moments_helper.rb by rubocop

    Checks that predicate methods names end with a question mark and do not start with a forbidden prefix.

    A method is determined to be a predicate method if its name starts with one of the prefixes defined in the NamePrefix configuration. You can change what prefixes are considered by changing this option. Any method name that starts with one of these prefixes is required by the cop to end with a ?. Other methods can be allowed by adding to the AllowedMethods configuration.

    NOTE: The is_a? method is allowed by default.

    If ForbiddenPrefixes is set, methods that start with the configured prefixes will not be allowed and will be removed by autocorrection.

    In other words, if ForbiddenPrefixes is empty, a method named is_foo will register an offense only due to the lack of question mark (and will be autocorrected to is_foo?). If ForbiddenPrefixes contains is_, is_foo will register an offense both because the ? is missing and because of the is_ prefix, and will be corrected to foo?.

    NOTE: ForbiddenPrefixes is only applied to prefixes in NamePrefix; a prefix in the former but not the latter will not be considered by this cop.

    Example:

    # bad
    def is_even(value)
    end
    
    def is_even?(value)
    end
    
    # good
    def even?(value)
    end
    
    # bad
    def has_value
    end
    
    def has_value?
    end
    
    # good
    def value?
    end

    Example: AllowedMethods: ['is_a?'] (default)

    # good
    def is_a?(value)
    end

    Use filter_map instead.
    Open

                 .map(&:ally).compact.reject(&:banned)
    Severity: Minor
    Found in app/models/concerns/ally_concern.rb by rubocop
    Severity
    Category
    Status
    Source
    Language