Showing 215 of 215 total issues
Function getErrorPath
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
export function getErrorPath(
dataProp: Name | string | number,
dataPropType?: Type,
jsPropertySyntax?: boolean
): Code | string {
- 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 validateKeywordUsage
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
export function validateKeywordUsage(
{schema, opts, self, errSchemaPath}: SchemaObjCxt,
def: AddedKeywordDefinition,
keyword: string
): 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 code
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
code(cxt: KeywordCxt) {
const {gen, data, $data, schema, schemaCode, it} = cxt
if (!$data && schema.length === 0) throw new Error("enum must have non-empty array")
const useLoop = schema.length >= it.opts.loopEnum
let eql: Name | undefined
- 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 code
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
code(cxt: KeywordCxt) {
checkMetadata(cxt)
const {data, schema, parentSchema, it} = cxt
let cond: Code
switch (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 addKeyword
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
addKeyword(
kwdOrDef: string | KeywordDefinition,
def?: KeywordDefinition // deprecated
): Ajv {
let keyword: string | string[]
- 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 hasRef
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
function hasRef(schema: AnySchemaObject): boolean {
for (const key in schema) {
if (REF_KEYWORDS.has(key)) return true
const sch = schema[key]
if (Array.isArray(sch) && sch.some(hasRef)) return true
- 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 invalid$data
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
invalid$data(): Code {
const {gen, schemaCode, schemaType, def, it} = this
return or(wrong$DataType(), invalid$DataSchema())
function wrong$DataType(): Code {
- 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 validateOneOf
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
function validateOneOf(): void {
schArr.forEach((sch: AnySchema, i: number) => {
let schCxt: SchemaCxt | undefined
if (alwaysValidSchema(it, sch)) {
gen.var(schValid, true)
Function code
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
code(cxt: KeywordCxt) {
const {gen, data, $data, schema, schemaCode, it} = cxt
if (!$data && schema.length === 0) throw new Error("enum must have non-empty array")
const useLoop = schema.length >= it.opts.loopEnum
let eql: Name | undefined
Function dynamicRef
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function dynamicRef(cxt: KeywordCxt, ref: string): void {
const {gen, keyword, it} = cxt
if (ref[0] !== "#") throw new Error(`"${keyword}" only supports hash fragment reference`)
const anchor = ref.slice(1)
if (it.allErrors) {
Function schemaKeywords
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
function schemaKeywords(
it: SchemaObjCxt,
types: JSONType[],
typeErrors: boolean,
errsCount?: Name
Function validateUnion
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function validateUnion(cxt: KeywordCxt): void {
const {gen, schema, keyword, it} = cxt
/* istanbul ignore if */
if (!Array.isArray(schema)) throw new Error("ajv implementation error")
const alwaysValid = schema.some((sch: AnySchema) => alwaysValidSchema(it, sch))
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (schema === false) {
cxt.setParams({unevaluatedProperty: key})
cxt.error()
if (!allErrors) gen.break()
return
- 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 55.
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 === false) {
cxt.setParams({additionalProperty: key})
cxt.error()
if (!allErrors) gen.break()
return
- 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 55.
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 code
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
code(cxt: KeywordCxt) {
checkMetadata(cxt)
const {gen, data, schema: ref, parentSchema, it} = cxt
const {
schemaEnv: {root},
- 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 validateSchema
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
validateSchema(schema: AnySchema, throwOrLogError?: boolean): boolean | Promise<unknown> {
if (typeof schema == "boolean") return true
let $schema: string | AnySchemaObject | undefined
$schema = schema.$schema
if ($schema !== undefined && typeof $schema != "string") {
- 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 code
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
code(cxt: KeywordCxt): void {
const {gen, schema: $ref, it} = cxt
const {baseId, schemaEnv: env, validateName, opts, self} = it
const {root} = env
if (($ref === "#" || $ref === "#/") && baseId === root.baseId) return callRootRef()
- 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 _removeAllSchemas
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private _removeAllSchemas(schemas: {[Ref in string]?: SchemaEnv | string}, regex?: RegExp): void {
for (const keyRef in schemas) {
const sch = schemas[keyRef]
if (!regex || regex.test(keyRef)) {
if (typeof sch == "string") {
- 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 countKeys
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
function countKeys(schema: AnySchemaObject): number {
let count = 0
for (const key in schema) {
if (key === "$ref") return Infinity
count++
- 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 extendSubschemaData
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
export function extendSubschemaData(
subschema: SubschemaContext,
it: SchemaObjCxt,
{dataProp, dataPropType: dpType, data, dataTypes, propertyName}: SubschemaArgs
): 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"