epoberezkin/ajv

View on GitHub

Showing 130 of 217 total issues

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

  code(cxt: KeywordCxt, ruleType?: string) {
    const {gen, data, $data, schema, schemaCode, it} = cxt
    const {opts, errSchemaPath, schemaEnv, self} = it
    if (!opts.validateFormats) return

Severity: Major
Found in lib/vocabularies/format/format.ts - About 2 hrs to fix

    Function coerceData has 69 lines of code (exceeds 25 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: Major
    Found in lib/compile/validate/dataType.ts - About 2 hrs to fix

      Function code has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

        code(cxt: KeywordCxt) {
          const {gen, schema, data, parentSchema, it} = cxt
          const {opts} = it
          const patterns = allSchemaProperties(schema)
          const alwaysValidPatterns = patterns.filter((p) =>
      Severity: Minor
      Found in lib/vocabularies/applicator/patternProperties.ts - About 2 hrs 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 20 (exceeds 5 allowed). Consider refactoring.
      Open

        code(cxt: KeywordCxt) {
          const {gen, schema, schemaCode, data, $data, it} = cxt
          const {opts} = it
          if (!$data && schema.length === 0) return
          const useLoop = schema.length >= opts.loopRequired
      Severity: Minor
      Found in lib/vocabularies/validation/required.ts - About 2 hrs 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

      File index.ts has 281 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import type {
        AnySchema,
        AnySchemaObject,
        AnyValidateFunction,
        AsyncValidateFunction,
      Severity: Minor
      Found in lib/compile/index.ts - About 2 hrs to fix

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

          code(cxt: KeywordCxt) {
            const {gen, schema, parentSchema, data, it} = cxt
            let min: number
            let max: number | undefined
            const {minContains, maxContains} = parentSchema
        Severity: Major
        Found in lib/vocabularies/applicator/contains.ts - About 2 hrs to fix

          Ajv has 24 functions (exceeds 20 allowed). Consider refactoring.
          Open

          export default class Ajv {
            opts: InstanceOptions
            errors?: ErrorObject[] | null // errors from the last validation
            logger: Logger
            // shared external scope values for compiled functions
          Severity: Minor
          Found in lib/core.ts - About 2 hrs to fix

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

              code(cxt: KeywordCxt) {
                const {gen, schema, data, parentSchema, it} = cxt
                const {opts} = it
                const patterns = allSchemaProperties(schema)
                const alwaysValidPatterns = patterns.filter((p) =>
            Severity: Major
            Found in lib/vocabularies/applicator/patternProperties.ts - About 2 hrs to fix

              Function getData has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
              Open

              export function getData(
                $data: string,
                {dataLevel, dataNames, dataPathArr}: SchemaCxt
              ): Code | number {
                let jsonPointer
              Severity: Minor
              Found in lib/compile/validate/index.ts - About 2 hrs 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 18 (exceeds 5 allowed). Consider refactoring.
              Open

                code(cxt) {
                  const {gen, schema, data, errsCount, it} = cxt
                  /* istanbul ignore if */
                  if (!errsCount) throw new Error("ajv implementation error")
                  const {allErrors, props} = it
              Severity: Minor
              Found in lib/vocabularies/unevaluated/unevaluatedProperties.ts - About 2 hrs 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 59 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                code(cxt: KeywordCxt) {
                  const {gen, schema, schemaCode, data, $data, it} = cxt
                  const {opts} = it
                  if (!$data && schema.length === 0) return
                  const useLoop = schema.length >= opts.loopRequired
              Severity: Major
              Found in lib/vocabularies/validation/required.ts - About 2 hrs to fix

                Function callRef has 58 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                export function callRef(cxt: KeywordCxt, v: Code, sch?: SchemaEnv, $async?: boolean): void {
                  const {gen, it} = cxt
                  const {allErrors, schemaEnv: env, opts} = it
                  const passCxt = opts.passContext ? N.this : nil
                  if ($async) callAsyncRef()
                Severity: Major
                Found in lib/vocabularies/core/ref.ts - About 2 hrs to fix

                  Function compileSchema has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                  Open

                  export function compileSchema(this: Ajv, sch: SchemaEnv): SchemaEnv {
                    // TODO refactor - remove compilations
                    const _sch = getCompilingSchema.call(this, sch)
                    if (_sch) return _sch
                    const rootId = getFullPath(this.opts.uriResolver, sch.root.baseId) // TODO if getFullPath removed 1 tests fails
                  Severity: Minor
                  Found in lib/compile/index.ts - About 2 hrs 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 compileAsync has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                  Open

                    compileAsync<T = unknown>(
                      schema: AnySchemaObject,
                      meta?: boolean
                    ): Promise<AnyValidateFunction<T>> {
                      if (typeof this.opts.loadSchema != "function") {
                  Severity: Minor
                  Found in lib/core.ts - About 2 hrs 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 parseJsonString has 56 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  export function parseJsonString(s: string, pos: number): string | undefined {
                    let str = ""
                    let c: string | undefined
                    parseJsonString.message = undefined
                    // eslint-disable-next-line no-constant-condition, @typescript-eslint/no-unnecessary-condition
                  Severity: Major
                  Found in lib/runtime/parseJson.ts - About 2 hrs to fix

                    Function parseJsonNumber has 55 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    export function parseJsonNumber(s: string, pos: number, maxDigits?: number): number | undefined {
                      let numStr = ""
                      let c: string
                      parseJsonNumber.message = undefined
                      if (s[pos] === "-") {
                    Severity: Major
                    Found in lib/runtime/parseJson.ts - About 2 hrs to fix

                      Function optimizeNodes has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                      Open

                        optimizeNodes(): If | ChildNode[] | undefined {
                          super.optimizeNodes()
                          const cond = this.condition
                          if (cond === true) return this.nodes // else is ignored here
                          let e = this.else
                      Severity: Minor
                      Found in lib/compile/codegen/index.ts - About 2 hrs 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 funcKeywordCode has 50 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      export function funcKeywordCode(cxt: KeywordCxt, def: FuncKeywordDefinition): void {
                        const {gen, keyword, schema, parentSchema, $data, it} = cxt
                        checkAsyncKeyword(it, def)
                        const validate =
                          !$data && def.compile ? def.compile.call(it.self, schema, parentSchema, it) : def.validate
                      Severity: Minor
                      Found in lib/compile/validate/keyword.ts - About 2 hrs to fix

                        Function code has 48 lines of code (exceeds 25 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 1 hr to fix

                          Function getSchemaRefs has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          export function getSchemaRefs(this: Ajv, schema: AnySchema, baseId: string): LocalRefs {
                            if (typeof schema == "boolean") return {}
                            const {schemaId, uriResolver} = this.opts
                            const schId = normalizeId(schema[schemaId] || baseId)
                            const baseIds: {[JsonPtr in string]?: string} = {"": schId}
                          Severity: Minor
                          Found in lib/compile/resolve.ts - About 1 hr to fix
                            Severity
                            Category
                            Status
                            Source
                            Language