Showing 130 of 215 total issues
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))
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"
Further reading
Function getSchemaTypes
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
export function getSchemaTypes(schema: AnySchemaObject): JSONType[] {
const types = getJSONTypes(schema.type)
const hasNull = types.includes("null")
if (hasNull) {
if (schema.nullable === false) throw new Error("type: null contradicts nullable: 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 getSubschema
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
export function getSubschema(
it: SchemaObjCxt,
{keyword, schemaProp, schema, schemaPath, errSchemaPath, topSchemaRef}: SubschemaArgs
): SubschemaContext {
if (keyword !== undefined && schema !== 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 8 (exceeds 5 allowed). Consider refactoring. Open
code(cxt: KeywordCxt) {
checkMetadata(cxt)
const {gen, data, schema, schemaValue, parentSchema, it} = cxt
if (schema.length === 0) throw new Error("enum must have non-empty array")
if (schema.length !== new Set(schema).size) throw new Error("enum items must be unique")
- 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 (c === undefined) {
errorMessage("unexpected end")
return undefined
}
Function coerceData
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
function coerceData(it: SchemaObjCxt, types: JSONType[], coerceTo: JSONType[]): void {
const {gen, data, opts} = it
const dataType = gen.let("dataType", _`typeof ${data}`)
const coerced = gen.let("coerced", _`undefined`)
if (opts.coerceTypes === "array") {
- 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 dynamicRef
has a Cognitive Complexity of 8 (exceeds 5 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) {
- 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 (c >= "a" && c <= "f") {
code += c.charCodeAt(0) - CODE_A + 10
} else if (c >= "0" && c <= "9") {
code += c.charCodeAt(0) - CODE_0
} else {
Function addSchema
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
addSchema(
schema: AnySchema | AnySchema[], // If array is passed, `key` will be ignored
key?: string, // Optional schema key. Can be passed to `validate` method instead of schema object or id/ref. One schema per instance can have empty `id` and `key`.
_meta?: boolean, // true if schema is a meta-schema. Used internally, addMetaSchema should be used instead.
_validateSchema = this.opts.validateSchema // false to skip schema validation. Used internally, option validateSchema should be used instead.
- 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 checkOptions
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
this: Ajv,
checkOpts: OptionsInfo<RemovedOptions | DeprecatedOptions>,
options: Options & RemovedOptions,
msg: string,
log: "warn" | "error" = "error"
Function checkDataTypes
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
export function checkDataTypes(
dataTypes: JSONType[],
data: Name,
strictNums?: boolean | "log",
correct?: DataType
- 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"