epoberezkin/ajv

View on GitHub

Showing 130 of 215 total issues

File core.ts has 766 lines of code (exceeds 250 allowed). Consider refactoring.
Open

export {
  Format,
  FormatDefinition,
  AsyncFormatDefinition,
  KeywordDefinition,
Severity: Major
Found in lib/core.ts - About 1 day to fix

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

    import type {ScopeValueSets, NameValue, ValueScope, ValueScopeName} from "./scope"
    import {_, nil, _Code, Code, Name, UsedNames, CodeItem, addCodeArg, _CodeOrName} from "./code"
    import {Scope, varKinds} from "./scope"
    
    export {_, str, strConcat, nil, getProperty, stringify, regexpCode, Name, Code} from "./code"
    Severity: Major
    Found in lib/compile/codegen/index.ts - About 1 day to fix

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

      import type {
        AddedKeywordDefinition,
        AnySchema,
        AnySchemaObject,
        KeywordErrorCxt,
      Severity: Major
      Found in lib/compile/validate/index.ts - About 1 day to fix

        Function standaloneCode has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
        Open

        function standaloneCode(
          ajv: AjvCore,
          refsOrFunc?: {[K in string]?: string} | AnyValidateFunction
        ): string {
          if (!ajv.opts.code.source) {
        Severity: Minor
        Found in lib/standalone/index.ts - About 6 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 41 (exceeds 5 allowed). Consider refactoring.
        Open

          code(cxt: KeywordCxt) {
            const {gen, data, schema, parentSchema, it} = cxt
            const {oneOf} = parentSchema
            if (!it.opts.discriminator) {
              throw new Error("discriminator: requires discriminator option")
        Severity: Minor
        Found in lib/vocabularies/discriminator/index.ts - About 6 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 40 (exceeds 5 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: Minor
        Found in lib/vocabularies/format/format.ts - About 6 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

        CodeGen has 43 functions (exceeds 20 allowed). Consider refactoring.
        Open

        export class CodeGen {
          readonly _scope: Scope
          readonly _extScope: ValueScope
          readonly _values: ScopeValueSets = {}
          private readonly _nodes: ParentNode[]
        Severity: Minor
        Found in lib/compile/codegen/index.ts - About 5 hrs to fix

          Function validateProperties has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
          Open

          export function validateProperties(cxt: KeywordCxt): void {
            checkMetadata(cxt)
            const {gen, data, parentSchema, it} = cxt
            const {additionalProperties, nullable} = parentSchema
            if (it.jtdDiscriminator && nullable) throw new Error("JTD: nullable inside discriminator mapping")
          Severity: Minor
          Found in lib/vocabularies/jtd/properties.ts - About 5 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 parse.ts has 373 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import type Ajv from "../../core"
          import type {SchemaObject} from "../../types"
          import {jtdForms, JTDForm, SchemaObjectMap} from "./types"
          import {SchemaEnv, getCompilingSchema} from ".."
          import {_, str, and, or, nil, not, CodeGen, Code, Name, SafeExpr} from "../codegen"
          Severity: Minor
          Found in lib/compile/jtd/parse.ts - About 4 hrs to fix

            Function parseJsonString has a Cognitive Complexity of 33 (exceeds 5 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: Minor
            Found in lib/runtime/parseJson.ts - About 4 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 validateProperties has 112 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export function validateProperties(cxt: KeywordCxt): void {
              checkMetadata(cxt)
              const {gen, data, parentSchema, it} = cxt
              const {additionalProperties, nullable} = parentSchema
              if (it.jtdDiscriminator && nullable) throw new Error("JTD: nullable inside discriminator mapping")
            Severity: Major
            Found in lib/vocabularies/jtd/properties.ts - About 4 hrs to fix

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

                code(cxt) {
                  const {gen, schema, parentSchema, data, errsCount, it} = cxt
                  /* istanbul ignore if */
                  if (!errsCount) throw new Error("ajv implementation error")
                  const {allErrors, opts} = it
              Severity: Minor
              Found in lib/vocabularies/applicator/additionalProperties.ts - About 4 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 callRef has a Cognitive Complexity of 27 (exceeds 5 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: Minor
              Found in lib/vocabularies/core/ref.ts - About 3 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 compileSchema has 82 lines of code (exceeds 25 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: Major
              Found in lib/compile/index.ts - About 3 hrs to fix

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

                  code(cxt: KeywordCxt) {
                    const {gen, data, schema, parentSchema, it} = cxt
                    const {oneOf} = parentSchema
                    if (!it.opts.discriminator) {
                      throw new Error("discriminator: requires discriminator option")
                Severity: Major
                Found in lib/vocabularies/discriminator/index.ts - About 3 hrs to fix

                  Function funcKeywordCode has a Cognitive Complexity of 22 (exceeds 5 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 3 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 parseJsonNumber has a Cognitive Complexity of 22 (exceeds 5 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: Minor
                  Found in lib/runtime/parseJson.ts - About 3 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 22 (exceeds 5 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: Minor
                  Found in lib/vocabularies/applicator/contains.ts - About 3 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 standaloneCode has 75 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function standaloneCode(
                    ajv: AjvCore,
                    refsOrFunc?: {[K in string]?: string} | AnyValidateFunction
                  ): string {
                    if (!ajv.opts.code.source) {
                  Severity: Major
                  Found in lib/standalone/index.ts - About 3 hrs to fix

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

                      code(cxt) {
                        const {gen, schema, parentSchema, data, errsCount, it} = cxt
                        /* istanbul ignore if */
                        if (!errsCount) throw new Error("ajv implementation error")
                        const {allErrors, opts} = it
                    Severity: Major
                    Found in lib/vocabularies/applicator/additionalProperties.ts - About 2 hrs to fix
                      Severity
                      Category
                      Status
                      Source
                      Language