File path.js
has 992 lines of code (exceeds 250 allowed). Consider refactoring. Open
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
Function resolve
has a Cognitive Complexity of 79 (exceeds 5 allowed). Consider refactoring. Open
resolve(...args) {
let resolvedDevice = '';
let resolvedTail = '';
let resolvedAbsolute = false;
- 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 parse
has a Cognitive Complexity of 63 (exceeds 5 allowed). Consider refactoring. Open
parse(path) {
validateString(path, 'path');
const ret = { root: '', dir: '', base: '', ext: '', name: '' };
if (path.length === 0)
- 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 dirname
has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring. Open
dirname(path) {
validateString(path, 'path');
const len = path.length;
if (len === 0)
return '.';
- 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 normalize
has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring. Open
normalize(path) {
validateString(path, 'path');
const len = path.length;
if (len === 0)
return '.';
- 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 basename
has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring. Open
basename(path, ext) {
if (ext !== undefined)
validateString(ext, 'ext');
validateString(path, 'path');
let start = 0;
- 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 basename
has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring. Open
basename(path, ext) {
if (ext !== undefined)
validateString(ext, 'ext');
validateString(path, 'path');
- 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 normalizeString
has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring. Open
function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
let res = '';
let lastSegmentLength = 0;
let lastSlash = -1;
let dots = 0;
- 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 relative
has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring. Open
relative(from, to) {
validateString(from, 'from');
validateString(to, 'to');
if (from === to)
- 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 parse
has 103 lines of code (exceeds 25 allowed). Consider refactoring. Open
parse(path) {
validateString(path, 'path');
const ret = { root: '', dir: '', base: '', ext: '', name: '' };
if (path.length === 0)
Function relative
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
relative(from, to) {
validateString(from, 'from');
validateString(to, 'to');
if (from === to)
- 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 parse
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
parse(path) {
validateString(path, 'path');
const ret = { root: '', dir: '', base: '', ext: '', name: '' };
if (path.length === 0)
- 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 resolve
has 92 lines of code (exceeds 25 allowed). Consider refactoring. Open
resolve(...args) {
let resolvedDevice = '';
let resolvedTail = '';
let resolvedAbsolute = false;
Function join
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
join(...args) {
if (args.length === 0)
return '.';
let joined;
- 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 relative
has 78 lines of code (exceeds 25 allowed). Consider refactoring. Open
relative(from, to) {
validateString(from, 'from');
validateString(to, 'to');
if (from === to)
Function extname
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
extname(path) {
validateString(path, 'path');
let start = 0;
let startDot = -1;
let startPart = 0;
- 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 normalize
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
normalize(path) {
validateString(path, 'path');
const len = path.length;
if (len === 0)
return '.';
Function extname
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
extname(path) {
validateString(path, 'path');
let startDot = -1;
let startPart = 0;
let end = -1;
- 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 basename
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Open
basename(path, ext) {
if (ext !== undefined)
validateString(ext, 'ext');
validateString(path, 'path');
let start = 0;
Function dirname
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
dirname(path) {
validateString(path, 'path');
const len = path.length;
if (len === 0)
return '.';
Function parse
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
parse(path) {
validateString(path, 'path');
const ret = { root: '', dir: '', base: '', ext: '', name: '' };
if (path.length === 0)
Function normalizeString
has 58 lines of code (exceeds 25 allowed). Consider refactoring. Open
function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
let res = '';
let lastSegmentLength = 0;
let lastSlash = -1;
let dots = 0;
Function basename
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
basename(path, ext) {
if (ext !== undefined)
validateString(ext, 'ext');
validateString(path, 'path');
Function relative
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
relative(from, to) {
validateString(from, 'from');
validateString(to, 'to');
if (from === to)
Function extname
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
extname(path) {
validateString(path, 'path');
let start = 0;
let startDot = -1;
let startPart = 0;
Function join
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
join(...args) {
if (args.length === 0)
return '.';
let joined;
Function dirname
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
dirname(path) {
validateString(path, 'path');
if (path.length === 0)
return '.';
const hasRoot = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
- 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 extname
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
extname(path) {
validateString(path, 'path');
let startDot = -1;
let startPart = 0;
let end = -1;
Function toNamespacedPath
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
toNamespacedPath(path) {
// Note: this will *probably* throw somewhere.
if (typeof path !== 'string')
return path;
- 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
Avoid deeply nested control flow statements. Open
if (j !== last) {
// We matched a UNC root with leftovers
// Offset by 1 to include the separator after the UNC root to
// treat it as a "normal root" on top of a (UNC) root
Avoid deeply nested control flow statements. Open
if (res.length > 2) {
const lastSlashIndex = res.lastIndexOf(separator);
if (lastSlashIndex === -1) {
res = '';
lastSegmentLength = 0;
Avoid deeply nested control flow statements. Open
while (j < len && !isPathSeparator(path.charCodeAt(j))) {
j++;
}
Avoid deeply nested control flow statements. Open
while (j < len && !isPathSeparator(path.charCodeAt(j))) {
j++;
}
Avoid deeply nested control flow statements. Open
while (j < len && !isPathSeparator(path.charCodeAt(j))) {
j++;
}
Avoid deeply nested control flow statements. Open
if (j !== last) {
// We matched a UNC root with leftovers
device = `\\\\${firstPart}\\${path.slice(last, j)}`;
rootEnd = j;
}
Avoid deeply nested control flow statements. Open
while (j < len && !isPathSeparator(path.charCodeAt(j))) {
j++;
}
Avoid deeply nested control flow statements. Open
if (code === ext.charCodeAt(extIdx)) {
if (--extIdx === -1) {
// We matched the extension, so mark this as the end of our path
// component
end = i;
Avoid deeply nested control flow statements. Open
if (j === len) {
// We matched a UNC root only
// Return the normalized version of the UNC root since there
// is nothing left to process
return `\\\\${firstPart}\\${path.slice(last)}\\`;
Function normalize
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
normalize(path) {
validateString(path, 'path');
if (path.length === 0)
return '.';
- 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
Avoid deeply nested control flow statements. Open
if (j < len && j !== last) {
const firstPart = path.slice(last, j);
// Matched!
last = j;
// Match 1 or more path separators
Avoid deeply nested control flow statements. Open
if (code === ext.charCodeAt(extIdx)) {
if (--extIdx === -1) {
// We matched the extension, so mark this as the end of our path
// component
end = i;
Avoid deeply nested control flow statements. Open
if (len > 2 && isPathSeparator(path.charCodeAt(2))) {
// Treat separator following drive name as an absolute path
// indicator
isAbsolute = true;
rootEnd = 3;
Avoid deeply nested control flow statements. Open
if (j === len) {
// We matched a UNC root only
return path;
}
Avoid deeply nested control flow statements. Open
if (j === len) {
// We matched a UNC root only
rootEnd = j;
} else if (j !== last) {
// We matched a UNC root with leftovers
Function join
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
join(...args) {
if (args.length === 0)
return '.';
let joined;
for (let i = 0; i < args.length; ++i) {
- 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
Consider simplifying this complex logical expression. Open
if (startDot === -1 ||
end === -1 ||
// We saw a non-dot character immediately before the dot
preDotState === 0 ||
// The (right-most) trimmed path component is exactly '..'
Consider simplifying this complex logical expression. Open
if (startDot === -1 ||
end === -1 ||
// We saw a non-dot character immediately before the dot
preDotState === 0 ||
// The (right-most) trimmed path component is exactly '..'
Function resolve
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
resolve(...args) {
let resolvedPath = '';
let resolvedAbsolute = false;
for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
- 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
Avoid too many return
statements within this function. Open
return ret;
Avoid too many return
statements within this function. Open
return toOrig.slice(toStart + i);
Avoid too many return
statements within this function. Open
return isAbsolute ? `${device}\\${tail}` : `${device}${tail}`;
Avoid too many return
statements within this function. Open
return `${out}${to.slice(toStart + lastCommonSep)}`;
Avoid too many return
statements within this function. Open
return path;
Avoid too many return
statements within this function. Open
return `\\\\?\\${resolvedPath}`;
Avoid too many return
statements within this function. Open
return ret;
Avoid too many return
statements within this function. Open
return toOrig.slice(toStart, toEnd);
Avoid too many return
statements within this function. Open
return `${out}${toOrig.slice(toStart, toEnd)}`;
Avoid too many return
statements within this function. Open
return path.slice(0, end);
Avoid too many return
statements within this function. Open
return toOrig.slice(toStart + i + 1);
Identical blocks of code found in 2 locations. Consider refactoring. Open
const win32 = {
// path.resolve([from ...], to)
resolve(...args) {
let resolvedDevice = '';
let resolvedTail = '';
- 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 5929.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
const posix = {
// path.resolve([from ...], to)
resolve(...args) {
let resolvedPath = '';
let resolvedAbsolute = false;
- 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 2786.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
let res = '';
let lastSegmentLength = 0;
let lastSlash = -1;
let dots = 0;
- 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 592.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
function _format(sep, pathObject) {
if (pathObject === null || typeof pathObject !== 'object') {
throw new ERR_INVALID_ARG_TYPE('pathObject', 'Object', pathObject);
}
const dir = pathObject.dir || pathObject.root;
- 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 162.
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