epoberezkin/ajv

View on GitHub

Showing 217 of 217 total issues

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

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

    function getSerialize(gen: CodeGen, sch: SchemaEnv): Code {
      return sch.serialize
        ? gen.scopeValue("serialize", {ref: sch.serialize})
        : _`${gen.scopeValue("wrapper", {ref: sch})}.serialize`
    }
    Severity: Major
    Found in lib/compile/jtd/serialize.ts and 1 other location - About 2 hrs to fix
    lib/compile/jtd/parse.ts on lines 352..356

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

    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

    function getParser(gen: CodeGen, sch: SchemaEnv): Code {
      return sch.parse
        ? gen.scopeValue("parse", {ref: sch.parse})
        : _`${gen.scopeValue("wrapper", {ref: sch})}.parse`
    }
    Severity: Major
    Found in lib/compile/jtd/parse.ts and 1 other location - About 2 hrs to fix
    lib/compile/jtd/serialize.ts on lines 246..250

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

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

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

        const error: KeywordErrorDefinition = {
          message: ({params: {len}}) => str`must NOT have more than ${len} items`,
          params: ({params: {len}}) => _`{limit: ${len}}`,
        }
        Severity: Major
        Found in lib/vocabularies/unevaluated/unevaluatedItems.ts and 3 other locations - About 2 hrs to fix
        lib/vocabularies/applicator/additionalItems.ts on lines 13..16
        lib/vocabularies/applicator/items2020.ts on lines 15..18
        lib/vocabularies/validation/required.ts on lines 19..22

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

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

        const error: KeywordErrorDefinition = {
          message: ({params: {len}}) => str`must NOT have more than ${len} items`,
          params: ({params: {len}}) => _`{limit: ${len}}`,
        }
        Severity: Major
        Found in lib/vocabularies/applicator/items2020.ts and 3 other locations - About 2 hrs to fix
        lib/vocabularies/applicator/additionalItems.ts on lines 13..16
        lib/vocabularies/unevaluated/unevaluatedItems.ts on lines 13..16
        lib/vocabularies/validation/required.ts on lines 19..22

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

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

        const error: KeywordErrorDefinition = {
          message: ({params: {missingProperty}}) => str`must have required property '${missingProperty}'`,
          params: ({params: {missingProperty}}) => _`{missingProperty: ${missingProperty}}`,
        }
        Severity: Major
        Found in lib/vocabularies/validation/required.ts and 3 other locations - About 2 hrs to fix
        lib/vocabularies/applicator/additionalItems.ts on lines 13..16
        lib/vocabularies/applicator/items2020.ts on lines 15..18
        lib/vocabularies/unevaluated/unevaluatedItems.ts on lines 13..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 82.

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

        const error: KeywordErrorDefinition = {
          message: ({params: {len}}) => str`must NOT have more than ${len} items`,
          params: ({params: {len}}) => _`{limit: ${len}}`,
        }
        Severity: Major
        Found in lib/vocabularies/applicator/additionalItems.ts and 3 other locations - About 2 hrs to fix
        lib/vocabularies/applicator/items2020.ts on lines 15..18
        lib/vocabularies/unevaluated/unevaluatedItems.ts on lines 13..16
        lib/vocabularies/validation/required.ts on lines 19..22

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

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

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

                _addDefaultMetaSchema(): void {
                  super._addDefaultMetaSchema()
                  const {$data, meta} = this.opts
                  if (!meta) return
                  addMetaSchema2019.call(this, $data)
              Severity: Major
              Found in lib/2019.ts and 1 other location - About 2 hrs to fix
              lib/2020.ts on lines 26..32

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

              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

                _addDefaultMetaSchema(): void {
                  super._addDefaultMetaSchema()
                  const {$data, meta} = this.opts
                  if (!meta) return
                  addMetaSchema2020.call(this, $data)
              Severity: Major
              Found in lib/2020.ts and 1 other location - About 2 hrs to fix
              lib/2019.ts on lines 32..38

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

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