epoberezkin/ajv

View on GitHub

Showing 215 of 215 total issues

Function getErrorPath has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

export function getErrorPath(
  dataProp: Name | string | number,
  dataPropType?: Type,
  jsPropertySyntax?: boolean
): Code | string {
Severity: Minor
Found in lib/compile/util.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 validateKeywordUsage has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

export function validateKeywordUsage(
  {schema, opts, self, errSchemaPath}: SchemaObjCxt,
  def: AddedKeywordDefinition,
  keyword: string
): void {
Severity: Minor
Found in lib/compile/validate/keyword.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 a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  code(cxt: KeywordCxt) {
    const {gen, data, $data, schema, schemaCode, it} = cxt
    if (!$data && schema.length === 0) throw new Error("enum must have non-empty array")
    const useLoop = schema.length >= it.opts.loopEnum
    let eql: Name | undefined
Severity: Minor
Found in lib/vocabularies/validation/enum.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 a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  code(cxt: KeywordCxt) {
    checkMetadata(cxt)
    const {data, schema, parentSchema, it} = cxt
    let cond: Code
    switch (schema) {
Severity: Minor
Found in lib/vocabularies/jtd/type.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 addKeyword has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  addKeyword(
    kwdOrDef: string | KeywordDefinition,
    def?: KeywordDefinition // deprecated
  ): Ajv {
    let keyword: string | 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

Function hasRef has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

function hasRef(schema: AnySchemaObject): boolean {
  for (const key in schema) {
    if (REF_KEYWORDS.has(key)) return true
    const sch = schema[key]
    if (Array.isArray(sch) && sch.some(hasRef)) return true
Severity: Minor
Found in lib/compile/resolve.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 invalid$data has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  invalid$data(): Code {
    const {gen, schemaCode, schemaType, def, it} = this
    return or(wrong$DataType(), invalid$DataSchema())

    function wrong$DataType(): Code {
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 validateOneOf has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    function validateOneOf(): void {
      schArr.forEach((sch: AnySchema, i: number) => {
        let schCxt: SchemaCxt | undefined
        if (alwaysValidSchema(it, sch)) {
          gen.var(schValid, true)
Severity: Minor
Found in lib/vocabularies/applicator/oneOf.ts - About 1 hr to fix

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

      code(cxt: KeywordCxt) {
        const {gen, data, $data, schema, schemaCode, it} = cxt
        if (!$data && schema.length === 0) throw new Error("enum must have non-empty array")
        const useLoop = schema.length >= it.opts.loopEnum
        let eql: Name | undefined
    Severity: Minor
    Found in lib/vocabularies/validation/enum.ts - About 1 hr to fix

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

      export function dynamicRef(cxt: KeywordCxt, ref: string): void {
        const {gen, keyword, it} = cxt
        if (ref[0] !== "#") throw new Error(`"${keyword}" only supports hash fragment reference`)
        const anchor = ref.slice(1)
        if (it.allErrors) {
      Severity: Minor
      Found in lib/vocabularies/dynamic/dynamicRef.ts - About 1 hr to fix

        Function schemaKeywords has 26 lines of code (exceeds 25 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

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

          export function validateUnion(cxt: KeywordCxt): void {
            const {gen, schema, keyword, it} = cxt
            /* istanbul ignore if */
            if (!Array.isArray(schema)) throw new Error("ajv implementation error")
            const alwaysValid = schema.some((sch: AnySchema) => alwaysValidSchema(it, sch))
          Severity: Minor
          Found in lib/vocabularies/code.ts - About 1 hr to fix

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

                  if (schema === false) {
                    cxt.setParams({unevaluatedProperty: key})
                    cxt.error()
                    if (!allErrors) gen.break()
                    return
            Severity: Major
            Found in lib/vocabularies/unevaluated/unevaluatedProperties.ts and 1 other location - About 1 hr to fix
            lib/vocabularies/applicator/additionalProperties.ts on lines 78..83

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

            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 (schema === false) {
                    cxt.setParams({additionalProperty: key})
                    cxt.error()
                    if (!allErrors) gen.break()
                    return
            Severity: Major
            Found in lib/vocabularies/applicator/additionalProperties.ts and 1 other location - About 1 hr to fix
            lib/vocabularies/unevaluated/unevaluatedProperties.ts on lines 50..55

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

            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 9 (exceeds 5 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 55 mins 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 validateSchema has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              validateSchema(schema: AnySchema, throwOrLogError?: boolean): boolean | Promise<unknown> {
                if (typeof schema == "boolean") return true
                let $schema: string | AnySchemaObject | undefined
                $schema = schema.$schema
                if ($schema !== undefined && typeof $schema != "string") {
            Severity: Minor
            Found in lib/core.ts - About 55 mins 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 9 (exceeds 5 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 55 mins 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 _removeAllSchemas has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              private _removeAllSchemas(schemas: {[Ref in string]?: SchemaEnv | string}, regex?: RegExp): void {
                for (const keyRef in schemas) {
                  const sch = schemas[keyRef]
                  if (!regex || regex.test(keyRef)) {
                    if (typeof sch == "string") {
            Severity: Minor
            Found in lib/core.ts - About 55 mins 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 countKeys has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

            function countKeys(schema: AnySchemaObject): number {
              let count = 0
              for (const key in schema) {
                if (key === "$ref") return Infinity
                count++
            Severity: Minor
            Found in lib/compile/resolve.ts - About 55 mins 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 extendSubschemaData has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

            export function extendSubschemaData(
              subschema: SubschemaContext,
              it: SchemaObjCxt,
              {dataProp, dataPropType: dpType, data, dataTypes, propertyName}: SubschemaArgs
            ): void {
            Severity: Minor
            Found in lib/compile/validate/subschema.ts - About 55 mins 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