cozy-labs/cozy-desktop

View on GitHub
core/local/channel_watcher/initial_diff.js

Summary

Maintainability
F
3 days
Test Coverage

Function initialDiff has a Cognitive Complexity of 59 (exceeds 5 allowed). Consider refactoring.
Open

async function initialDiff(
  channel /*: Channel */,
  out /*: Channel */,
  { config, state } /*: { config: Config, state: InitialDiffState } */
) /*: Promise<void> */ {
Severity: Minor
Found in core/local/channel_watcher/initial_diff.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 debounce has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

function debounce(waiting /*: WaitingItem[] */, events /*: ChannelEvent[] */) {
  for (let i = 0; i < events.length; i++) {
    const event = events[i]
    if (event.incomplete) {
      continue
Severity: Minor
Found in core/local/channel_watcher/initial_diff.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

File initial_diff.js has 261 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/** This step handle the events of the ChannelWatcher initial scan.
 *
 * Some files and directories can have been deleted while cozy-desktop was
 * stopped. So, at the end of the initial scan, we have to do a diff between
 * what was in pouchdb and the events from the local watcher to find what was
Severity: Minor
Found in core/local/channel_watcher/initial_diff.js - About 2 hrs to fix

    Function fixPathsAfterParentMove has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    function fixPathsAfterParentMove(renamedEvents, event) {
      for (const renamedEvent of renamedEvents) {
        if (
          event.oldPath &&
          areParentChildPaths(renamedEvent.oldPath, event.oldPath)
    Severity: Minor
    Found in core/local/channel_watcher/initial_diff.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 fixPathsAfterParentMove has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function fixPathsAfterParentMove(renamedEvents, event) {
      for (const renamedEvent of renamedEvents) {
        if (
          event.oldPath &&
          areParentChildPaths(renamedEvent.oldPath, event.oldPath)
    Severity: Minor
    Found in core/local/channel_watcher/initial_diff.js - About 1 hr to fix

      Function debounce has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function debounce(waiting /*: WaitingItem[] */, events /*: ChannelEvent[] */) {
        for (let i = 0; i < events.length; i++) {
          const event = events[i]
          if (event.incomplete) {
            continue
      Severity: Minor
      Found in core/local/channel_watcher/initial_diff.js - About 1 hr to fix

        Avoid deeply nested control flow statements.
        Open

                  if (kind(was) === event.kind) {
                    // TODO for a directory, maybe we should check the children
                    _.set(event, [STEP_NAME, 'actionConvertedFrom'], event.action)
                    event.action = 'renamed'
                    event.oldPath = was.local.path
        Severity: Major
        Found in core/local/channel_watcher/initial_diff.js - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                    if (doc.local) {
                      const deletedEvent /*: ChannelEvent */ = {
                        action: 'deleted',
                        kind: kind(doc),
                        path: doc.local.path,
          Severity: Major
          Found in core/local/channel_watcher/initial_diff.js - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                    } else if (foundUntouchedFile(event, was, truncateWindowsDates)) {
                      _.set(event, [STEP_NAME, 'md5sumReusedFrom'], was.local.path)
                      event.md5sum = was.local.md5sum
                    }
            Severity: Major
            Found in core/local/channel_watcher/initial_diff.js - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                        if (e.action === 'renamed' && e.path === event.path) {
                          log.debug(`Ignore overlapping ${event.kind} ${event.action}`, {
                            renamedEvent: e,
                            scanEvent: event
                          })
              Severity: Major
              Found in core/local/channel_watcher/initial_diff.js - About 45 mins to fix

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

                function sendReadyBatches(waiting /*: WaitingItem[] */, out /*: Channel */) {
                  while (waiting.length > 0) {
                    if (waiting[0].nbCandidates !== 0) {
                      break
                    }
                Severity: Major
                Found in core/local/channel_watcher/initial_diff.js and 1 other location - About 3 hrs to fix
                core/local/channel_watcher/await_write_finish.js on lines 48..57

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

                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 foundRenamedOrReplacedDoc(event, was) /*: boolean %checks */ {
                  return was != null && was.local != null && was.local.path !== event.path
                }
                Severity: Minor
                Found in core/local/channel_watcher/initial_diff.js and 1 other location - About 50 mins to fix
                core/local/channel_watcher/initial_diff.js on lines 365..367

                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

                function foundUnappliedMove(event, was) /*: boolean %checks */ {
                  return was != null && was.moveFrom != null && was.moveFrom.path === event.path
                }
                Severity: Minor
                Found in core/local/channel_watcher/initial_diff.js and 1 other location - About 50 mins to fix
                core/local/channel_watcher/initial_diff.js on lines 369..371

                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 timeout = setTimeout(() => {
                      out.push(waiting.shift().batch)
                      sendReadyBatches(waiting, out)
                    }, DELAY)
                Severity: Minor
                Found in core/local/channel_watcher/initial_diff.js and 1 other location - About 40 mins to fix
                core/local/channel_watcher/await_write_finish.js on lines 257..260

                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

                There are no issues that match your filters.

                Category
                Status