mekanika/skematic

View on GitHub

Showing 45 of 45 total issues

Function _dive has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
Open

function _dive (skm, payload, opts, parentData) {
  // On the odd chance we reach here with no `skm` model defined
  if (!skm) return payload

  // Placeholder for formatted data
Severity: Minor
Found in src/format.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

Function _validate has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Open

function _validate (data, model, opts, parentData = {}) {
  let errs = {}

  // Validate scalars
  // Used by `_sparse()` to check scalar vals -- pass parentObj if exists
Severity: Minor
Found in src/validate/validate.js - About 5 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 checkValue has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
Open

module.exports = function checkValue (val, model, data, opts = {}) {
  let errs = []
  if (!model) return []

  //  1. Check null value status
Severity: Minor
Found in src/validate/checkValue.js - About 4 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 _generate has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

function _generate (gen, runOnce, value, data) {
  // Run immediately if `gen` is a function
  if (is.function(gen)) return gen.call(data, value)

  // Prepare the value to return
Severity: Minor
Found in src/compute.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 _makeValue has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

function _makeValue (data = {}, ss = {}, opts, val) {
  // Set defaults
  if (opts.defaults !== false) {
    if (!is.undefined(ss.default)) val = setDefault(val, ss)
  }
Severity: Minor
Found in src/format.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 convertNumber has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

function convertNumber (val, convertor, radix) {
  // Setup defaults
  convertor || (convertor = radix !== undefined ? parseInt : Number)
  radix || (radix = 10)

Severity: Minor
Found in src/plugins/typeconvert.js - About 2 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

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

function format (model, opts = {}) {
  return function SkematicFormat (ctx, next) {
    const data = ctx.request.body
    const out = Skematic.format(model, data, opts)
    ctx.state[opts.formatField || 'formatted'] = out
Severity: Major
Found in src/plugins/koaMiddleware.js and 1 other location - About 2 hrs to fix
src/plugins/koaMiddleware.js on lines 3..10

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

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

function validate (model, opts = {}) {
  return function SkematicValidate (ctx, next) {
    const data = ctx.request.body
    const out = Skematic.validate(model, data, opts)
    ctx.state[opts.validateField || 'validated'] = out
Severity: Major
Found in src/plugins/koaMiddleware.js and 1 other location - About 2 hrs to fix
src/plugins/koaMiddleware.js on lines 12..19

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

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

Function equal has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

  equal: (a, b) => {
    if (a === b) return true
    let i = -1

    if (is.array(a)) {
Severity: Minor
Found in src/is.js - About 2 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

pgSQL has 23 functions (exceeds 20 allowed). Consider refactoring.
Open

const pgSQL = {
  ARRAY: (t, opts) => typeToSQL(t.type, opts) + ' ARRAY',
  BOOLEAN: t => t.key,
  BYTEA: t => t.key,
  CHAR: t => 'CHAR' + (t.length ? `(${t.length})` : ''),
Severity: Minor
Found in src/plugins/toSQL.js - About 2 hrs to fix

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

    function format (model, opts = {}) {
      return function SkematicFormat (req, res, next) {
        const data = req.body
        const out = Skematic.format(model, data, opts)
        req[opts.formatField || 'formatted'] = out
    Severity: Major
    Found in src/plugins/connectMiddleware.js and 1 other location - About 2 hrs to fix
    src/plugins/connectMiddleware.js on lines 3..10

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

    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

    function validate (model, opts = {}) {
      return function SkematicValidate (req, res, next) {
        const data = req.body
        const out = Skematic.validate(model, data, opts)
        req[opts.validateField || 'validated'] = out
    Severity: Major
    Found in src/plugins/connectMiddleware.js and 1 other location - About 2 hrs to fix
    src/plugins/connectMiddleware.js on lines 12..19

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

    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

    Function _dive has 53 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function _dive (skm, payload, opts, parentData) {
      // On the odd chance we reach here with no `skm` model defined
      if (!skm) return payload
    
      // Placeholder for formatted data
    Severity: Major
    Found in src/format.js - About 2 hrs to fix

      Function _validate has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function _validate (data, model, opts, parentData = {}) {
        let errs = {}
      
        // Validate scalars
        // Used by `_sparse()` to check scalar vals -- pass parentObj if exists
      Severity: Minor
      Found in src/validate/validate.js - About 1 hr to fix

        Function checkValue has 45 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        module.exports = function checkValue (val, model, data, opts = {}) {
          let errs = []
          if (!model) return []
        
          //  1. Check null value status
        Severity: Minor
        Found in src/validate/checkValue.js - About 1 hr to fix

          Function createFrom has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

          function createFrom (model, nullValue) {
            let o = {}
          
            if (!model) return o
          
          
          Severity: Minor
          Found in src/format.js - About 1 hr 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 exports has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

          module.exports = function (v, model) {
            if (!model) return v
          
            const def = function (v, s) {
              // No default, return the value as is
          Severity: Minor
          Found in src/default.js - About 1 hr 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 toString has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

          function toString (val) {
            if (val === null) return val
          
            // Parse if value is not undefined
            if (val !== undefined) {
          Severity: Minor
          Found in src/plugins/typeconvert.js - About 1 hr 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 _generate has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function _generate (gen, runOnce, value, data) {
            // Run immediately if `gen` is a function
            if (is.function(gen)) return gen.call(data, value)
          
            // Prepare the value to return
          Severity: Minor
          Found in src/compute.js - About 1 hr to fix

            Function toDate has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

            function toDate (val) {
              if (val === undefined || val instanceof Array) {
                throw new Error('Failed to cast to Date')
              }
              if (val === null || val === '') return null
            Severity: Minor
            Found in src/plugins/typeconvert.js - About 1 hr 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

            Severity
            Category
            Status
            Source
            Language