glitch-soc/mastodon

View on GitHub
app/javascript/flavours/glitch/components/status.jsx

Summary

Maintainability
F
1 wk
Test Coverage

File status.jsx has 683 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import PropTypes from 'prop-types';

import { injectIntl, FormattedMessage } from 'react-intl';

import classNames from 'classnames';
Severity: Major
Found in app/javascript/flavours/glitch/components/status.jsx - About 1 day to fix

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

      render () {
        const {
          parseClick,
          setCollapsed,
        } = this;
    Severity: Major
    Found in app/javascript/flavours/glitch/components/status.jsx - About 1 day to fix

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

        render () {
          const {
            parseClick,
            setCollapsed,
          } = this;
      Severity: Minor
      Found in app/javascript/flavours/glitch/components/status.jsx - About 6 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

      Status has 33 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Status extends ImmutablePureComponent {
      
        static contextType = SensitiveMediaContext;
      
        static propTypes = {
      Severity: Minor
      Found in app/javascript/flavours/glitch/components/status.jsx - About 4 hrs to fix

        Consider simplifying this complex logical expression.
        Open

            if (collapse ||
              autoCollapseSettings.get('all') ||
              (autoCollapseSettings.get('notifications') && muted) ||
              (autoCollapseSettings.get('lengthy') && node.clientHeight > autoCollapseHeight) ||
              (autoCollapseSettings.get('reblogs') && prepend === 'reblogged_by') ||
        Severity: Critical
        Found in app/javascript/flavours/glitch/components/status.jsx - About 3 hrs to fix

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

            static getDerivedStateFromProps(nextProps, prevState) {
              let update = {};
              let updated = false;
          
              // Make sure the state mirrors props we track…
          Severity: Minor
          Found in app/javascript/flavours/glitch/components/status.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 componentDidMount has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

            componentDidMount () {
              const { node } = this;
              const {
                status,
                settings,
          Severity: Minor
          Found in app/javascript/flavours/glitch/components/status.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 getDerivedStateFromProps has 42 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            static getDerivedStateFromProps(nextProps, prevState) {
              let update = {};
              let updated = false;
          
              // Make sure the state mirrors props we track…
          Severity: Minor
          Found in app/javascript/flavours/glitch/components/status.jsx - About 1 hr to fix

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

              componentDidMount () {
                const { node } = this;
                const {
                  status,
                  settings,
            Severity: Minor
            Found in app/javascript/flavours/glitch/components/status.jsx - About 1 hr to fix

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

                getSnapshotBeforeUpdate() {
                  if (!this.props.getScrollPosition) return null;
              
                  const { muted, hidden, status, settings } = this.props;
              
              
              Severity: Minor
              Found in app/javascript/flavours/glitch/components/status.jsx - 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

              Consider simplifying this complex logical expression.
              Open

                    } else if (attachments.getIn([0, 'type']) === 'video') {
                      const attachment = status.getIn(['media_attachments', 0]);
                      const description = attachment.getIn(['translation', 'description']) || attachment.get('description');
              
                      media.push(
              Severity: Major
              Found in app/javascript/flavours/glitch/components/status.jsx - About 40 mins to fix

                Function textForScreenReader has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                export const textForScreenReader = (intl, status, rebloggedByText = false, expanded = false) => {
                  const displayName = status.getIn(['account', 'display_name']);
                
                  const spoilerText = status.getIn(['translation', 'spoiler_text']) || status.get('spoiler_text');
                  const contentHtml = status.getIn(['translation', 'contentHtml']) || status.get('contentHtml');
                Severity: Minor
                Found in app/javascript/flavours/glitch/components/status.jsx - About 25 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

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

                          <Bundle fetchComponent={Audio} loading={this.renderLoadingAudioPlayer} >
                            {Component => (
                              <Component
                                src={attachment.get('url')}
                                alt={description}
                Severity: Major
                Found in app/javascript/flavours/glitch/components/status.jsx and 1 other location - About 1 day to fix
                app/javascript/mastodon/components/status.jsx on lines 464..485

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

                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

                    if (this.state.forceFilter === undefined ? matchedFilters : this.state.forceFilter) {
                      const minHandlers = this.props.muted ? {} : {
                        moveUp: this.handleHotkeyMoveUp,
                        moveDown: this.handleHotkeyMoveDown,
                      };
                Severity: Major
                Found in app/javascript/flavours/glitch/components/status.jsx and 1 other location - About 7 hrs to fix
                app/javascript/mastodon/components/status.jsx on lines 396..413

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

                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 ref={this.handleRef} className='status focusable' tabIndex={0}>
                            <span>{status.getIn(['account', 'display_name']) || status.getIn(['account', 'username'])}</span>
                            <span>{status.get('content')}</span>
                          </div>
                Severity: Major
                Found in app/javascript/flavours/glitch/components/status.jsx and 1 other location - About 1 hr to fix
                app/javascript/mastodon/components/status.jsx on lines 383..386

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

                            {(connectReply || connectUp || connectToRoot) && <div className={classNames('status__line', { 'status__line--full': connectReply, 'status__line--first': !status.get('in_reply_to_id') && !connectToRoot })} />}
                Severity: Major
                Found in app/javascript/flavours/glitch/components/status.jsx and 1 other location - About 1 hr to fix
                app/javascript/mastodon/components/status.jsx on lines 556..556

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

                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

                  handleHotkeyMoveDown = e => {
                    this.props.onMoveDown(this.props.containerId || this.props.id, e.target.getAttribute('data-featured'));
                  };
                Severity: Major
                Found in app/javascript/flavours/glitch/components/status.jsx and 1 other location - About 1 hr to fix
                app/javascript/flavours/glitch/components/status.jsx on lines 472..474

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

                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

                  handleHotkeyMoveUp = e => {
                    this.props.onMoveUp(this.props.containerId || this.props.id, e.target.getAttribute('data-featured'));
                  };
                Severity: Major
                Found in app/javascript/flavours/glitch/components/status.jsx and 1 other location - About 1 hr to fix
                app/javascript/flavours/glitch/components/status.jsx on lines 476..478

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

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

                  handleHotkeyOpenProfile = () => {
                    this.props.history.push(`/@${this.props.status.getIn(['account', 'acct'])}`);
                  };
                Severity: Major
                Found in app/javascript/flavours/glitch/components/status.jsx and 2 other locations - About 1 hr to fix
                app/javascript/flavours/glitch/features/status/index.jsx on lines 538..540
                app/javascript/mastodon/features/status/index.jsx on lines 501..503

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

                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 (status.get('reblog', null) !== null && typeof status.get('reblog') === 'object') {
                    status = status.get('reblog');
                  }
                Severity: Minor
                Found in app/javascript/flavours/glitch/components/status.jsx and 1 other location - About 55 mins to fix
                app/javascript/mastodon/components/status.jsx on lines 65..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 53.

                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 (this.props.settings.getIn(['content_warnings', 'shared_state'])) {
                      this.props.onToggleHidden(this.props.status);
                    } else if (this.props.status.get('spoiler_text')) {
                      this.setExpansion(!this.state.isExpanded);
                    }
                Severity: Minor
                Found in app/javascript/flavours/glitch/components/status.jsx and 1 other location - About 30 mins to fix
                app/javascript/flavours/glitch/features/status/index.jsx on lines 260..268

                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