File config.js
has 1011 lines of code (exceeds 250 allowed). Consider refactoring. Open
const _ = require('underscore-plus');
const { Emitter } = require('event-kit');
const {
getValueAtKeyPath,
setValueAtKeyPath,
Config
has 50 functions (exceeds 20 allowed). Consider refactoring. Open
class Config {
static addSchemaEnforcer(typeName, enforcerFunction) {
if (schemaEnforcers[typeName] == null) {
schemaEnforcers[typeName] = [];
}
Function unset
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
unset(keyPath, options) {
if (!this.settingsLoaded) {
this.pendingOperations.push(() => this.unset(keyPath, options));
}
- 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 unset
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
unset(keyPath, options) {
if (!this.settingsLoaded) {
this.pendingOperations.push(() => this.unset(keyPath, options));
}
Function getSchema
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
getSchema(keyPath) {
const keys = splitKeyPath(keyPath);
let { schema } = this;
for (let key of keys) {
let childSchema;
- 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 coerce
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
coerce(keyPath, value, schema) {
if (!isPlainObject(value)) {
throw new Error(
`Validation failed at ${keyPath}, ${JSON.stringify(
value
- 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 coerce
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
coerce(keyPath, value, schema) {
if (!isPlainObject(value)) {
throw new Error(
`Validation failed at ${keyPath}, ${JSON.stringify(
value
Function setScopedDefaultsFromSchema
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
setScopedDefaultsFromSchema(keyPath, schema) {
if (schema.scopes != null && isPlainObject(schema.scopes)) {
const scopedDefaults = {};
for (let scope in schema.scopes) {
const scopeSchema = schema.scopes[scope];
- 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 getRawValue
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
getRawValue(keyPath, options = {}) {
let value;
if (
!options.excludeSources ||
!options.excludeSources.includes(this.mainSource)
- 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 set
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
set(...args) {
let [keyPath, value, options = {}] = args;
if (!this.settingsLoaded) {
this.pendingOperations.push(() => this.set(keyPath, value, options));
- 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 makeValueConformToSchema
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
makeValueConformToSchema(keyPath, value, options) {
if (options != null ? options.suppressException : undefined) {
try {
return this.makeValueConformToSchema(keyPath, value);
} catch (e) {
- 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 withoutEmptyObjects
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
const withoutEmptyObjects = object => {
let resultObject;
if (isPlainObject(object)) {
for (let key in object) {
const value = object[key];
- 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 getAll
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
getAll(keyPath, options) {
let globalValue, result, scope;
if (options != null) {
({ scope } = options);
}
Function setSchema
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
setSchema(keyPath, schema) {
if (!isPlainObject(schema)) {
throw new Error(
`Error loading schema for ${keyPath}: schemas can only be objects!`
);
- 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 deepDefaults
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
deepDefaults(target) {
let result = target;
let i = 0;
while (++i < arguments.length) {
const object = arguments[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
Function setSchema
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
setSchema(keyPath, schema) {
if (!isPlainObject(schema)) {
throw new Error(
`Error loading schema for ${keyPath}: schemas can only be objects!`
);
Function set
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
set(...args) {
let [keyPath, value, options = {}] = args;
if (!this.settingsLoaded) {
this.pendingOperations.push(() => this.set(keyPath, value, options));
Function setScopedDefaultsFromSchema
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
setScopedDefaultsFromSchema(keyPath, schema) {
if (schema.scopes != null && isPlainObject(schema.scopes)) {
const scopedDefaults = {};
for (let scope in schema.scopes) {
const scopeSchema = schema.scopes[scope];
Function setRawValue
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
setRawValue(keyPath, value, options = {}) {
const source = options.source ? options.source : undefined;
const settingsToChange =
source === this.projectFile ? 'projectSettings' : 'settings';
const defaultValue = getValueAtKeyPath(this.defaultSettings, keyPath);
- 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 validateEnum
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
validateEnum(keyPath, value, schema) {
let possibleValues = schema.enum;
if (Array.isArray(possibleValues)) {
possibleValues = possibleValues.map(value => {
Function setDefaults
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
setDefaults(keyPath, defaults) {
if (defaults != null && isPlainObject(defaults)) {
const keys = splitKeyPath(keyPath);
this.transact(() => {
const result = [];
Function _resetSettings
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
_resetSettings(newSettings, options = {}) {
const source = options.source;
newSettings = Object.assign({}, newSettings);
if (newSettings.global != null) {
newSettings['*'] = newSettings.global;
Function get
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
get(...args) {
let keyPath, options, scope;
if (args.length > 1) {
if (typeof args[0] === 'string' || args[0] == null) {
[keyPath, options] = args;
- 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 coerce
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
coerce(keyPath, value, schema) {
if (!Array.isArray(value)) {
throw new Error(
`Validation failed at ${keyPath}, ${JSON.stringify(
value
- 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 observe
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
observe(...args) {
let callback, keyPath, options, scopeDescriptor;
if (args.length === 2) {
[keyPath, callback] = args;
} else if (
- 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 executeSchemaEnforcers
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
static executeSchemaEnforcers(keyPath, value, schema) {
let error = null;
let types = schema.type;
if (!Array.isArray(types)) {
types = [types];
- 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 validateEnum
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
validateEnum(keyPath, value, schema) {
let possibleValues = schema.enum;
if (Array.isArray(possibleValues)) {
possibleValues = possibleValues.map(value => {
- 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 extractDefaultsFromSchema
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
extractDefaultsFromSchema(schema) {
if (schema.default != null) {
return schema.default;
} else if (
schema.type === 'object' &&
- 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 getAll
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
getAll(keyPath, options) {
let globalValue, result, scope;
if (options != null) {
({ scope } = options);
}
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
integer: {
coerce(keyPath, value, schema) {
value = parseInt(value);
if (isNaN(value) || !isFinite(value)) {
throw new Error(
- 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 80.
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
number: {
coerce(keyPath, value, schema) {
value = parseFloat(value);
if (isNaN(value) || !isFinite(value)) {
throw new Error(
- 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 80.
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
unshiftAtKeyPath(keyPath, value) {
const left = this.get(keyPath);
const arrayValue = left == null ? [] : left;
const result = arrayValue.unshift(value);
this.set(keyPath, arrayValue);
- 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 73.
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
pushAtKeyPath(keyPath, value) {
const left = this.get(keyPath);
const arrayValue = left == null ? [] : left;
const result = arrayValue.push(value);
this.set(keyPath, arrayValue);
- 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 73.
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
if (schema.minimum != null && typeof schema.minimum === 'number') {
value = Math.max(value, schema.minimum);
}
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (schema.maximum != null && typeof schema.maximum === 'number') {
value = Math.min(value, schema.maximum);
}
- 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