Showing 35 of 35 total issues
Function regexSample
has a Cognitive Complexity of 59 (exceeds 5 allowed). Consider refactoring. Open
export function regexSample(pattern) {
let isCaseInsensitive = false;
if (pattern instanceof RegExp) {
isCaseInsensitive = pattern.flags.includes('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 sampleNumber
has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring. Open
export function sampleNumber(schema) {
let res = 0;
if (schema.type === 'number' && (schema.format === 'float' || schema.format === 'double')) {
res = 0.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 traverse
has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring. Open
export function traverse(schema, options, spec, context) {
// checking circular JS references by checking context
// because context is passed only when traversing through nested objects happens
if (context) {
if (seenSchemasStack.includes(schema)) return getResultForCircular(inferType(schema));
- 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 regexSample
has 139 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function regexSample(pattern) {
let isCaseInsensitive = false;
if (pattern instanceof RegExp) {
isCaseInsensitive = pattern.flags.includes('i');
Function traverse
has 108 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function traverse(schema, options, spec, context) {
// checking circular JS references by checking context
// because context is passed only when traversing through nested objects happens
if (context) {
if (seenSchemasStack.includes(schema)) return getResultForCircular(inferType(schema));
Similar blocks of code found in 2 locations. Consider refactoring. Open
for (let i = 65; i <= 90; i++) {
index = rangeCodes.indexOf(i);
if (index > -1) {
rangeCodes.splice(index, 1);
continue;
- 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 79.
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
for (let i = 48; i <= 57; i++) {
index = rangeCodes.indexOf(i);
if (index > -1) {
rangeCodes.splice(index, 1);
continue;
- 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 79.
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
Function allOfSample
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
export function allOfSample(into, children, options, spec, context) {
let res = traverse(into, options, spec);
const subSamples = [];
for (let subSchema of children) {
- 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 sampleObject
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function sampleObject(schema, options = {}, spec, context) {
let res = {};
const depth = (context && context.depth || 1);
if (schema && typeof schema.properties === 'object') {
Function sampleObject
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
export function sampleObject(schema, options = {}, spec, context) {
let res = {};
const depth = (context && context.depth || 1);
if (schema && typeof schema.properties === '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 sampleNumber
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function sampleNumber(schema) {
let res = 0;
if (schema.type === 'number' && (schema.format === 'float' || schema.format === 'double')) {
res = 0.1;
}
Function exports
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports = function (config) {
function configureLocalBrowsers() {
let isMac = /^darwin/.test(process.platform),
isWindows = /^win/.test(process.platform),
isLinux = !(isMac || isWindows);
Identical blocks of code found in 3 locations. Consider refactoring. Open
pattern =
pattern.slice(0, token.index) +
token[1].repeat(repetitions) +
pattern.slice(token.index + token[0].length);
- 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 64.
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 3 locations. Consider refactoring. Open
pattern =
pattern.slice(0, token.index) +
token[1].repeat(repetitions) +
pattern.slice(token.index + token[0].length);
- 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 64.
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 3 locations. Consider refactoring. Open
pattern =
pattern.slice(0, token.index) +
token[1].repeat(repetitions) +
pattern.slice(token.index + token[0].length);
- 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 64.
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
Function getRepetitionsBasedOnQuantifierParameters
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
function getRepetitionsBasedOnQuantifierParameters(
quantifierSymbol,
quantifierMin,
quantifierMax
) {
- 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 getRepetitionsBasedOnQuantifierParameters
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
function getRepetitionsBasedOnQuantifierParameters(
quantifierSymbol,
quantifierMin,
quantifierMax
) {
Function inferType
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
export function inferType(schema) {
if (schema.type !== undefined) {
return Array.isArray(schema.type) ? schema.type.length === 0 ? null : schema.type[0] : schema.type;
}
const keywords = Object.keys(schemaKeywordTypes);
- 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 sampleArray
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
export function sampleArray(schema, options = {}, spec, context) {
const depth = (context && context.depth || 1);
let arrayLength = Math.min(schema.maxItems != undefined ? schema.maxItems : Infinity, schema.minItems || 1);
// for the sake of simplicity, we're treating `contains` in a similar way to `items`
- 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 (isCaseInsensitive && isNaN(Number(String.fromCharCode(i)))) {
const ch = String.fromCharCode(i);
rangeCodes.push(ch.toUpperCase().charCodeAt(0));
rangeCodes.push(ch.toLowerCase().charCodeAt(0));
} else {