huridocs/uwazi

View on GitHub
app/react/Metadata/components/Metadata.js

Summary

Maintainability
A
3 hrs
Test Coverage
B
82%

Function showByType has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

export const showByType = ({ prop, templateId = '', useV2Player = false, compact = false }) => {
  let result = prop.value;

  switch (prop.type) {
    case null:
Severity: Minor
Found in app/react/Metadata/components/Metadata.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

Assignment to property of function parameter 'prop'.
Open

      prop.value = url;

title: no-param-reassign ruletype: suggestion furtherreading:

- https://spin.atomicobject.com/2011/04/10/javascript-don-t-reassign-your-function-arguments/

Assignment to variables declared as function parameters can be misleading and lead to confusing behavior, as modifying function parameters will also mutate the arguments object when not in strict mode (see When Not To Use It below). Often, assignment to function parameters is unintended and indicative of a mistake or programmer error.

This rule can be also configured to fail when function parameters are modified. Side effects on parameters can cause counter-intuitive execution flow and make errors difficult to track down.

Rule Details

This rule aims to prevent unintended behavior caused by modification or reassignment of function parameters.

Examples of incorrect code for this rule:

::: incorrect

/*eslint no-param-reassign: "error"*/

function foo(bar) {
    bar = 13;
}

function foo(bar) {
    bar++;
}

function foo(bar) {
    for (bar in baz) {}
}

function foo(bar) {
    for (bar of baz) {}
}

:::

Examples of correct code for this rule:

::: correct

/*eslint no-param-reassign: "error"*/

function foo(bar) {
    var baz = bar;
}

:::

Options

This rule takes one option, an object, with a boolean property "props", and arrays "ignorePropertyModificationsFor" and "ignorePropertyModificationsForRegex". "props" is false by default. If "props" is set to true, this rule warns against the modification of parameter properties unless they're included in "ignorePropertyModificationsFor" or "ignorePropertyModificationsForRegex", which is an empty array by default.

props

Examples of correct code for the default { "props": false } option:

::: correct

/*eslint no-param-reassign: ["error", { "props": false }]*/

function foo(bar) {
    bar.prop = "value";
}

function foo(bar) {
    delete bar.aaa;
}

function foo(bar) {
    bar.aaa++;
}

function foo(bar) {
    for (bar.aaa in baz) {}
}

function foo(bar) {
    for (bar.aaa of baz) {}
}

:::

Examples of incorrect code for the { "props": true } option:

::: incorrect

/*eslint no-param-reassign: ["error", { "props": true }]*/

function foo(bar) {
    bar.prop = "value";
}

function foo(bar) {
    delete bar.aaa;
}

function foo(bar) {
    bar.aaa++;
}

function foo(bar) {
    for (bar.aaa in baz) {}
}

function foo(bar) {
    for (bar.aaa of baz) {}
}

:::

Examples of correct code for the { "props": true } option with "ignorePropertyModificationsFor" set:

::: correct

/*eslint no-param-reassign: ["error", { "props": true, "ignorePropertyModificationsFor": ["bar"] }]*/

function foo(bar) {
    bar.prop = "value";
}

function foo(bar) {
    delete bar.aaa;
}

function foo(bar) {
    bar.aaa++;
}

function foo(bar) {
    for (bar.aaa in baz) {}
}

function foo(bar) {
    for (bar.aaa of baz) {}
}

:::

Examples of correct code for the { "props": true } option with "ignorePropertyModificationsForRegex" set:

::: correct

/*eslint no-param-reassign: ["error", { "props": true, "ignorePropertyModificationsForRegex": ["^bar"] }]*/

function foo(barVar) {
    barVar.prop = "value";
}

function foo(barrito) {
    delete barrito.aaa;
}

function foo(bar_) {
    bar_.aaa++;
}

function foo(barBaz) {
    for (barBaz.aaa in baz) {}
}

function foo(barBaz) {
    for (barBaz.aaa of baz) {}
}

:::

When Not To Use It

If you want to allow assignment to function parameters, then you can safely disable this rule.

Strict mode code doesn't sync indices of the arguments object with each parameter binding. Therefore, this rule is not necessary to protect against arguments object mutation in ESM modules or other strict mode functions. Source: http://eslint.org/docs/rules/

Assignment to property of function parameter 'prop'.
Open

        prop.fileName =

title: no-param-reassign ruletype: suggestion furtherreading:

- https://spin.atomicobject.com/2011/04/10/javascript-don-t-reassign-your-function-arguments/

Assignment to variables declared as function parameters can be misleading and lead to confusing behavior, as modifying function parameters will also mutate the arguments object when not in strict mode (see When Not To Use It below). Often, assignment to function parameters is unintended and indicative of a mistake or programmer error.

This rule can be also configured to fail when function parameters are modified. Side effects on parameters can cause counter-intuitive execution flow and make errors difficult to track down.

Rule Details

This rule aims to prevent unintended behavior caused by modification or reassignment of function parameters.

Examples of incorrect code for this rule:

::: incorrect

/*eslint no-param-reassign: "error"*/

function foo(bar) {
    bar = 13;
}

function foo(bar) {
    bar++;
}

function foo(bar) {
    for (bar in baz) {}
}

function foo(bar) {
    for (bar of baz) {}
}

:::

Examples of correct code for this rule:

::: correct

/*eslint no-param-reassign: "error"*/

function foo(bar) {
    var baz = bar;
}

:::

Options

This rule takes one option, an object, with a boolean property "props", and arrays "ignorePropertyModificationsFor" and "ignorePropertyModificationsForRegex". "props" is false by default. If "props" is set to true, this rule warns against the modification of parameter properties unless they're included in "ignorePropertyModificationsFor" or "ignorePropertyModificationsForRegex", which is an empty array by default.

props

Examples of correct code for the default { "props": false } option:

::: correct

/*eslint no-param-reassign: ["error", { "props": false }]*/

function foo(bar) {
    bar.prop = "value";
}

function foo(bar) {
    delete bar.aaa;
}

function foo(bar) {
    bar.aaa++;
}

function foo(bar) {
    for (bar.aaa in baz) {}
}

function foo(bar) {
    for (bar.aaa of baz) {}
}

:::

Examples of incorrect code for the { "props": true } option:

::: incorrect

/*eslint no-param-reassign: ["error", { "props": true }]*/

function foo(bar) {
    bar.prop = "value";
}

function foo(bar) {
    delete bar.aaa;
}

function foo(bar) {
    bar.aaa++;
}

function foo(bar) {
    for (bar.aaa in baz) {}
}

function foo(bar) {
    for (bar.aaa of baz) {}
}

:::

Examples of correct code for the { "props": true } option with "ignorePropertyModificationsFor" set:

::: correct

/*eslint no-param-reassign: ["error", { "props": true, "ignorePropertyModificationsFor": ["bar"] }]*/

function foo(bar) {
    bar.prop = "value";
}

function foo(bar) {
    delete bar.aaa;
}

function foo(bar) {
    bar.aaa++;
}

function foo(bar) {
    for (bar.aaa in baz) {}
}

function foo(bar) {
    for (bar.aaa of baz) {}
}

:::

Examples of correct code for the { "props": true } option with "ignorePropertyModificationsForRegex" set:

::: correct

/*eslint no-param-reassign: ["error", { "props": true, "ignorePropertyModificationsForRegex": ["^bar"] }]*/

function foo(barVar) {
    barVar.prop = "value";
}

function foo(barrito) {
    delete barrito.aaa;
}

function foo(bar_) {
    bar_.aaa++;
}

function foo(barBaz) {
    for (barBaz.aaa in baz) {}
}

function foo(barBaz) {
    for (barBaz.aaa of baz) {}
}

:::

When Not To Use It

If you want to allow assignment to function parameters, then you can safely disable this rule.

Strict mode code doesn't sync indices of the arguments object with each parameter binding. Therefore, this rule is not necessary to protect against arguments object mutation in ESM modules or other strict mode functions. Source: http://eslint.org/docs/rules/

Prefer named exports.
Open

export default Metadata;

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

Do not use Array index in keys
Open

        key={`${prop.name}_${index}`}

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 */

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

Prop type "array" is forbidden
Open

  attachments: PropTypes.array,

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

There are no issues that match your filters.

Category
Status