cozy-labs/cozy-desktop

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

Summary

Maintainability
D
2 days
Test Coverage

Function debounce has a Cognitive Complexity of 59 (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) {
Severity: Minor
Found in core/local/channel_watcher/await_write_finish.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 51 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) {
Severity: Major
Found in core/local/channel_watcher/await_write_finish.js - About 2 hrs to fix

    Avoid deeply nested control flow statements.
    Open

              if (
                (['created', 'modified'].includes(e.action) ||
                  (e.action === 'renamed' && ino(e) === ino(event))) &&
                e.path === event.path
              ) {
    Severity: Major
    Found in core/local/channel_watcher/await_write_finish.js - About 45 mins to fix

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

      function aggregateEvents(oldEvent, recentEvent) {
        if (recentEvent.action === 'deleted') {
          if (oldEvent.action === 'created') {
            // It's just a temporary file that we can ignore
            log.debug(
      Severity: Minor
      Found in core/local/channel_watcher/await_write_finish.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 countFileWriteEvents has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      function countFileWriteEvents(events /*: ChannelEvent[] */) /*: number */ {
        let nbCandidates = 0
        for (let i = 0; i < events.length; i++) {
          const event = events[i]
          if (event.incomplete) {
      Severity: Minor
      Found in core/local/channel_watcher/await_write_finish.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

      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/await_write_finish.js and 1 other location - About 3 hrs to fix
      core/local/channel_watcher/initial_diff.js on lines 264..273

      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

        if (recentEvent.action === 'modified') {
          addDebugInfo(recentEvent, oldEvent)
          // Preserve the action from the first event (it can be a created file)
          recentEvent.action = oldEvent.action
      
      
      Severity: Major
      Found in core/local/channel_watcher/await_write_finish.js and 1 other location - About 1 hr to fix
      core/local/channel_watcher/await_write_finish.js on lines 207..215

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

      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 (event.action === 'modified') {
                    addDebugInfo(event, e)
                    // Preserve the action from the first event (it can be a created file)
                    event.action = e.action
      
      
      Severity: Major
      Found in core/local/channel_watcher/await_write_finish.js and 1 other location - About 1 hr to fix
      core/local/channel_watcher/await_write_finish.js on lines 136..144

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

      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

                      log.debug(
                        { createdEvent: e, deletedEvent: event },
                        `Ignore ${e.kind} ${e.action} then ${event.action}`
                      )
      Severity: Minor
      Found in core/local/channel_watcher/await_write_finish.js and 1 other location - About 55 mins to fix
      core/local/channel_watcher/await_write_finish.js on lines 123..126

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

      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

            log.debug(
              { createdEvent: oldEvent, deletedEvent: recentEvent },
              `Ignore ${oldEvent.kind} ${oldEvent.action} then ${recentEvent.action}`
            )
      Severity: Minor
      Found in core/local/channel_watcher/await_write_finish.js and 1 other location - About 55 mins to fix
      core/local/channel_watcher/await_write_finish.js on lines 220..223

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

      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().events)
            sendReadyBatches(waiting, out)
          }, DELAY)
      Severity: Minor
      Found in core/local/channel_watcher/await_write_finish.js and 1 other location - About 40 mins to fix
      core/local/channel_watcher/initial_diff.js on lines 253..256

      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