epoberezkin/ajv

View on GitHub

Showing 217 of 217 total issues

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

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

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

          Function schemaKeywords has a Cognitive Complexity of 15 (exceeds 5 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

          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 45 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            code(cxt: KeywordCxt) {
              const {gen, data, $data, schema, parentSchema, schemaCode, it} = cxt
              if (!$data && !schema) return
              const valid = gen.let("valid")
              const itemTypes = parentSchema.items ? getSchemaTypes(parentSchema.items) : []
          Severity: Minor
          Found in lib/vocabularies/validation/uniqueItems.ts - About 1 hr to fix

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

              code(cxt: KeywordCxt) {
                checkMetadata(cxt)
                const {gen, data, schema, parentSchema} = cxt
                const [valid, cond] = checkNullableObject(cxt, data)
            
            
            Severity: Minor
            Found in lib/vocabularies/jtd/discriminator.ts - About 1 hr to fix

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

              function serializeSchemaProperties(cxt: SerializeCxt, discriminator?: string): void {
                const {gen, schema, data} = cxt
                const {properties, optionalProperties} = schema
                const props = keys(properties)
                const optProps = keys(optionalProperties)
              Severity: Minor
              Found in lib/compile/jtd/serialize.ts - About 1 hr to fix

                Function serializeSchemaProperties has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                Open

                function serializeSchemaProperties(cxt: SerializeCxt, discriminator?: string): void {
                  const {gen, schema, data} = cxt
                  const {properties, optionalProperties} = schema
                  const props = keys(properties)
                  const optProps = keys(optionalProperties)
                Severity: Minor
                Found in lib/compile/jtd/serialize.ts - About 1 hr 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 3 locations. Consider refactoring.
                Open

                const error: KeywordErrorDefinition = {
                  message: ({schemaCode}) => str`must match format "${schemaCode}"`,
                  params: ({schemaCode}) => _`{format: ${schemaCode}}`,
                }
                Severity: Major
                Found in lib/vocabularies/format/format.ts and 2 other locations - About 1 hr to fix
                lib/vocabularies/validation/multipleOf.ts on lines 11..14
                lib/vocabularies/validation/pattern.ts on lines 8..11

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

                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 3 locations. Consider refactoring.
                Open

                const error: KeywordErrorDefinition = {
                  message: ({schemaCode}) => str`must match pattern "${schemaCode}"`,
                  params: ({schemaCode}) => _`{pattern: ${schemaCode}}`,
                }
                Severity: Major
                Found in lib/vocabularies/validation/pattern.ts and 2 other locations - About 1 hr to fix
                lib/vocabularies/format/format.ts on lines 23..26
                lib/vocabularies/validation/multipleOf.ts on lines 11..14

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

                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 3 locations. Consider refactoring.
                Open

                const error: KeywordErrorDefinition = {
                  message: ({schemaCode}) => str`must be multiple of ${schemaCode}`,
                  params: ({schemaCode}) => _`{multipleOf: ${schemaCode}}`,
                }
                Severity: Major
                Found in lib/vocabularies/validation/multipleOf.ts and 2 other locations - About 1 hr to fix
                lib/vocabularies/format/format.ts on lines 23..26
                lib/vocabularies/validation/pattern.ts on lines 8..11

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

                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 coerceSpecificType has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  function coerceSpecificType(t: string): void {
                    switch (t) {
                      case "string":
                        gen
                          .elseIf(_`${dataType} == "number" || ${dataType} == "boolean"`)
                Severity: Minor
                Found in lib/compile/validate/dataType.ts - About 1 hr to fix

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

                    code(cxt: KeywordCxt) {
                      const {gen, schema, parentSchema, it} = cxt
                      /* istanbul ignore if */
                      if (!Array.isArray(schema)) throw new Error("ajv implementation error")
                      if (it.opts.discriminator && parentSchema.discriminator) return
                  Severity: Minor
                  Found in lib/vocabularies/applicator/oneOf.ts - About 1 hr to fix

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

                      optimizeNames(names: UsedNames, constants: Constants): this | undefined {
                        if (!super.optimizeNames(names, constants)) return
                        this.iterable = optimizeExpr(this.iterable, names, constants)
                        return this
                      }
                    Severity: Major
                    Found in lib/compile/codegen/index.ts and 1 other location - About 1 hr to fix
                    lib/compile/codegen/index.ts on lines 290..294

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

                    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

                      optimizeNames(names: UsedNames, constants: Constants): this | undefined {
                        if (!super.optimizeNames(names, constants)) return
                        this.iteration = optimizeExpr(this.iteration, names, constants)
                        return this
                      }
                    Severity: Major
                    Found in lib/compile/codegen/index.ts and 1 other location - About 1 hr to fix
                    lib/compile/codegen/index.ts on lines 337..341

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

                    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 42 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      code(cxt: KeywordCxt) {
                        const {gen, parentSchema, it} = cxt
                        if (parentSchema.then === undefined && parentSchema.else === undefined) {
                          checkStrictMode(it, '"if" without "then" and "else" is ignored')
                        }
                    Severity: Minor
                    Found in lib/vocabularies/applicator/if.ts - About 1 hr to fix

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

                        _addVocabularies(): void {
                          super._addVocabularies()
                          draft7Vocabularies.forEach((v) => this.addVocabulary(v))
                          if (this.opts.discriminator) this.addKeyword(discriminator)
                        }
                      Severity: Major
                      Found in lib/ajv.ts and 1 other location - About 1 hr to fix
                      lib/2020.ts on lines 20..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 68.

                      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

                        _addVocabularies(): void {
                          super._addVocabularies()
                          draft2020Vocabularies.forEach((v) => this.addVocabulary(v))
                          if (this.opts.discriminator) this.addKeyword(discriminator)
                        }
                      Severity: Major
                      Found in lib/2020.ts and 1 other location - About 1 hr to fix
                      lib/ajv.ts on lines 12..16

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

                      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 getMapping has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          function getMapping(): {[T in string]?: number} {
                            const oneOfMapping: {[T in string]?: number} = {}
                            const topRequired = hasRequired(parentSchema)
                            let tagRequired = true
                            for (let i = 0; i < oneOf.length; i++) {
                      Severity: Minor
                      Found in lib/vocabularies/discriminator/index.ts - About 1 hr to fix
                        Severity
                        Category
                        Status
                        Source
                        Language