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> */ {
- Read upRead up
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
- Read upRead up
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
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)
- Read upRead up
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)
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
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
Avoid deeply nested control flow statements. Open
if (doc.local) {
const deletedEvent /*: ChannelEvent */ = {
action: 'deleted',
kind: kind(doc),
path: doc.local.path,
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
}
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
})
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
}
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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
}
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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
}
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
const timeout = setTimeout(() => {
out.push(waiting.shift().batch)
sendReadyBatches(waiting, out)
}, DELAY)
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76