metamaps/metamaps

View on GitHub
frontend/src/routes/MapView/index.js

Summary

Maintainability
A
2 hrs
Test Coverage

Arrow function should not return assignment.
Open

      {currentUser && <MapChat {...this.props} onOpen={onChatOpen} onClose={onChatClose} chatOpen={chatOpen} ref={x => this.mapChat = x} />}
Severity: Minor
Found in frontend/src/routes/MapView/index.js by eslint

Disallow Assignment in return Statement (no-return-assign)

One of the interesting, and sometimes confusing, aspects of JavaScript is that assignment can happen at almost any point. Because of this, an errant equals sign can end up causing assignment when the true intent was to do a comparison. This is especially true when using a return statement. For example:

function doSomething() {
    return foo = bar + 2;
}

It is difficult to tell the intent of the return statement here. It's possible that the function is meant to return the result of bar + 2, but then why is it assigning to foo? It's also possible that the intent was to use a comparison operator such as == and that this code is an error.

Because of this ambiguity, it's considered a best practice to not use assignment in return statements.

Rule Details

This rule aims to eliminate assignments from return statements. As such, it will warn whenever an assignment is found as part of return.

Options

The rule takes one option, a string, which must contain one of the following values:

  • except-parens (default): Disallow assignments unless they are enclosed in parentheses.
  • always: Disallow all assignments.

except-parens

This is the default option. It disallows assignments unless they are enclosed in parentheses.

Examples of incorrect code for the default "except-parens" option:

/*eslint no-return-assign: "error"*/

function doSomething() {
    return foo = bar + 2;
}

function doSomething() {
    return foo += 2;
}

Examples of correct code for the default "except-parens" option:

/*eslint no-return-assign: "error"*/

function doSomething() {
    return foo == bar + 2;
}

function doSomething() {
    return foo === bar + 2;
}

function doSomething() {
    return (foo = bar + 2);
}

always

This option disallows all assignments in return statements. All assignments are treated as problems.

Examples of incorrect code for the "always" option:

/*eslint no-return-assign: ["error", "always"]*/

function doSomething() {
    return foo = bar + 2;
}

function doSomething() {
    return foo += 2;
}

function doSomething() {
    return (foo = bar + 2);
}

Examples of correct code for the "always" option:

/*eslint no-return-assign: ["error", "always"]*/

function doSomething() {
    return foo == bar + 2;
}

function doSomething() {
    return foo === bar + 2;
}

When Not To Use It

If you want to allow the use of assignment operators in a return statement, then you can safely disable this rule. Source: http://eslint.org/docs/rules/

Arrow function should not return assignment.
Open

      <UpperOptions ref={x => this.upperOptions = x}
Severity: Minor
Found in frontend/src/routes/MapView/index.js by eslint

Disallow Assignment in return Statement (no-return-assign)

One of the interesting, and sometimes confusing, aspects of JavaScript is that assignment can happen at almost any point. Because of this, an errant equals sign can end up causing assignment when the true intent was to do a comparison. This is especially true when using a return statement. For example:

function doSomething() {
    return foo = bar + 2;
}

It is difficult to tell the intent of the return statement here. It's possible that the function is meant to return the result of bar + 2, but then why is it assigning to foo? It's also possible that the intent was to use a comparison operator such as == and that this code is an error.

Because of this ambiguity, it's considered a best practice to not use assignment in return statements.

Rule Details

This rule aims to eliminate assignments from return statements. As such, it will warn whenever an assignment is found as part of return.

Options

The rule takes one option, a string, which must contain one of the following values:

  • except-parens (default): Disallow assignments unless they are enclosed in parentheses.
  • always: Disallow all assignments.

except-parens

This is the default option. It disallows assignments unless they are enclosed in parentheses.

Examples of incorrect code for the default "except-parens" option:

/*eslint no-return-assign: "error"*/

function doSomething() {
    return foo = bar + 2;
}

function doSomething() {
    return foo += 2;
}

Examples of correct code for the default "except-parens" option:

/*eslint no-return-assign: "error"*/

function doSomething() {
    return foo == bar + 2;
}

function doSomething() {
    return foo === bar + 2;
}

function doSomething() {
    return (foo = bar + 2);
}

always

This option disallows all assignments in return statements. All assignments are treated as problems.

Examples of incorrect code for the "always" option:

/*eslint no-return-assign: ["error", "always"]*/

function doSomething() {
    return foo = bar + 2;
}

function doSomething() {
    return foo += 2;
}

function doSomething() {
    return (foo = bar + 2);
}

Examples of correct code for the "always" option:

/*eslint no-return-assign: ["error", "always"]*/

function doSomething() {
    return foo == bar + 2;
}

function doSomething() {
    return foo === bar + 2;
}

When Not To Use It

If you want to allow the use of assignment operators in a return statement, then you can safely disable this rule. Source: http://eslint.org/docs/rules/

TODO found
Open

    // TODO: stop using {...this.props} and make explicit
Severity: Minor
Found in frontend/src/routes/MapView/index.js by fixme

Block must not be padded by blank lines.
Open

export default class MapView extends Component {
Severity: Minor
Found in frontend/src/routes/MapView/index.js by eslint

require or disallow padding within blocks (padded-blocks)

Some style guides require block statements to start and end with blank lines. The goal is to improve readability by visually separating the block content and the surrounding code.

if (a) {

    b();

}

Since it's good to have a consistent code style, you should either always write padded blocks or never do it.

Rule Details

This rule enforces consistent empty line padding within blocks.

Options

This rule has one option, which can be a string option or an object option.

String option:

  • "always" (default) requires empty lines at the beginning and ending of block statements (except switch statements and classes)
  • "never" disallows empty lines at the beginning and ending of block statements (except switch statements and classes)

Object option:

  • "blocks" require or disallow padding within block statements
  • "classes" require or disallow padding within classes
  • "switches" require or disallow padding within switch statements

always

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

/*eslint padded-blocks: ["error", "always"]*/

if (a) {
    b();
}

if (a) { b(); }

if (a)
{
    b();
}

if (a) {

    b();
}

if (a) {
    b();

}

if (a) {
    // comment
    b();

}

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

/*eslint padded-blocks: ["error", "always"]*/

if (a) {

    b();

}

if (a)
{

    b();

}

if (a) {

    // comment
    b();

}

never

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

/*eslint padded-blocks: ["error", "never"]*/

if (a) {

    b();

}

if (a)
{

    b();

}

if (a) {

    b();
}

if (a) {
    b();

}

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

/*eslint padded-blocks: ["error", "never"]*/

if (a) {
    b();
}

if (a)
{
    b();
}

blocks

Examples of incorrect code for this rule with the { "blocks": "always" } option:

/*eslint padded-blocks: ["error", { "blocks": "always" }]*/

if (a) {
    b();
}

if (a) { b(); }

if (a)
{
    b();
}

if (a) {

    b();
}

if (a) {
    b();

}

if (a) {
    // comment
    b();

}

Examples of correct code for this rule with the { "blocks": "always" } option:

/*eslint padded-blocks: ["error", { "blocks": "always" }]*/

if (a) {

    b();

}

if (a)
{

    b();

}

if (a) {

    // comment
    b();

}

Examples of incorrect code for this rule with the { "blocks": "never" } option:

/*eslint padded-blocks: ["error", { "blocks": "never" }]*/

if (a) {

    b();

}

if (a)
{

    b();

}

if (a) {

    b();
}

if (a) {
    b();

}

Examples of correct code for this rule with the { "blocks": "never" } option:

/*eslint padded-blocks: ["error", { "blocks": "never" }]*/

if (a) {
    b();
}

if (a)
{
    b();
}

classes

Examples of incorrect code for this rule with the { "classes": "always" } option:

/*eslint padded-blocks: ["error", { "classes": "always" }]*/

class  A {
    constructor(){
    }
}

Examples of correct code for this rule with the { "classes": "always" } option:

/*eslint padded-blocks: ["error", { "classes": "always" }]*/

class  A {

    constructor(){
    }

}

Examples of incorrect code for this rule with the { "classes": "never" } option:

/*eslint padded-blocks: ["error", { "classes": "never" }]*/

class  A {

    constructor(){
    }

}

Examples of correct code for this rule with the { "classes": "never" } option:

/*eslint padded-blocks: ["error", { "classes": "never" }]*/

class  A {
    constructor(){
    }
}

switches

Examples of incorrect code for this rule with the { "switches": "always" } option:

/*eslint padded-blocks: ["error", { "switches": "always" }]*/

switch (a) {
    case 0: foo();
}

Examples of correct code for this rule with the { "switches": "always" } option:

/*eslint padded-blocks: ["error", { "switches": "always" }]*/

switch (a) {

    case 0: foo();

}

if (a) {
    b();
}

Examples of incorrect code for this rule with the { "switches": "never" } option:

/*eslint padded-blocks: ["error", { "switches": "never" }]*/

switch (a) {

    case 0: foo();

}

Examples of correct code for this rule with the { "switches": "never" } option:

/*eslint padded-blocks: ["error", { "switches": "never" }]*/

switch (a) {
    case 0: foo();
}

if (a) {

    b();

}

When Not To Use It

You can turn this rule off if you are not concerned with the consistency of padding within blocks. Source: http://eslint.org/docs/rules/

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

    }
Severity: Minor
Found in frontend/src/routes/MapView/index.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

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

  componentDidUpdate(prevProps) {
    const oldMapId = prevProps.mapId
    const { mapId, launchNewMap } = this.props
    if (!oldMapId && mapId) launchNewMap(mapId)
    else if (oldMapId && mapId && oldMapId !== mapId) {
Severity: Major
Found in frontend/src/routes/MapView/index.js and 1 other location - About 2 hrs to fix
frontend/src/routes/TopicView.js on lines 45..54

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

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