wmakeev/moysklad

View on GitHub
src/methods/parseUrl.js

Summary

Maintainability
D
2 days
Test Coverage
A
100%

Function parseUrl has 40 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = function parseUrl(...args) {
  const { url, path } = have.strict(args, [
    { url: 'url' },
    { path: 'str or str arr' }
  ])
Severity: Minor
Found in src/methods/parseUrl.js - About 1 hr to fix

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

    module.exports = function parseUrl(...args) {
      const { url, path } = have.strict(args, [
        { url: 'url' },
        { path: 'str or str arr' }
      ])
    Severity: Minor
    Found in src/methods/parseUrl.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

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

    module.exports = function parseUrl(...args) {
      const { url, path } = have.strict(args, [
        { url: 'url' },
        { path: 'str or str arr' }
      ])
    Severity: Major
    Found in src/methods/parseUrl.js and 1 other location - About 2 days to fix
    bundle/umd/moysklad.js on lines 1182..1230

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

    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

    Insert ;
    Open

    const URL_REGEX = /^(https:\/\/.+\/api)\/(.+)\/(\d+\.\d+)\/([^?]+)(?:\?(.+))?$/
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Insert ;
    Open

        api = api_
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Replace 'string' with "string"
    Open

      } else if (typeof path === 'string') {
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Replace 'use·srict' with "use·srict";
    Open

    'use srict'
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Replace '../tools/normalizeUrl') with "../tools/normalizeUrl");
    Open

    const normalizeUrl = require('../tools/normalizeUrl')
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Insert ;
    Open

        pathStr = path
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Insert ;
    Open

        pathStr = path_
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Insert ;
    Open

        queryStr = query_
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Replace '../errors') with "../errors");
    Open

    const { MoyskladError } = require('../errors')
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Insert ;
    Open

        )
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Insert ;
    Open

      const isCalledOnInstance = !!(this && this.getOptions)
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Insert ;
    Open

    }
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Replace 'str·or·str·arr' with "str·or·str·arr"
    Open

        { path: 'str or str arr' }
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Insert ;
    Open

      }
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Replace '../have') with "../have");
    Open

    const have = require('../have')
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Replace '../tools/parseQueryString') with "../tools/parseQueryString");
    Open

    const parseQueryString = require('../tools/parseQueryString')
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Insert ;
    Open

        endpoint = endpoint_
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Insert ;
    Open

      ])
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Insert ;
    Open

        )
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Replace '' with "";
    Open

      let queryStr = ''
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Insert ;
    Open

        apiVersion = version_
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Replace 'url' with "url"
    Open

        { url: 'url' },
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Replace '/') with "/");
    Open

        pathStr = path.join('/')
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Insert ;
    Open

        : {}
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Replace '' with "";
    Open

      let pathStr = ''
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Replace 'Для·вызова·статического·метода·parseUrl,·необходимо·передать·url' with "Для·вызова·статического·метода·parseUrl,·необходимо·передать·url"
    Open

          'Для вызова статического метода parseUrl, необходимо передать url'
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Replace ⏎······URL_REGEX.exec(url)·||·[] with ·URL_REGEX.exec(⏎······url⏎····)·||·[];
    Open

        const [, endpoint_, api_, version_, path_, query_] =
    Severity: Minor
    Found in src/methods/parseUrl.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    There are no issues that match your filters.

    Category
    Status