fission-suite/webnative

View on GitHub
src/fs/v1/PrivateTree.ts

Summary

Maintainability
F
4 days
Test Coverage

File PrivateTree.ts has 392 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import * as Uint8arrays from "uint8arrays"

import * as Crypto from "../../components/crypto/implementation.js"
import * as Depot from "../../components/depot/implementation.js"
import * as History from "./PrivateHistory.js"
Severity: Minor
Found in src/fs/v1/PrivateTree.ts - About 5 hrs to fix

    PrivateTree has 23 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export default class PrivateTree extends BaseTree {
    
      crypto: Crypto.Implementation
      depot: Depot.Implementation
      manners: Manners.Implementation
    Severity: Minor
    Found in src/fs/v1/PrivateTree.ts - About 2 hrs to fix

      Function getRecurse has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        async getRecurse(
          nodeInfo: PrivateSkeletonInfo | SoftLink,
          parts: string[]
        ): Promise<PrivateTree | PrivateFile | null> {
          const [ head, ...rest ] = parts
      Severity: Minor
      Found in src/fs/v1/PrivateTree.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 getNode has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

        crypto: Crypto.Implementation,
        depot: Depot.Implementation,
        manners: Manners.Implementation,
        reference: Reference.Implementation,
        mmpt: MMPT,
      Severity: Minor
      Found in src/fs/v1/PrivateTree.ts - About 45 mins to fix

        Function getDirectChild has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          async getDirectChild(name: string): Promise<PrivateTree | PrivateFile | null> {
            let child = null
        
            if (this.children[ name ]) {
              return this.children[ name ]
        Severity: Minor
        Found in src/fs/v1/PrivateTree.ts - About 45 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

        Avoid too many return statements within this function.
        Open

            return child
        Severity: Major
        Found in src/fs/v1/PrivateTree.ts - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              if (!check.isPrivateTreeInfo(reloadedNode)) return null
          Severity: Major
          Found in src/fs/v1/PrivateTree.ts - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                if (nextChild !== undefined) return this.getRecurse(nextChild, rest)
            Severity: Major
            Found in src/fs/v1/PrivateTree.ts - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                  return reloadedNext === undefined ? null : this.getRecurse(reloadedNext, rest)
              Severity: Major
              Found in src/fs/v1/PrivateTree.ts - About 30 mins to fix

                Function resolveSoftLink has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  static async resolveSoftLink(
                    crypto: Crypto.Implementation,
                    depot: Depot.Implementation,
                    manners: Manners.Implementation,
                    reference: Reference.Implementation,
                Severity: Minor
                Found in src/fs/v1/PrivateTree.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

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

                  static async fromLatestName(
                    crypto: Crypto.Implementation,
                    depot: Depot.Implementation,
                    manners: Manners.Implementation,
                    reference: Reference.Implementation,
                Severity: Major
                Found in src/fs/v1/PrivateTree.ts and 2 other locations - About 4 hrs to fix
                src/fs/v1/PrivateTree.ts on lines 133..144
                src/fs/v1/PrivateTree.ts on lines 159..170

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

                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

                  static async fromName(
                    crypto: Crypto.Implementation,
                    depot: Depot.Implementation,
                    manners: Manners.Implementation,
                    reference: Reference.Implementation,
                Severity: Major
                Found in src/fs/v1/PrivateTree.ts and 2 other locations - About 4 hrs to fix
                src/fs/v1/PrivateTree.ts on lines 133..144
                src/fs/v1/PrivateTree.ts on lines 146..157

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

                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

                  static async fromBareNameFilter(
                    crypto: Crypto.Implementation,
                    depot: Depot.Implementation,
                    manners: Manners.Implementation,
                    reference: Reference.Implementation,
                Severity: Major
                Found in src/fs/v1/PrivateTree.ts and 2 other locations - About 4 hrs to fix
                src/fs/v1/PrivateTree.ts on lines 146..157
                src/fs/v1/PrivateTree.ts on lines 159..170

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

                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

                  async getName(): Promise<PrivateName> {
                    const { bareNameFilter, revision } = this.header
                    const revisionFilter = await namefilter.addRevision(this.crypto, bareNameFilter, this.key, revision)
                    return namefilter.toPrivateName(this.crypto, revisionFilter)
                  }
                Severity: Major
                Found in src/fs/v1/PrivateTree.ts and 1 other location - About 2 hrs to fix
                src/fs/v1/PrivateFile.ts on lines 174..178

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

                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

                  static async create(
                    crypto: Crypto.Implementation,
                    depot: Depot.Implementation,
                    manners: Manners.Implementation,
                    reference: Reference.Implementation,
                Severity: Major
                Found in src/fs/v1/PrivateTree.ts and 1 other location - About 1 hr to fix
                src/fs/v1/PrivateTree.ts on lines 172..186

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

                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

                  static async fromInfo(
                    crypto: Crypto.Implementation,
                    depot: Depot.Implementation,
                    manners: Manners.Implementation,
                    reference: Reference.Implementation,
                Severity: Major
                Found in src/fs/v1/PrivateTree.ts and 1 other location - About 1 hr to fix
                src/fs/v1/PrivateTree.ts on lines 91..119

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

                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

                  static instanceOf(obj: unknown): obj is PrivateTree {
                    return isObject(obj)
                      && hasProp(obj, "mmpt")
                      && hasProp(obj, "header")
                      && check.isPrivateTreeInfo(obj.header)
                Severity: Major
                Found in src/fs/v1/PrivateTree.ts and 1 other location - About 1 hr to fix
                src/fs/v1/PublicFile.ts on lines 53..58

                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

                async function getNode(
                  crypto: Crypto.Implementation,
                  depot: Depot.Implementation,
                  manners: Manners.Implementation,
                  reference: Reference.Implementation,
                Severity: Major
                Found in src/fs/v1/PrivateTree.ts and 1 other location - About 1 hr to fix
                src/fs/v1/PrivateTree.ts on lines 121..131

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

                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

                  static async fromBaseKey(
                    crypto: Crypto.Implementation,
                    depot: Depot.Implementation,
                    manners: Manners.Implementation,
                    reference: Reference.Implementation,
                Severity: Major
                Found in src/fs/v1/PrivateTree.ts and 1 other location - About 1 hr to fix
                src/fs/v1/PrivateTree.ts on lines 441..461

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

                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

                    const key = await this.crypto.aes.genKey(DEFAULT_AES_ALG).then(this.crypto.aes.exportKey)
                Severity: Minor
                Found in src/fs/v1/PrivateTree.ts and 1 other location - About 30 mins to fix
                src/fs/v1/PrivateTree.ts on lines 209..209

                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

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

                      const key = await this.crypto.aes.genKey(DEFAULT_AES_ALG).then(this.crypto.aes.exportKey)
                Severity: Minor
                Found in src/fs/v1/PrivateTree.ts and 1 other location - About 30 mins to fix
                src/fs/v1/PrivateTree.ts on lines 189..189

                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

                There are no issues that match your filters.

                Category
                Status