mashirozx/mastodon

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

Summary

Maintainability
D
2 days
Test Coverage

ScrollableList has 27 functions (exceeds 20 allowed). Consider refactoring.
Open

export default @connect(mapStateToProps, null, null, { forwardRef: true })
class ScrollableList extends PureComponent {

  static contextTypes = {
    router: PropTypes.object,
Severity: Minor
Found in app/javascript/mastodon/components/scrollable_list.js - About 3 hrs to fix

    File scrollable_list.js has 295 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import React, { PureComponent } from 'react';
    import ScrollContainer from 'mastodon/containers/scroll_container';
    import PropTypes from 'prop-types';
    import IntersectionObserverArticleContainer from '../containers/intersection_observer_article_container';
    import LoadMore from './load_more';
    Severity: Minor
    Found in app/javascript/mastodon/components/scrollable_list.js - About 3 hrs to fix

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

        render () {
          const { children, scrollKey, trackScroll, showLoading, isLoading, hasMore, numPending, prepend, alwaysPrepend, append, emptyMessage, onLoadMore } = this.props;
          const { fullscreen } = this.state;
          const childrenCount = React.Children.count(children);
      
      
      Severity: Major
      Found in app/javascript/mastodon/components/scrollable_list.js - About 2 hrs to fix

        Consider simplifying this complex logical expression.
        Open

            } else if (isLoading || childrenCount > 0 || numPending > 0 || hasMore || !emptyMessage) {
              scrollableArea = (
                <div className={classNames('scrollable', { fullscreen })} ref={this.setRef} onMouseMove={this.handleMouseMove}>
                  <div role='feed' className='item-list'>
                    {prepend}
        Severity: Major
        Found in app/javascript/mastodon/components/scrollable_list.js - About 1 hr to fix

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

            render () {
              const { children, scrollKey, trackScroll, showLoading, isLoading, hasMore, numPending, prepend, alwaysPrepend, append, emptyMessage, onLoadMore } = this.props;
              const { fullscreen } = this.state;
              const childrenCount = React.Children.count(children);
          
          
          Severity: Minor
          Found in app/javascript/mastodon/components/scrollable_list.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

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

            getSnapshotBeforeUpdate (prevProps) {
              const someItemInserted = React.Children.count(prevProps.children) > 0 &&
                React.Children.count(prevProps.children) < React.Children.count(this.props.children) &&
                this.getFirstChildKey(prevProps) !== this.getFirstChildKey(this.props);
              const pendingChanged = (prevProps.numPending > 0) !== (this.props.numPending > 0);
          Severity: Minor
          Found in app/javascript/mastodon/components/scrollable_list.js - 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

            attachScrollListener () {
              if (this.props.bindToDocument) {
                document.addEventListener('scroll', this.handleScroll);
                document.addEventListener('wheel', this.handleWheel);
              } else {
          Severity: Major
          Found in app/javascript/mastodon/components/scrollable_list.js and 1 other location - About 3 hrs to fix
          app/javascript/mastodon/components/scrollable_list.js on lines 247..255

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

          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

            detachScrollListener () {
              if (this.props.bindToDocument) {
                document.removeEventListener('scroll', this.handleScroll);
                document.removeEventListener('wheel', this.handleWheel);
              } else {
          Severity: Major
          Found in app/javascript/mastodon/components/scrollable_list.js and 1 other location - About 3 hrs to fix
          app/javascript/mastodon/components/scrollable_list.js on lines 237..245

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

          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

              const { children, scrollKey, trackScroll, showLoading, isLoading, hasMore, numPending, prepend, alwaysPrepend, append, emptyMessage, onLoadMore } = this.props;
          Severity: Major
          Found in app/javascript/mastodon/components/scrollable_list.js and 2 other locations - About 1 hr to fix
          app/javascript/mastodon/features/account_timeline/index.js on lines 135..135
          app/javascript/mastodon/features/notifications/index.js on lines 178..178

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

          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