epoberezkin/ajv

View on GitHub

Showing 215 of 215 total issues

Avoid too many return statements within this function.
Open

    return new SchemaEnv({schema, schemaId, root, baseId})
Severity: Major
Found in lib/compile/index.ts - About 30 mins to fix

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

      render({_n}: CGOptions): string {
        return `throw ${this.error};` + _n
      }
    Severity: Minor
    Found in lib/compile/codegen/index.ts and 2 other locations - About 30 mins to fix
    lib/compile/codegen/index.ts on lines 115..117
    lib/compile/codegen/index.ts on lines 151..153

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

    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.assign(fType, _`${fDef}.type || "string"`).assign(format, _`${fDef}.validate`),
    Severity: Minor
    Found in lib/vocabularies/format/format.ts and 1 other location - About 30 mins to fix
    lib/compile/validate/dataType.ts on lines 69..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 45.

    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

    Avoid too many return statements within this function.
    Open

        if (b[0] === '"') return a.slice(0, -1) + b.slice(1)
    Severity: Major
    Found in lib/compile/codegen/code.ts - About 30 mins to fix

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

        render({_n}: CGOptions): string {
          return `${this.label}:` + _n
        }
      Severity: Minor
      Found in lib/compile/codegen/index.ts and 2 other locations - About 30 mins to fix
      lib/compile/codegen/index.ts on lines 137..139
      lib/compile/codegen/index.ts on lines 151..153

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

      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 assignDefaults has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      export function assignDefaults(it: SchemaObjCxt, ty?: string): void {
        const {properties, items} = it.schema
        if (ty === "object" && properties) {
          for (const key in properties) {
            assignDefault(it, key, properties[key].default)
      Severity: Minor
      Found in lib/compile/validate/defaults.ts - About 25 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 hasRef has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      export function hasRef(schema: AnySchemaObject): boolean {
        for (const key in schema) {
          let sch: AnySchemaObject
          if (key === "ref" || (typeof (sch = schema[key]) == "object" && hasRef(sch))) return true
        }
      Severity: Minor
      Found in lib/vocabularies/jtd/ref.ts - About 25 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 addRule has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      function addRule(
        this: Ajv,
        keyword: string,
        definition?: AddedKeywordDefinition,
        dataType?: JSONType
      Severity: Minor
      Found in lib/core.ts - About 25 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 checkKeywordTypes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      function checkKeywordTypes(it: SchemaObjCxt, ts: JSONType[]): void {
        const rules = it.self.RULES.all
        for (const keyword in rules) {
          const rule = rules[keyword]
          if (typeof rule == "object" && shouldUseRule(it.schema, rule)) {
      Severity: Minor
      Found in lib/compile/validate/index.ts - About 25 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 optimize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      function optimize(expr: CodeItem[]): void {
        let i = 1
        while (i < expr.length - 1) {
          if (expr[i] === plus) {
            const res = mergeExprItems(expr[i - 1], expr[i + 1])
      Severity: Minor
      Found in lib/compile/codegen/code.ts - About 25 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 parseJson has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      export function parseJson(s: string, pos: number): unknown {
        let endPos: number | undefined
        parseJson.message = undefined
        let matches: RegExpExecArray | null
        if (pos) s = s.slice(pos)
      Severity: Minor
      Found in lib/runtime/parseJson.ts - About 25 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 removeSchema has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        removeSchema(schemaKeyRef?: AnySchema | string | RegExp): Ajv {
          if (schemaKeyRef instanceof RegExp) {
            this._removeAllSchemas(this.schemas, schemaKeyRef)
            this._removeAllSchemas(this.refs, schemaKeyRef)
            return this
      Severity: Minor
      Found in lib/core.ts - About 25 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 object has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        object(...keyValues: [Name | string, SafeExpr | string][]): _Code {
          const code: CodeItem[] = ["{"]
          for (const [key, value] of keyValues) {
            if (code.length > 1) code.push(",")
            code.push(key)
      Severity: Minor
      Found in lib/compile/codegen/index.ts - About 25 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 extraErrorProps has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      function extraErrorProps(
        cxt: KeywordErrorCxt,
        {params, message}: KeywordErrorDefinition,
        keyValues: [Name, SafeExpr | string][]
      ): void {
      Severity: Minor
      Found in lib/compile/errors.ts - About 25 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 schemaRefOrVal has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      export function schemaRefOrVal(
        {topSchemaRef, schemaPath}: SchemaObjCxt,
        schema: unknown,
        keyword: string,
        $data?: string | false
      Severity: Minor
      Found in lib/compile/util.ts - About 25 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