maa123/mastodon

View on GitHub
app/javascript/mastodon/features/directory/components/account_card.jsx

Summary

Maintainability
F
6 days
Test Coverage

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

  render() {
    const { account, intl } = this.props;

    let actionBtn;

    Function mapDispatchToProps has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    const mapDispatchToProps = (dispatch, { intl }) => ({
      onFollow(account) {
        if (account.getIn(['relationship', 'following'])) {
          if (unfollowModal) {
            dispatch(

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

      render() {
        const { account, intl } = this.props;
    
        let actionBtn;
    
    

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

      onFollow(account) {
        if (account.getIn(['relationship', 'following'])) {
          if (unfollowModal) {
            dispatch(
              openModal({

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

        onFollow(account) {
          if (account.getIn(['relationship', 'following'])) {
            if (unfollowModal) {
              dispatch(
                openModal({
      app/javascript/mastodon/features/account_timeline/containers/header_container.jsx on lines 48..78

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

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

      const messages = defineMessages({
        unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
        follow: { id: 'account.follow', defaultMessage: 'Follow' },
        cancel_follow_request: { id: 'account.cancel_follow_request', defaultMessage: 'Withdraw follow request' },
        cancelFollowRequestConfirm: { id: 'confirmations.cancel_follow_request.confirm', defaultMessage: 'Withdraw request' },
      app/javascript/mastodon/components/account.jsx on lines 24..34
      app/javascript/mastodon/containers/status_container.jsx on lines 53..63
      app/javascript/mastodon/features/compose/components/poll_form.jsx on lines 15..25
      app/javascript/mastodon/features/compose/components/privacy_dropdown.jsx on lines 15..25
      app/javascript/mastodon/features/notifications/components/notification.jsx on lines 22..32
      app/javascript/mastodon/features/video/index.jsx on lines 18..28

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

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

        handleMouseLeave = ({ currentTarget }) => {
          if (autoPlayGif) {
            return;
          }
      
      
      app/javascript/mastodon/components/status_content.jsx on lines 141..152
      app/javascript/mastodon/components/status_content.jsx on lines 154..165
      app/javascript/mastodon/features/account/components/header.jsx on lines 132..143
      app/javascript/mastodon/features/account/components/header.jsx on lines 145..156
      app/javascript/mastodon/features/direct_timeline/components/conversation.jsx on lines 50..61
      app/javascript/mastodon/features/direct_timeline/components/conversation.jsx on lines 63..74
      app/javascript/mastodon/features/directory/components/account_card.jsx on lines 112..123
      app/javascript/mastodon/features/getting_started/components/announcements.jsx on lines 114..125
      app/javascript/mastodon/features/getting_started/components/announcements.jsx on lines 127..138

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

        handleMouseEnter = ({ currentTarget }) => {
          if (autoPlayGif) {
            return;
          }
      
      
      app/javascript/mastodon/components/status_content.jsx on lines 141..152
      app/javascript/mastodon/components/status_content.jsx on lines 154..165
      app/javascript/mastodon/features/account/components/header.jsx on lines 132..143
      app/javascript/mastodon/features/account/components/header.jsx on lines 145..156
      app/javascript/mastodon/features/direct_timeline/components/conversation.jsx on lines 50..61
      app/javascript/mastodon/features/direct_timeline/components/conversation.jsx on lines 63..74
      app/javascript/mastodon/features/directory/components/account_card.jsx on lines 125..136
      app/javascript/mastodon/features/getting_started/components/announcements.jsx on lines 114..125
      app/javascript/mastodon/features/getting_started/components/announcements.jsx on lines 127..138

      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

                  <div className='account-card__counters__item'>
                    <ShortNumber value={account.get('following_count')} />{' '}
                    <small>
                      <FormattedMessage
                        id='account.following'
      app/javascript/mastodon/features/directory/components/account_card.jsx on lines 211..219

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

      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 className='account-card__counters__item'>
                    <ShortNumber value={account.get('followers_count')} />{' '}
                    <small>
                      <FormattedMessage
                        id='account.followers'
      app/javascript/mastodon/features/directory/components/account_card.jsx on lines 221..229

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

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

        static propTypes = {
          account: ImmutablePropTypes.map.isRequired,
          intl: PropTypes.object.isRequired,
          onFollow: PropTypes.func.isRequired,
          onBlock: PropTypes.func.isRequired,
      app/javascript/mastodon/features/getting_started/components/announcements.jsx on lines 250..256
      app/javascript/mastodon/features/list_editor/components/search.jsx on lines 30..36
      app/javascript/mastodon/features/picture_in_picture/components/header.jsx on lines 25..31
      app/javascript/mastodon/features/ui/components/block_modal.jsx on lines 46..52
      app/javascript/mastodon/features/ui/components/compare_history_modal.jsx on lines 36..42

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

      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

                <div className='account-card__title'>
                  <div className='account-card__title__avatar'><Avatar account={account} size={56} /></div>
                  <DisplayName account={account} />
                </div>
      app/javascript/mastodon/features/list_adder/components/account.jsx on lines 32..35
      app/javascript/mastodon/features/list_editor/components/account.jsx on lines 64..67

      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

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

      const makeMapStateToProps = () => {
        const getAccount = makeGetAccount();
      
        const mapStateToProps = (state, { id }) => ({
          account: getAccount(state, id),
      app/javascript/mastodon/components/inline_account.jsx on lines 9..17
      app/javascript/mastodon/features/compose/containers/autosuggest_account_container.js on lines 6..14
      app/javascript/mastodon/features/list_adder/components/account.jsx on lines 11..19
      app/javascript/mastodon/features/ui/components/report_modal.jsx on lines 25..33

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

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

            } else if (account.getIn(['relationship', 'muting'])) {
              actionBtn = <Button  text={intl.formatMessage(messages.unmute)} onClick={this.handleMute} />;
            } else if (!account.getIn(['relationship', 'blocking'])) {
              actionBtn = <Button disabled={account.getIn(['relationship', 'blocked_by'])} className={classNames({ 'button--destructive': account.getIn(['relationship', 'following']) })} text={intl.formatMessage(account.getIn(['relationship', 'following']) ? messages.unfollow : messages.follow)} onClick={this.handleFollow} />;
            } else if (account.getIn(['relationship', 'blocking'])) {
      app/javascript/mastodon/components/account.jsx on lines 109..134
      app/javascript/mastodon/components/account.jsx on lines 111..134
      app/javascript/mastodon/components/account.jsx on lines 116..120
      app/javascript/mastodon/components/account.jsx on lines 128..134
      app/javascript/mastodon/components/account.jsx on lines 130..134
      app/javascript/mastodon/features/directory/components/account_card.jsx on lines 168..170

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

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

            } else if (account.getIn(['relationship', 'blocking'])) {
              actionBtn = <Button  text={intl.formatMessage(messages.unblock)} onClick={this.handleBlock} />;
            }
      app/javascript/mastodon/components/account.jsx on lines 109..134
      app/javascript/mastodon/components/account.jsx on lines 111..134
      app/javascript/mastodon/components/account.jsx on lines 116..120
      app/javascript/mastodon/components/account.jsx on lines 128..134
      app/javascript/mastodon/components/account.jsx on lines 130..134
      app/javascript/mastodon/features/directory/components/account_card.jsx on lines 164..170

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

      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

          if (me !== account.get('id')) {
            if (!account.get('relationship')) { // Wait until the relationship is loaded
              actionBtn = '';
            } else if (account.getIn(['relationship', 'requested'])) {
              actionBtn = <Button  text={intl.formatMessage(messages.cancel_follow_request)} title={intl.formatMessage(messages.requested)} onClick={this.handleFollow} />;
      app/javascript/mastodon/components/account.jsx on lines 116..120
      app/javascript/mastodon/features/account/components/header.jsx on lines 264..276

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

      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

        onMute(account) {
          if (account.getIn(['relationship', 'muting'])) {
            dispatch(unmuteAccount(account.get('id')));
          }
        },
      app/javascript/mastodon/features/directory/components/account_card.jsx on lines 88..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 46.

      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

        onBlock(account) {
          if (account.getIn(['relationship', 'blocking'])) {
            dispatch(unblockAccount(account.get('id')));
          }
        },
      app/javascript/mastodon/features/directory/components/account_card.jsx on lines 94..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 46.

      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