epoberezkin/ajv

View on GitHub

Showing 217 of 217 total issues

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

const error: KeywordErrorDefinition = {
  message({keyword, schemaCode}) {
    const comp = keyword === "maxItems" ? "more" : "fewer"
    return str`must NOT have ${comp} than ${schemaCode} items`
  },
Severity: Major
Found in lib/vocabularies/validation/limitItems.ts and 2 other locations - About 3 hrs to fix
lib/vocabularies/validation/limitLength.ts on lines 7..13
lib/vocabularies/validation/limitProperties.ts on lines 5..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 99.

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

export {
  Format,
  FormatDefinition,
  AsyncFormatDefinition,
  KeywordDefinition,
Severity: Major
Found in lib/jtd.ts and 2 other locations - About 3 hrs to fix
lib/ajv.ts on lines 40..60
lib/core.ts on lines 1..21

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

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({keyword, schemaCode}) {
    const comp = keyword === "maxLength" ? "more" : "fewer"
    return str`must NOT have ${comp} than ${schemaCode} characters`
  },
Severity: Major
Found in lib/vocabularies/validation/limitLength.ts and 2 other locations - About 3 hrs to fix
lib/vocabularies/validation/limitItems.ts on lines 5..11
lib/vocabularies/validation/limitProperties.ts on lines 5..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 99.

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

export {
  Format,
  FormatDefinition,
  AsyncFormatDefinition,
  KeywordDefinition,
Severity: Major
Found in lib/ajv.ts and 2 other locations - About 3 hrs to fix
lib/core.ts on lines 1..21
lib/jtd.ts on lines 101..121

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

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

export {
  Format,
  FormatDefinition,
  AsyncFormatDefinition,
  KeywordDefinition,
Severity: Major
Found in lib/core.ts and 2 other locations - About 3 hrs to fix
lib/ajv.ts on lines 40..60
lib/jtd.ts on lines 101..121

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

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({keyword, schemaCode}) {
    const comp = keyword === "maxProperties" ? "more" : "fewer"
    return str`must NOT have ${comp} than ${schemaCode} properties`
  },
Severity: Major
Found in lib/vocabularies/validation/limitProperties.ts and 2 other locations - About 3 hrs to fix
lib/vocabularies/validation/limitItems.ts on lines 5..11
lib/vocabularies/validation/limitLength.ts on lines 7..13

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

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 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 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 76 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 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

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

      export {
        Format,
        FormatDefinition,
        AsyncFormatDefinition,
        KeywordDefinition,
      Severity: Major
      Found in lib/2019.ts and 1 other location - About 2 hrs to fix
      lib/2020.ts on lines 46..65

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

      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

      export {
        Format,
        FormatDefinition,
        AsyncFormatDefinition,
        KeywordDefinition,
      Severity: Major
      Found in lib/2020.ts and 1 other location - About 2 hrs to fix
      lib/2019.ts on lines 52..71

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

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

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