epoberezkin/ajv

View on GitHub

Showing 217 of 217 total issues

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

  gen.if(_`${it.evaluated}.dynamicProps`, () => gen.assign(_`${it.evaluated}.props`, _`undefined`))
Severity: Major
Found in lib/compile/validate/index.ts and 1 other location - About 1 hr to fix
lib/compile/validate/index.ts on lines 111..111

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

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

  gen.if(_`${it.evaluated}.dynamicItems`, () => gen.assign(_`${it.evaluated}.items`, _`undefined`))
Severity: Major
Found in lib/compile/validate/index.ts and 1 other location - About 1 hr to fix
lib/compile/validate/index.ts on lines 110..110

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

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 13 (exceeds 5 allowed). Consider refactoring.
Open

  code(cxt: KeywordCxt) {
    const {gen, schema, parentSchema, data, it} = cxt
    if (it.opts.removeAdditional === "all" && parentSchema.additionalProperties === undefined) {
      apDef.code(new KeywordCxt(it, apDef, "additionalProperties"))
    }
Severity: Minor
Found in lib/vocabularies/applicator/properties.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 parseType has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

function parseType(cxt: ParseCxt): void {
  const {gen, schema, data, self} = cxt
  switch (schema.type) {
    case "boolean":
      parseBoolean(cxt)
Severity: Minor
Found in lib/compile/jtd/parse.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 parseType has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function parseType(cxt: ParseCxt): void {
  const {gen, schema, data, self} = cxt
  switch (schema.type) {
    case "boolean":
      parseBoolean(cxt)
Severity: Minor
Found in lib/compile/jtd/parse.ts - About 1 hr to fix

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

      code(cxt: KeywordCxt) {
        const {gen, schema, parentSchema, data, it} = cxt
        if (it.opts.removeAdditional === "all" && parentSchema.additionalProperties === undefined) {
          apDef.code(new KeywordCxt(it, apDef, "additionalProperties"))
        }
    Severity: Minor
    Found in lib/vocabularies/applicator/properties.ts - About 1 hr to fix

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

      export default function compileSerializer(
        this: Ajv,
        sch: SchemaEnv,
        definitions: SchemaObjectMap
      ): SchemaEnv {
      Severity: Minor
      Found in lib/compile/jtd/serialize.ts - About 1 hr to fix

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

          params: ({params: {min, max}}) =>
            max === undefined ? _`{minContains: ${min}}` : _`{minContains: ${min}, maxContains: ${max}}`,
        Severity: Major
        Found in lib/vocabularies/applicator/contains.ts and 1 other location - About 1 hr to fix
        lib/vocabularies/applicator/contains.ts on lines 18..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 66.

        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

          message: ({params: {min, max}}) =>
            max === undefined
              ? str`must contain at least ${min} valid item(s)`
              : str`must contain at least ${min} and no more than ${max} valid item(s)`,
        Severity: Major
        Found in lib/vocabularies/applicator/contains.ts and 1 other location - About 1 hr to fix
        lib/vocabularies/applicator/contains.ts on lines 22..23

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

        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

          addKeyword(...args: Parameters<typeof Ajv.prototype.addKeyword>): AjvPack {
            this.ajv.addKeyword.call(this.ajv, ...args)
            return this
          }
        Severity: Major
        Found in lib/standalone/instance.ts and 1 other location - About 1 hr to fix
        lib/standalone/instance.ts on lines 27..30

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

        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

          addSchema(...args: Parameters<typeof Ajv.prototype.addSchema>): AjvPack {
            this.ajv.addSchema.call(this.ajv, ...args)
            return this
          }
        Severity: Major
        Found in lib/standalone/instance.ts and 1 other location - About 1 hr to fix
        lib/standalone/instance.ts on lines 32..35

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

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

            function validateFormat(): void {
              const formatDef: AddedFormat | undefined = self.formats[schema]
              if (!formatDef) {
                unknownFormat()
                return
        Severity: Minor
        Found in lib/vocabularies/format/format.ts - About 1 hr to fix

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

          export default function compileParser(
            this: Ajv,
            sch: SchemaEnv,
            definitions: SchemaObjectMap
          ): SchemaEnv {
          Severity: Minor
          Found in lib/compile/jtd/parse.ts - About 1 hr to fix

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

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

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

                private _compileSerializer<T>(sch: SchemaEnv): (data: T) => string {
                  compileSerializer.call(this, sch, (sch.schema as AnySchemaObject).definitions || {})
                  /* istanbul ignore if */
                  if (!sch.serialize) throw new Error("ajv implementation error")
                  return sch.serialize
              Severity: Major
              Found in lib/jtd.ts and 1 other location - About 1 hr to fix
              lib/jtd.ts on lines 87..92

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

              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

                private _compileParser(sch: SchemaEnv): JTDParser {
                  compileParser.call(this, sch, (sch.schema as AnySchemaObject).definitions || {})
                  /* istanbul ignore if */
                  if (!sch.parse) throw new Error("ajv implementation error")
                  return sch.parse
              Severity: Major
              Found in lib/jtd.ts and 1 other location - About 1 hr to fix
              lib/jtd.ts on lines 80..85

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

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

                code(cxt: KeywordCxt): void {
                  const {gen, schema: $ref, it} = cxt
                  const {baseId, schemaEnv: env, validateName, opts, self} = it
                  const {root} = env
                  if (($ref === "#" || $ref === "#/") && baseId === root.baseId) return callRootRef()
              Severity: Minor
              Found in lib/vocabularies/core/ref.ts - About 1 hr to fix

                Function getJsonPointer has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                function getJsonPointer(
                  this: Ajv,
                  parsedRef: URI.URIComponents,
                  {baseId, schema, root}: SchemaEnv
                ): SchemaEnv | undefined {
                Severity: Minor
                Found in lib/compile/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 _addSchema has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                  _addSchema(
                    schema: AnySchema,
                    meta?: boolean,
                    baseId?: string,
                    validateSchema = this.opts.validateSchema,
                Severity: Minor
                Found in lib/core.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 $dataMetaSchema has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                  $dataMetaSchema(metaSchema: AnySchemaObject, keywordsJsonPointers: string[]): AnySchemaObject {
                    const rules = this.RULES.all
                    metaSchema = JSON.parse(JSON.stringify(metaSchema))
                    for (const jsonPointer of keywordsJsonPointers) {
                      const segments = jsonPointer.split("/").slice(1) // first segment is an empty string
                Severity: Minor
                Found in lib/core.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

                Severity
                Category
                Status
                Source
                Language