epoberezkin/ajv

View on GitHub

Showing 217 of 217 total issues

File core.ts has 765 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 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 code has a Cognitive Complexity of 37 (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 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

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

          const def: CodeKeywordDefinition = {
            keyword: ["maxItems", "minItems"],
            type: "array",
            schemaType: "number",
            $data: true,
          Severity: Major
          Found in lib/vocabularies/validation/limitItems.ts and 1 other location - About 5 hrs to fix
          lib/vocabularies/validation/limitProperties.ts on lines 13..24

          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 137.

          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

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

          const def: CodeKeywordDefinition = {
            keyword: ["maxProperties", "minProperties"],
            type: "object",
            schemaType: "number",
            $data: true,
          Severity: Major
          Found in lib/vocabularies/validation/limitProperties.ts and 1 other location - About 5 hrs to fix
          lib/vocabularies/validation/limitItems.ts on lines 13..24

          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 137.

          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

          Further Reading

          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

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                  if (it.props !== true) {
                    if (schEvaluated && !schEvaluated.dynamicProps) {
                      if (schEvaluated.props !== undefined) {
                        it.props = mergeEvaluated.props(gen, schEvaluated.props, it.props)
                      }
              Severity: Major
              Found in lib/vocabularies/core/ref.ts and 1 other location - About 4 hrs to fix
              lib/vocabularies/core/ref.ts on lines 116..125

              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 124.

              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

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                  if (it.items !== true) {
                    if (schEvaluated && !schEvaluated.dynamicItems) {
                      if (schEvaluated.items !== undefined) {
                        it.items = mergeEvaluated.items(gen, schEvaluated.items, it.items)
                      }
              Severity: Major
              Found in lib/vocabularies/core/ref.ts and 1 other location - About 4 hrs to fix
              lib/vocabularies/core/ref.ts on lines 106..115

              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 124.

              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

              Further Reading

              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

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                    S extends {
                        properties: Record<string, unknown>
                        optionalProperties?: Record<string, unknown>
                        additionalProperties?: boolean
                      }
              Severity: Major
              Found in lib/types/jtd-schema.ts and 1 other location - About 4 hrs to fix
              lib/types/jtd-schema.ts on lines 246..268

              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 115.

              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

              Further Reading

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                    : S extends {
                        properties?: Record<string, unknown>
                        optionalProperties: Record<string, unknown>
                        additionalProperties?: boolean
                      }
              Severity: Major
              Found in lib/types/jtd-schema.ts and 1 other location - About 4 hrs to fix
              lib/types/jtd-schema.ts on lines 235..268

              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 115.

              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

              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
                Severity
                Category
                Status
                Source
                Language