cozy-labs/cozy-desktop

View on GitHub
core/metadata.js

Summary

Maintainability
F
3 days
Test Coverage

File metadata.js has 589 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/** Metadata of synchronized files & directories.
 *
 * ### File
 *
 * - `_rev`: from PouchDB
Severity: Major
Found in core/metadata.js - About 1 day to fix

    Function makeComparator has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
    Open

    const makeComparator = (
      name /*: string */,
      { attributes } /*: { attributes?: Array<string> } */ = {}
    ) => {
      const interestingPaths = attributes && attributes.map(f => f.split('.'))
    Severity: Minor
    Found in core/metadata.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 fromRemoteFile has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function fromRemoteFile(remoteFile /*: MetadataRemoteFile */) /*: Metadata */ {
      const doc /*: Object */ = {
        docType: localDocType(remoteFile.type),
        path: pathUtils.remoteToLocal(remoteFile.path),
        size: parseInt(remoteFile.size, 10),
    Severity: Minor
    Found in core/metadata.js - About 1 hr to fix

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

      function removeNoteMetadata(doc /*: Metadata */) {
        if (doc.metadata) {
          if (doc.metadata.content) delete doc.metadata.content
          if (doc.metadata.schema) delete doc.metadata.schema
          if (doc.metadata.title) delete doc.metadata.title
      Severity: Minor
      Found in core/metadata.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

      Function invariants has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      function invariants /*:: <T: Metadata|SavedMetadata> */(doc /*: T */) {
        // If the record is meant to be erased we don't care about invariants
        if (doc._deleted) return doc
      
        let err
      Severity: Minor
      Found in core/metadata.js - About 35 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 detectSingleSide has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      function detectSingleSide(doc /*: Metadata */) /*: ?SideName */ {
        if (doc.sides) {
          for (const sideName of SIDE_NAMES) {
            if (doc.sides[sideName] && !doc.sides[otherSide(sideName)]) {
              return sideName
      Severity: Minor
      Found in core/metadata.js - About 35 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 too many return statements within this function.
      Open

            return [Number(lhs), Number(rhs)]
      Severity: Major
      Found in core/metadata.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

              return [Boolean(lhs), Boolean(rhs)]
        Severity: Major
        Found in core/metadata.js - About 30 mins to fix

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

          function dissociateLocal(doc /*: Metadata */) {
            if (doc.sides && doc.sides.local) delete doc.sides.local
            if (doc.local) delete doc.local
          }
          Severity: Major
          Found in core/metadata.js and 1 other location - About 1 hr to fix
          core/metadata.js on lines 505..508

          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

          function dissociateRemote(doc /*: Metadata */) {
            if (doc.sides && doc.sides.remote) delete doc.sides.remote
            if (doc.remote) delete doc.remote
          }
          Severity: Major
          Found in core/metadata.js and 1 other location - About 1 hr to fix
          core/metadata.js on lines 510..513

          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

          function isFile(
            doc /*: Metadata|MetadataLocalInfo|MetadataRemoteInfo */
          ) /*: boolean %checks */ {
            return doc.docType != null
              ? doc.docType === FILE
          Severity: Major
          Found in core/metadata.js and 1 other location - About 1 hr to fix
          core/metadata.js on lines 335..343

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

          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 isFolder(
            doc /*: Metadata|MetadataLocalInfo|MetadataRemoteInfo */
          ) /*: boolean %checks */ {
            return doc.docType != null
              ? doc.docType === FOLDER
          Severity: Major
          Found in core/metadata.js and 1 other location - About 1 hr to fix
          core/metadata.js on lines 325..333

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

          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 sameLocal = (() => {
            const comparator = makeComparator('sameLocal')
          
            return (one /*: MetadataLocalInfo */, two /*: MetadataLocalInfo */) =>
              comparator(one, two)
          Severity: Minor
          Found in core/metadata.js and 1 other location - About 50 mins to fix
          core/metadata.js on lines 731..736

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

          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 sameRemote = (() => {
            const comparator = makeComparator('sameRemote')
          
            return (one /*: MetadataRemoteInfo */, two /*: MetadataRemoteInfo */) =>
              comparator(one, two)
          Severity: Minor
          Found in core/metadata.js and 1 other location - About 50 mins to fix
          core/metadata.js on lines 723..728

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

          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

            for (const field of fields) {
              if (remoteDir[field]) {
                doc[field] = _.cloneDeep(remoteDir[field])
              }
            }
          Severity: Minor
          Found in core/metadata.js and 1 other location - About 35 mins to fix
          core/metadata.js on lines 316..320

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

          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

            for (const field of fields) {
              if (remoteFile[field]) {
                doc[field] = _.cloneDeep(remoteFile[field])
              }
            }
          Severity: Minor
          Found in core/metadata.js and 1 other location - About 35 mins to fix
          core/metadata.js on lines 282..286

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

          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

          There are no issues that match your filters.

          Category
          Status