onejgordon/flow-dashboard

View on GitHub
src/js/components/HabitWidget.js

Summary

Maintainability
F
4 days
Test Coverage

Function render_habit has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring.
Open

  render_habit(h) {
    let {commitments, days} = this.props;
    let {habitdays, cancellable_habitday} = this.state;
    let cursor = new Date()
    let today = new Date()
Severity: Minor
Found in src/js/components/HabitWidget.js - About 1 day 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

File HabitWidget.js has 487 lines of code (exceeds 250 allowed). Consider refactoring.
Open

var React = require('react');
import { IconButton, IconMenu, MenuItem, Dialog,
  RaisedButton, TextField, FontIcon, FlatButton,
  Toggle } from 'material-ui';
var util = require('utils/util');
Severity: Minor
Found in src/js/components/HabitWidget.js - About 7 hrs to fix

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

      render() {
        let {habits, habitdays, editor_open, form, habit_analysis, working} = this.state;
        let no_habits = habits.length == 0;
        let _commit_bar, _progress_bar, table;
        let target = 0, done = 0, committed = 0, committed_done = 0;
    Severity: Major
    Found in src/js/components/HabitWidget.js - About 4 hrs to fix

      Function render_habit has 100 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        render_habit(h) {
          let {commitments, days} = this.props;
          let {habitdays, cancellable_habitday} = this.state;
          let cursor = new Date()
          let today = new Date()
      Severity: Major
      Found in src/js/components/HabitWidget.js - About 4 hrs to fix

        HabitWidget has 30 functions (exceeds 20 allowed). Consider refactoring.
        Open

        @changeHandler
        export default class HabitWidget extends React.Component {
        
          static propTypes = {
            days: PropTypes.number,
        Severity: Minor
        Found in src/js/components/HabitWidget.js - About 3 hrs to fix

          Function generate_habit_table has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            generate_habit_table() {
              let {habits} = this.state;
              let habit_rows = [];
              let target = 0, done = 0, committed = 0, committed_done = 0;
              habits.sort(this.name_sort.bind(this)).forEach((h) => {
          Severity: Minor
          Found in src/js/components/HabitWidget.js - About 1 hr to fix

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

                  <MenuItem key="gr" primaryText="Refresh" onClick={this.fetch_current.bind(this)} leftIcon={<FontIcon className="material-icons">refresh</FontIcon>} />
            Severity: Major
            Found in src/js/components/HabitWidget.js and 6 other locations - About 1 hr to fix
            src/js/components/HabitWidget.js on lines 432..432
            src/js/components/MiniJournalWidget.js on lines 352..352
            src/js/components/ProjectViewer.js on lines 247..247
            src/js/components/ReadWidget.js on lines 138..138
            src/js/components/ReadWidget.js on lines 139..139
            src/js/components/ReadWidget.js on lines 140..140

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

                if (this.count_habits() < AppConstants.HABIT_ACTIVE_LIMIT) menu_actions.push(<MenuItem key="new" primaryText="New Habit" onClick={this.show_creator.bind(this)} leftIcon={<FontIcon className="material-icons">add</FontIcon>} />)
            Severity: Major
            Found in src/js/components/HabitWidget.js and 6 other locations - About 1 hr to fix
            src/js/components/HabitWidget.js on lines 430..430
            src/js/components/MiniJournalWidget.js on lines 352..352
            src/js/components/ProjectViewer.js on lines 247..247
            src/js/components/ReadWidget.js on lines 138..138
            src/js/components/ReadWidget.js on lines 139..139
            src/js/components/ReadWidget.js on lines 140..140

            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

                            <TextField floatingLabelText="Habit name"
                                       name="name"
                                       value={form.name || ''}
                                       onChange={this.changeHandler.bind(this, 'form', 'name')}
                                       fullWidth autoFocus />
            Severity: Major
            Found in src/js/components/HabitWidget.js and 1 other location - About 1 hr to fix
            src/js/components/Reading.js on lines 252..252

            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

              select_habit_color(color) {
                let {form} = this.state;
                form.color = color.hex;
                this.setState({form});
              }
            Severity: Major
            Found in src/js/components/HabitWidget.js and 1 other location - About 1 hr to fix
            src/js/components/Timeline.js on lines 62..66

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

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

              set_new_habit_icon(ic) {
                let {form} = this.state;
                form.icon = ic;
                this.setState({form});
              }
            Severity: Major
            Found in src/js/components/HabitWidget.js and 3 other locations - About 40 mins to fix
            src/js/components/common/ReactJsonEditor.js on lines 68..72
            src/js/components/common/ReactJsonEditor.js on lines 74..78
            src/js/components/common/ReactJsonEditor.js on lines 80..84

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

            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