src/commands/init/checkFolder.js

Summary

Maintainability
A
45 mins
Test Coverage

Function checkDirectory has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

export default async function checkDirectory(name = '', directory = '', { force = false } = {}) {
    const directoryPath = getAbsolutePath(name, directory) || directory;

    if (folderExists(directoryPath) && name) {
        log.warn(`Found a folder named ${chalk.underline(directoryPath)}, will try to use it.`);
Severity: Minor
Found in src/commands/init/checkFolder.js - About 45 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

Unexpected string concatenation.
Open

                name: 'Run anyway ' + chalk.yellow('Warning: Some files might be overwritten.'),
Severity: Minor
Found in src/commands/init/checkFolder.js by eslint

Suggest using template literals instead of string concatenation. (prefer-template)

In ES2015 (ES6), we can use template literals instead of string concatenation.

var str = "Hello, " + name + "!";
/*eslint-env es6*/

var str = `Hello, ${name}!`;

Rule Details

This rule is aimed to flag usage of + operators with strings.

Examples

Examples of incorrect code for this rule:

/*eslint prefer-template: "error"*/

var str = "Hello, " + name + "!";
var str = "Time: " + (12 * 60 * 60 * 1000);

Examples of correct code for this rule:

/*eslint prefer-template: "error"*/
/*eslint-env es6*/

var str = "Hello World!";
var str = `Hello, ${name}!`;
var str = `Time: ${12 * 60 * 60 * 1000}`;

// This is reported by `no-useless-concat`.
var str = "Hello, " + "World!";

When Not To Use It

This rule should not be used in ES3/5 environments.

In ES2015 (ES6) or later, if you don't want to be notified about string concatenation, you can safely disable this rule.

Related Rules

Redundant use of await on a return value.
Open

        return await askForDirectory(directory);
Severity: Minor
Found in src/commands/init/checkFolder.js by eslint

Disallows unnecessary return await (no-return-await)

Inside an async function, return await is useless. Since the return value of an async function is always wrapped in Promise.resolve, return await doesn't actually do anything except add extra time before the overarching Promise resolves or rejects. This pattern is almost certainly due to programmer ignorance of the return semantics of async functions.

Rule Details

This rule aims to prevent a likely common performance hazard due to a lack of understanding of the semantics of async function.

The following patterns are considered warnings:

async function foo() {
  return await bar();
}

The following patterns are not warnings:

async function foo() {
  return bar();
}

async function foo() {
  await bar();
  return;
}

async function foo() {
  const x = await bar();
  return x;
}

When Not To Use It

If you want to use await to denote a value that is a thenable, even when it is not necessary; or if you do not want the performance benefit of avoiding return await, you can turn off this rule.

Further Reading

async function on MDN Source: http://eslint.org/docs/rules/

Redundant use of await on a return value.
Open

            return await askForDirectory(directory);
Severity: Minor
Found in src/commands/init/checkFolder.js by eslint

Disallows unnecessary return await (no-return-await)

Inside an async function, return await is useless. Since the return value of an async function is always wrapped in Promise.resolve, return await doesn't actually do anything except add extra time before the overarching Promise resolves or rejects. This pattern is almost certainly due to programmer ignorance of the return semantics of async functions.

Rule Details

This rule aims to prevent a likely common performance hazard due to a lack of understanding of the semantics of async function.

The following patterns are considered warnings:

async function foo() {
  return await bar();
}

The following patterns are not warnings:

async function foo() {
  return bar();
}

async function foo() {
  await bar();
  return;
}

async function foo() {
  const x = await bar();
  return x;
}

When Not To Use It

If you want to use await to denote a value that is a thenable, even when it is not necessary; or if you do not want the performance benefit of avoiding return await, you can turn off this rule.

Further Reading

async function on MDN Source: http://eslint.org/docs/rules/

Redundant use of await on a return value.
Open

        return await askForDirectory(directory);
Severity: Minor
Found in src/commands/init/checkFolder.js by eslint

Disallows unnecessary return await (no-return-await)

Inside an async function, return await is useless. Since the return value of an async function is always wrapped in Promise.resolve, return await doesn't actually do anything except add extra time before the overarching Promise resolves or rejects. This pattern is almost certainly due to programmer ignorance of the return semantics of async functions.

Rule Details

This rule aims to prevent a likely common performance hazard due to a lack of understanding of the semantics of async function.

The following patterns are considered warnings:

async function foo() {
  return await bar();
}

The following patterns are not warnings:

async function foo() {
  return bar();
}

async function foo() {
  await bar();
  return;
}

async function foo() {
  const x = await bar();
  return x;
}

When Not To Use It

If you want to use await to denote a value that is a thenable, even when it is not necessary; or if you do not want the performance benefit of avoiding return await, you can turn off this rule.

Further Reading

async function on MDN Source: http://eslint.org/docs/rules/

There are no issues that match your filters.

Category
Status