Function wrapError
has 148 lines of code (exceeds 25 allowed). Consider refactoring. Open
const wrapError = (
err /*: FetchError | Error */,
doc /*: ?SavedMetadata */
) /*: RemoteError */ => {
if (isNetworkError(err)) {
Function wrapError
has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring. Open
const wrapError = (
err /*: FetchError | Error */,
doc /*: ?SavedMetadata */
) /*: RemoteError */ => {
if (isNetworkError(err)) {
- 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 errors.js
has 325 lines of code (exceeds 250 allowed). Consider refactoring. Open
/**
* @module core/remote/errors
* @flow
*/
Avoid too many return
statements within this function. Open
return new RemoteError({
code: INVALID_METADATA_CODE,
message: 'The local metadata for the document is corrupted',
err
})
Avoid too many return
statements within this function. Open
return new RemoteError({
code: COZY_NOT_FOUND_CODE,
message: 'Remote Cozy could not be found',
err
})
Avoid too many return
statements within this function. Open
return new RemoteError({
code: PATH_TOO_DEEP_CODE,
message:
'The path of the document has too many levels for the remote Cozy',
err
Avoid too many return
statements within this function. Open
return new RemoteError({ err })
Avoid too many return
statements within this function. Open
return err
Avoid too many return
statements within this function. Open
return new RemoteError({
code: FILE_TOO_LARGE_CODE,
message: 'The file is larger than allowed by the remote Cozy',
err
})
Avoid too many return
statements within this function. Open
return new RemoteError({
code: NO_COZY_SPACE_CODE,
message: 'Not enough space available on remote Cozy',
err
})
Avoid too many return
statements within this function. Open
return new RemoteError({
code: INVALID_NAME_CODE,
message:
'The name of the document contains characters forbidden by the remote Cozy',
err
Avoid too many return
statements within this function. Open
return new RemoteError({
code: MISSING_DOCUMENT_CODE,
message: 'The updated document is missing on the remote Cozy',
err
})
Avoid too many return
statements within this function. Open
return new RemoteError({
code: UNKNOWN_REMOTE_ERROR_CODE,
message:
'The remote Cozy failed to process the request for an unknown reason',
err
Avoid too many return
statements within this function. Open
return new RemoteError({
code: UNREACHABLE_COZY_CODE,
message: 'Cannot reach remote Cozy',
err
})
Avoid too many return
statements within this function. Open
return new RemoteError({
code: UNKNOWN_INVALID_DATA_ERROR_CODE,
message:
'The data sent to the remote Cozy is invalid for some unhandled reason',
err
Avoid too many return
statements within this function. Open
return new RemoteError({
code: NEEDS_REMOTE_MERGE_CODE,
message: 'The known remote document revision is outdated',
err
})
Avoid too many return
statements within this function. Open
return new RemoteError({
code: INVALID_METADATA_CODE,
message: 'The local metadata for the document is corrupted',
err
})
Avoid too many return
statements within this function. Open
return new RemoteError({
code: MISSING_PARENT_CODE,
message:
'The parent directory of the document is missing on the remote Cozy',
err
Avoid too many return
statements within this function. Open
return new RemoteError({
code: INVALID_FOLDER_MOVE_CODE,
message:
'The folder would be moved wihtin one of its sub-folders on the remote Cozy',
err
Similar blocks of code found in 2 locations. Consider refactoring. Open
case 413:
if (isFileLargerThanAllowed(doc)) {
return new RemoteError({
code: FILE_TOO_LARGE_CODE,
message: 'The file is larger than allowed by the remote Cozy',
- 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 65.
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
case 404:
if (hasNoReason(err)) {
return new RemoteError({
code: COZY_NOT_FOUND_CODE,
message: 'Remote Cozy could not be found',
- 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 65.
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
constructor({ cozyURL } /*: { cozyURL: string } */) {
super('Cannot reach remote Cozy')
if (Error.captureStackTrace) {
Error.captureStackTrace(this, UnreachableError)
- 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 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
- 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