mashirozx/mastodon

View on GitHub
app/javascript/mastodon/components/status_content.js

Summary

Maintainability
F
4 days
Test Coverage

Function render has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

  render () {
    const { status, quote } = this.props;

    const hidden = this.props.onExpandedToggle ? !this.props.expanded : this.state.hidden;
    const renderReadMore = this.props.onClick && status.get('collapsed');
Severity: Minor
Found in app/javascript/mastodon/components/status_content.js - 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

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

  render () {
    const { status, quote } = this.props;

    const hidden = this.props.onExpandedToggle ? !this.props.expanded : this.state.hidden;
    const renderReadMore = this.props.onClick && status.get('collapsed');
Severity: Major
Found in app/javascript/mastodon/components/status_content.js - About 3 hrs to fix

    Function _updateStatusLinks has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

      _updateStatusLinks () {
        const node = this.node;
    
        if (!node) {
          return;
    Severity: Minor
    Found in app/javascript/mastodon/components/status_content.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

    Function _updateStatusLinks has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      _updateStatusLinks () {
        const node = this.node;
    
        if (!node) {
          return;
    Severity: Minor
    Found in app/javascript/mastodon/components/status_content.js - About 1 hr to fix

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

        onHashtagClick = (hashtag, e) => {
          hashtag = hashtag.replace(/^#/, '');
      
          if (this.context.router && e.button === 0 && !(e.ctrlKey || e.metaKey)) {
            e.preventDefault();
      Severity: Major
      Found in app/javascript/mastodon/components/status_content.js and 1 other location - About 4 hrs to fix
      app/javascript/mastodon/features/getting_started/components/announcements.js on lines 94..101

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

      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

        onMentionClick = (mention, e) => {
          if (this.context.router && e.button === 0 && !(e.ctrlKey || e.metaKey)) {
            e.preventDefault();
            this.context.router.history.push(`/@${mention.get('acct')}`);
          }
      Severity: Major
      Found in app/javascript/mastodon/components/status_content.js and 1 other location - About 3 hrs to fix
      app/javascript/mastodon/features/getting_started/components/announcements.js on lines 87..92

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

      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 12 locations. Consider refactoring.
      Open

        handleMouseEnter = ({ currentTarget }) => {
          if (autoPlayGif) {
            return;
          }
      
      
      Severity: Major
      Found in app/javascript/mastodon/components/status_content.js and 11 other locations - About 3 hrs to fix
      app/javascript/mastodon/components/display_name.js on lines 14..25
      app/javascript/mastodon/components/display_name.js on lines 27..38
      app/javascript/mastodon/components/status_content.js on lines 93..104
      app/javascript/mastodon/features/account/components/header.js on lines 105..116
      app/javascript/mastodon/features/account/components/header.js on lines 118..129
      app/javascript/mastodon/features/direct_timeline/components/conversation.js on lines 47..58
      app/javascript/mastodon/features/direct_timeline/components/conversation.js on lines 60..71
      app/javascript/mastodon/features/directory/components/account_card.js on lines 99..110
      app/javascript/mastodon/features/directory/components/account_card.js on lines 112..123
      app/javascript/mastodon/features/getting_started/components/announcements.js on lines 110..121
      app/javascript/mastodon/features/getting_started/components/announcements.js on lines 123..134

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

      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 12 locations. Consider refactoring.
      Open

        handleMouseLeave = ({ currentTarget }) => {
          if (autoPlayGif) {
            return;
          }
      
      
      Severity: Major
      Found in app/javascript/mastodon/components/status_content.js and 11 other locations - About 3 hrs to fix
      app/javascript/mastodon/components/display_name.js on lines 14..25
      app/javascript/mastodon/components/display_name.js on lines 27..38
      app/javascript/mastodon/components/status_content.js on lines 80..91
      app/javascript/mastodon/features/account/components/header.js on lines 105..116
      app/javascript/mastodon/features/account/components/header.js on lines 118..129
      app/javascript/mastodon/features/direct_timeline/components/conversation.js on lines 47..58
      app/javascript/mastodon/features/direct_timeline/components/conversation.js on lines 60..71
      app/javascript/mastodon/features/directory/components/account_card.js on lines 99..110
      app/javascript/mastodon/features/directory/components/account_card.js on lines 112..123
      app/javascript/mastodon/features/getting_started/components/announcements.js on lines 110..121
      app/javascript/mastodon/features/getting_started/components/announcements.js on lines 123..134

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

      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

          const readMoreButton = (
            <button className='status__content__read-more-button' onClick={this.props.onClick} key='read-more'>
              <FormattedMessage id='status.read_more' defaultMessage='Read more' /><Icon id='angle-right' fixedWidth />
            </button>
          );
      Severity: Major
      Found in app/javascript/mastodon/components/status_content.js and 1 other location - About 2 hrs to fix
      app/javascript/mastodon/components/status_content.js on lines 212..216

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

      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

          const showPollButton = (
            <button className='status__content__read-more-button' onClick={this.props.onClick} key='show-poll'>
              <FormattedMessage id='status.show_poll' defaultMessage='Show poll' /><Icon id='angle-right' fixedWidth />
            </button>
          );
      Severity: Major
      Found in app/javascript/mastodon/components/status_content.js and 1 other location - About 2 hrs to fix
      app/javascript/mastodon/components/status_content.js on lines 206..210

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

      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

            } else if (link.textContent[0] === '#' || (link.previousSibling && link.previousSibling.textContent && link.previousSibling.textContent[link.previousSibling.textContent.length - 1] === '#')) {
              link.addEventListener('click', this.onHashtagClick.bind(this, link.text), false);
            } else {
              link.setAttribute('title', link.href);
              link.classList.add('unhandled-link');
      Severity: Major
      Found in app/javascript/mastodon/components/status_content.js and 1 other location - About 1 hr to fix
      app/javascript/mastodon/features/getting_started/components/announcements.js on lines 71..80

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

      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

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

              <div className={classNames} ref={this.setRef} tabIndex='0' onMouseEnter={this.handleMouseEnter} onMouseLeave={this.handleMouseLeave}>
                <div className='status__content__text status__content__text--visible translate' lang={lang} dangerouslySetInnerHTML={content} />
      
                <StatusTranslation status={status} />
      
      
      Severity: Major
      Found in app/javascript/mastodon/components/status_content.js and 1 other location - About 1 hr to fix
      app/javascript/mastodon/components/status_content.js on lines 258..266

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

      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

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

              <div className={classNames} ref={this.setRef} tabIndex='0' onMouseDown={this.handleMouseDown} onMouseUp={this.handleMouseUp} key='status-content' onMouseEnter={this.handleMouseEnter} onMouseLeave={this.handleMouseLeave}>
                <div className='status__content__text status__content__text--visible translate' lang={lang} dangerouslySetInnerHTML={content} />
      
                <StatusTranslation status={status} />
      
      
      Severity: Major
      Found in app/javascript/mastodon/components/status_content.js and 1 other location - About 1 hr to fix
      app/javascript/mastodon/components/status_content.js on lines 276..284

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

      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 3 locations. Consider refactoring.
      Open

            let mention = this.props.status.get('mentions').find(item => link.href === item.get('url'));
      Severity: Major
      Found in app/javascript/mastodon/components/status_content.js and 2 other locations - About 50 mins to fix
      app/javascript/mastodon/features/getting_started/components/announcements.js on lines 66..66
      app/javascript/mastodon/features/getting_started/components/announcements.js on lines 74..74

      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

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

            if (mention) {
              link.addEventListener('click', this.onMentionClick.bind(this, mention), false);
              link.setAttribute('title', mention.get('acct'));
            } else if (link.textContent[0] === '#' || (link.previousSibling && link.previousSibling.textContent && link.previousSibling.textContent[link.previousSibling.textContent.length - 1] === '#')) {
              link.addEventListener('click', this.onHashtagClick.bind(this, link.text), false);
      Severity: Minor
      Found in app/javascript/mastodon/components/status_content.js and 1 other location - About 45 mins to fix
      app/javascript/mastodon/features/getting_started/components/announcements.js on lines 68..80

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

      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

            const toggleText = hidden ? <FormattedMessage id='status.show_more' defaultMessage='Show more' /> : <FormattedMessage id='status.show_less' defaultMessage='Show less' />;
      Severity: Minor
      Found in app/javascript/mastodon/components/status_content.js and 1 other location - About 30 mins to fix
      app/javascript/mastodon/features/compose/components/search.js on lines 22..22

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

      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