makeomatic/ms-files

View on GitHub
src/actions/list.js

Summary

Maintainability
F
5 days
Test Coverage

Function redisSearch has a Cognitive Complexity of 67 (exceeds 5 allowed). Consider refactoring.
Open

async function redisSearch(ctx) {
  // 1. build query
  const indexName = `${ctx.service.config.redis.options.keyPrefix}:${FILES_LIST_SEARCH}`;
  const args = ['FT.SEARCH', indexName];
  const query = [];
Severity: Minor
Found in src/actions/list.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

File list.js has 489 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const { ActionTransport } = require('@microfleet/plugin-router');
const Promise = require('bluebird');
const fsort = require('redis-filtered-sort');
const perf = require('ms-perf');
const { HttpStatusError, NotImplementedError } = require('common-errors');
Severity: Minor
Found in src/actions/list.js - About 7 hrs to fix

    Function redisSearch has 123 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    async function redisSearch(ctx) {
      // 1. build query
      const indexName = `${ctx.service.config.redis.options.keyPrefix}:${FILES_LIST_SEARCH}`;
      const args = ['FT.SEARCH', indexName];
      const query = [];
    Severity: Major
    Found in src/actions/list.js - About 4 hrs to fix

      Function interstore has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

      async function interstore(ctx) {
        const { isPublic, temp, tags, redis, hasTags, uploadedAt, order, maxInterval, username, modelType } = ctx;
      
        if (modelType === 'nft') {
          throw new NotImplementedError('nft filter is unavailable');
      Severity: Minor
      Found in src/actions/list.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 interstore has 97 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      async function interstore(ctx) {
        const { isPublic, temp, tags, redis, hasTags, uploadedAt, order, maxInterval, username, modelType } = ctx;
      
        if (modelType === 'nft') {
          throw new NotImplementedError('nft filter is unavailable');
      Severity: Major
      Found in src/actions/list.js - About 3 hrs to fix

        Function listFiles has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

        async function listFiles({ params }) {
          const timer = perf('list', { thunk: false });
        
          const {
            redis,
        Severity: Minor
        Found in src/actions/list.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

        Avoid deeply nested control flow statements.
        Open

            } else if (actionTypeOrValue.eq) {
              query.push(`@${propName}:{ $f_${propName}_eq }`);
              params.push(`f_${propName}_eq`, actionTypeOrValue.eq);
            } else if (actionTypeOrValue.ne) {
              query.push(`-@${propName}:{ $f_${propName}_ne }`);
        Severity: Major
        Found in src/actions/list.js - About 45 mins to fix

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

          const numericQueryRange = (actionTypeOrValue) => {
            // eslint-disable-next-line no-nested-ternary
            const lowerRange = actionTypeOrValue.gte || actionTypeOrValue.gt
              ? (
                actionTypeOrValue.gte
          Severity: Minor
          Found in src/actions/list.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

          Avoid deeply nested control flow statements.
          Open

                if (numericProps.includes(propName)) {
                  query.push(`-@${propName}:[-inf +inf]`);
                } else {
                  query.push(`@${propName}:""`);
                }
          Severity: Major
          Found in src/actions/list.js - About 45 mins to fix

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

                } else if (actionTypeOrValue.exists !== undefined) {
                  if (numericProps.includes(propName)) {
                    query.push(`@${propName}:[-inf +inf]`);
                  } else {
                    query.push(`-@${propName}:""`);
            Severity: Major
            Found in src/actions/list.js and 1 other location - About 1 hr to fix
            src/actions/list.js on lines 431..461

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

            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

                } else if (actionTypeOrValue.isempty !== undefined) {
                  if (numericProps.includes(propName)) {
                    query.push(`-@${propName}:[-inf +inf]`);
                  } else {
                    query.push(`@${propName}:""`);
            Severity: Major
            Found in src/actions/list.js and 1 other location - About 1 hr to fix
            src/actions/list.js on lines 425..461

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

            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

              const upperRange = actionTypeOrValue.lte || actionTypeOrValue.lt
                ? (
                  actionTypeOrValue.lte
                    ? `${actionTypeOrValue.lte}`
                    : `(${actionTypeOrValue.lt}`
            Severity: Major
            Found in src/actions/list.js and 1 other location - About 1 hr to fix
            src/actions/list.js on lines 62..68

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

            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

              const lowerRange = actionTypeOrValue.gte || actionTypeOrValue.gt
                ? (
                  actionTypeOrValue.gte
                    ? `${actionTypeOrValue.gte}`
                    : `(${actionTypeOrValue.gt}`
            Severity: Major
            Found in src/actions/list.js and 1 other location - About 1 hr to fix
            src/actions/list.js on lines 70..76

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

            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

              const { isPublic, temp, tags, redis, hasTags, uploadedAt, order, maxInterval, username, modelType } = ctx;
            Severity: Major
            Found in src/actions/list.js and 1 other location - About 1 hr to fix
            src/actions/upload.js on lines 52..63

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

            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

                } else if (actionTypeOrValue.eq) {
                  query.push(`@${propName}:{ $f_${propName}_eq }`);
                  params.push(`f_${propName}_eq`, actionTypeOrValue.eq);
                } else if (actionTypeOrValue.ne) {
                  query.push(`-@${propName}:{ $f_${propName}_ne }`);
            Severity: Minor
            Found in src/actions/list.js and 1 other location - About 55 mins to fix
            src/actions/list.js on lines 440..461

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

            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

                } else if (actionTypeOrValue.ne) {
                  query.push(`-@${propName}:{ $f_${propName}_ne }`);
                  params.push(`f_${propName}_ne`, actionTypeOrValue.ne);
                } else if (actionTypeOrValue.match) {
                  const varName = `f_${propName.replace(/\|/g, '_')}_m`;
            Severity: Minor
            Found in src/actions/list.js and 1 other location - About 55 mins to fix
            src/actions/list.js on lines 437..461

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

            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

                  if (ctx.nftOwner) {
                    // only wallet match
                    nftOwnerMatch = `(@${FILES_NFT_OWNER_FIELD}:{ $nftOwner }) @${FILES_HAS_NFT_OWNER_FIELD}:[1 1]`;
                    params.push('nftOwner', ctx.nftOwner);
                  }
            Severity: Minor
            Found in src/actions/list.js and 1 other location - About 40 mins to fix
            src/actions/list.js on lines 381..385

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

            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

                  if (ctx.username) {
                    // owner and empty wallet
                    ownerMatch = `(@${FILES_OWNER_FIELD}:{ $username } -@${FILES_HAS_NFT_OWNER_FIELD}:[1 1])`;
                    params.push('username', ctx.username);
                  }
            Severity: Minor
            Found in src/actions/list.js and 1 other location - About 40 mins to fix
            src/actions/list.js on lines 387..391

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

            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

              const {
                redis,
                criteria,
                order,
                strFilter,
            Severity: Minor
            Found in src/actions/list.js and 1 other location - About 35 mins to fix
            src/utils/reference.js on lines 59..69

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

            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

            Parsing error: The keyword 'const' is reserved
            Open

            const { ActionTransport } = require('@microfleet/plugin-router');
            Severity: Minor
            Found in src/actions/list.js by eslint

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

            There are no issues that match your filters.

            Category
            Status