epoberezkin/ajv

View on GitHub

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
Severity: Minor
Found in lib/vocabularies/validation/enum.ts - About 1 hr to fix

    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)
    Severity: Minor
    Found in lib/vocabularies/applicator/oneOf.ts - About 1 hr to fix

      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))
      Severity: Minor
      Found in lib/vocabularies/code.ts - About 1 hr to fix

        Function schemaKeywords has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function schemaKeywords(
          it: SchemaObjCxt,
          types: JSONType[],
          typeErrors: boolean,
          errsCount?: Name
        Severity: Minor
        Found in lib/compile/validate/index.ts - About 1 hr to fix

          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++
          Severity: Minor
          Found in lib/compile/resolve.ts - About 55 mins to fix

          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) {
              checkMetadata(cxt)
              const {gen, data, schema: ref, parentSchema, it} = cxt
              const {
                schemaEnv: {root},
          Severity: Minor
          Found in lib/vocabularies/jtd/ref.ts - About 55 mins to fix

          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") {
          Severity: Minor
          Found in lib/core.ts - About 55 mins to fix

          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 {
          Severity: Minor
          Found in lib/compile/validate/subschema.ts - About 55 mins to fix

          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) {
          Severity: Minor
          Found in lib/compile/validate/subschema.ts - About 55 mins to fix

          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()
          Severity: Minor
          Found in lib/vocabularies/core/ref.ts - About 55 mins to fix

          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") {
          Severity: Minor
          Found in lib/core.ts - About 55 mins to fix

          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")
          Severity: Minor
          Found in lib/compile/validate/dataType.ts - About 55 mins to fix

          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 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") {
          Severity: Minor
          Found in lib/compile/validate/dataType.ts - About 45 mins to fix

          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")
          Severity: Minor
          Found in lib/vocabularies/jtd/enum.ts - About 45 mins to fix

          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 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.
          Severity: Minor
          Found in lib/core.ts - About 45 mins to fix

          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) {
          Severity: Minor
          Found in lib/vocabularies/dynamic/dynamicRef.ts - About 45 mins to fix

          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
                    }
          Severity: Major
          Found in lib/runtime/parseJson.ts - About 45 mins to fix

            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 {
            Severity: Major
            Found in lib/runtime/parseJson.ts - About 45 mins to fix

              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"
              Severity: Minor
              Found in lib/core.ts - About 35 mins to fix

                Function failResult has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                  failResult(condition: Code, successAction?: () => void, failAction?: () => void): void {
                    this.gen.if(condition)
                    if (failAction) failAction()
                    else this.error()
                    if (successAction) {
                Severity: Minor
                Found in lib/compile/validate/index.ts - About 35 mins to fix

                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

                Severity
                Category
                Status
                Source
                Language