metamaps/metamaps

View on GitHub
frontend/src/Metamaps/Topic.js

Summary

Maintainability
D
2 days
Test Coverage

File Topic.js has 350 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* global $ */

import $jit from '../patched/JIT'

import Active from './Active'
Severity: Minor
Found in frontend/src/Metamaps/Topic.js - About 4 hrs to fix

Function renderTopic has 104 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  renderTopic: function(mapping, topic, createNewInDB, permitCreateSynapseAfter, opts = {}) {
    var nodeOnViz, tempPos

    var newnode = topic.createNode()

Severity: Major
Found in frontend/src/Metamaps/Topic.js - About 4 hrs to fix

Function renderTopic has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

  renderTopic: function(mapping, topic, createNewInDB, permitCreateSynapseAfter, opts = {}) {
    var nodeOnViz, tempPos

    var newnode = topic.createNode()

Severity: Minor
Found in frontend/src/Metamaps/Topic.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 fetchSiblings has 54 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  fetchSiblings: function(nodes, metacodeId) {
    var self = this

    var node = Array.isArray(nodes) ? nodes[0] : nodes

Severity: Major
Found in frontend/src/Metamaps/Topic.js - About 2 hrs to fix

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

  launch: function(id) {
    var dataIsReadySetupTopic = function() {
      Visualize.type = 'RGraph'
      JIT.prepareVizData()
      Selected.reset()
Severity: Minor
Found in frontend/src/Metamaps/Topic.js - About 1 hr to fix

Function createTopicLocally has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  createTopicLocally: function() {
    var self = Topic

    if (Create.newTopic.name === '') {
      GlobalUI.notifyUser('Please enter a topic title...')
Severity: Minor
Found in frontend/src/Metamaps/Topic.js - About 1 hr to fix

Function renderTopic has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

  renderTopic: function(mapping, topic, createNewInDB, permitCreateSynapseAfter, opts = {}) {
Severity: Minor
Found in frontend/src/Metamaps/Topic.js - About 35 mins to fix

Closing curly brace does not appear on the same line as the subsequent block.
Open

    }
Severity: Minor
Found in frontend/src/Metamaps/Topic.js by eslint

Require Brace Style (brace-style)

Brace style is closely related to indent style in programming and describes the placement of braces relative to their control statement and body. There are probably a dozen, if not more, brace styles in the world.

The one true brace style is one of the most common brace styles in JavaScript, in which the opening brace of a block is placed on the same line as its corresponding statement or declaration. For example:

if (foo) {
  bar();
} else {
  baz();
}

One common variant of one true brace style is called Stroustrup, in which the else statements in an if-else construct, as well as catch and finally, must be on its own line after the preceding closing brace. For example:

if (foo) {
  bar();
}
else {
  baz();
}

Another style is called Allman, in which all the braces are expected to be on their own lines without any extra indentation. For example:

if (foo)
{
  bar();
}
else
{
  baz();
}

While no style is considered better than the other, most developers agree that having a consistent style throughout a project is important for its long-term maintainability.

Rule Details

This rule enforces consistent brace style for blocks.

Options

This rule has a string option:

  • "1tbs" (default) enforces one true brace style
  • "stroustrup" enforces Stroustrup style
  • "allman" enforces Allman style

This rule has an object option for an exception:

  • "allowSingleLine": true (default false) allows the opening and closing braces for a block to be on the same line

1tbs

Examples of incorrect code for this rule with the default "1tbs" option:

/*eslint brace-style: "error"*/

function foo()
{
  return true;
}

if (foo)
{
  bar();
}

try
{
  somethingRisky();
} catch(e)
{
  handleError();
}

if (foo) {
  bar();
}
else {
  baz();
}

Examples of correct code for this rule with the default "1tbs" option:

/*eslint brace-style: "error"*/

function foo() {
  return true;
}

if (foo) {
  bar();
}

if (foo) {
  bar();
} else {
  baz();
}

try {
  somethingRisky();
} catch(e) {
  handleError();
}

// when there are no braces, there are no problems
if (foo) bar();
else if (baz) boom();

Examples of correct code for this rule with the "1tbs", { "allowSingleLine": true } options:

/*eslint brace-style: ["error", "1tbs", { "allowSingleLine": true }]*/

function nop() { return; }

if (foo) { bar(); }

if (foo) { bar(); } else { baz(); }

try { somethingRisky(); } catch(e) { handleError(); }

stroustrup

Examples of incorrect code for this rule with the "stroustrup" option:

/*eslint brace-style: ["error", "stroustrup"]*/

function foo()
{
  return true;
}

if (foo)
{
  bar();
}

try
{
  somethingRisky();
} catch(e)
{
  handleError();
}

if (foo) {
  bar();
} else {
  baz();
}

Examples of correct code for this rule with the "stroustrup" option:

/*eslint brace-style: ["error", "stroustrup"]*/

function foo() {
  return true;
}

if (foo) {
  bar();
}

if (foo) {
  bar();
}
else {
  baz();
}

try {
  somethingRisky();
}
catch(e) {
  handleError();
}

// when there are no braces, there are no problems
if (foo) bar();
else if (baz) boom();

Examples of correct code for this rule with the "stroustrup", { "allowSingleLine": true } options:

/*eslint brace-style: ["error", "stroustrup", { "allowSingleLine": true }]*/

function nop() { return; }

if (foo) { bar(); }

if (foo) { bar(); }
else { baz(); }

try { somethingRisky(); }
catch(e) { handleError(); }

allman

Examples of incorrect code for this rule with the "allman" option:

/*eslint brace-style: ["error", "allman"]*/

function foo() {
  return true;
}

if (foo)
{
  bar(); }

try
{
  somethingRisky();
} catch(e)
{
  handleError();
}

if (foo) {
  bar();
} else {
  baz();
}

Examples of correct code for this rule with the "allman" option:

/*eslint brace-style: ["error", "allman"]*/

function foo()
{
  return true;
}

if (foo)
{
  bar();
}

if (foo)
{
  bar();
}
else
{
  baz();
}

try
{
  somethingRisky();
}
catch(e)
{
  handleError();
}

// when there are no braces, there are no problems
if (foo) bar();
else if (baz) boom();

Examples of correct code for this rule with the "allman", { "allowSingleLine": true } options:

/*eslint brace-style: ["error", "allman", { "allowSingleLine": true }]*/

function nop() { return; }

if (foo) { bar(); }

if (foo) { bar(); }
else { baz(); }

try { somethingRisky(); }
catch(e) { handleError(); }

When Not To Use It

If you don't want to enforce a particular brace style, don't enable this rule.

Further Reading

TODO found
Open

  // TODO: move createNewInDB and permitCreateSynapseAfter into opts
Severity: Minor
Found in frontend/src/Metamaps/Topic.js by fixme

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

  onTopicFollow: topic => {
    const isFollowing = topic.isFollowedBy(Active.Mapper)
    $.post({
      url: `/topics/${topic.id}/${isFollowing ? 'un' : ''}follow`
    })
Severity: Major
Found in frontend/src/Metamaps/Topic.js and 1 other location - About 3 hrs to fix
frontend/src/Metamaps/Views/ExploreMaps.js on lines 138..151

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

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

  get: function(id, callback = noOp) {
    // if the desired topic is not yet in the local topic repository, fetch it
    if (DataModel.Topics.get(id) === undefined) {
      $.ajax({
        url: '/topics/' + id + '.json',
Severity: Major
Found in frontend/src/Metamaps/Topic.js and 1 other location - About 3 hrs to fix
frontend/src/Metamaps/Synapse.js on lines 17..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 134.

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