huridocs/uwazi

View on GitHub
app/api/entities/entities.js

Summary

Maintainability
C
1 day
Test Coverage
A
95%

Function sanitize has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

function sanitize(doc, template) {
  if (!doc.metadata || !template) {
    return doc;
  }

Severity: Minor
Found in app/api/entities/entities.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 updateEntity has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

async function updateEntity(entity, _template, unrestricted = false) {
  const docLanguages = await this.getAllLanguages(entity.sharedId);

  if (
    docLanguages[0].template &&
Severity: Minor
Found in app/api/entities/entities.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

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

  async save(_doc, { user, language }, options = {}) {
    const { updateRelationships = true, index = true, includeDocuments = true } = options;
    await validateEntity(_doc);
    await saveSelections(_doc);
    const doc = _doc;
Severity: Minor
Found in app/api/entities/entities.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

Consider simplifying this complex logical expression.
Open

        if (entity && entity.template) {
          entity.metadata = entity.metadata || {};
          const template = _templates.find(t => t._id.toString() === entity.template.toString());

          const relationshipProperties = template.properties.filter(p => p.type === 'relationship');
Severity: Major
Found in app/api/entities/entities.js - About 40 mins to fix

    Function deleteFromMetadata has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      async deleteFromMetadata(deletedId, propertyContent, propTypes) {
        const includesRelationships = propTypes.includes(propertyTypes.relationship);
        const allTemplates = await templates.get({
          $or: [
            {
    Severity: Minor
    Found in app/api/entities/entities.js - About 25 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

    Function extendSelect has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    const extendSelect = select => {
      if (!select) {
        return select;
      }
      if (typeof select === 'string') {
    Severity: Minor
    Found in app/api/entities/entities.js - About 25 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

    Prefer named exports.
    Open

    export default {
    Severity: Minor
    Found in app/api/entities/entities.js by eslint

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

    Definition for rule 'node/no-restricted-import' was not found.
    Open

    /* eslint-disable max-lines */
    Severity: Minor
    Found in app/api/entities/entities.js by eslint

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

    There are no issues that match your filters.

    Category
    Status