fission-suite/webnative

View on GitHub
src/fs/filesystem.ts

Summary

Maintainability
F
3 days
Test Coverage

File filesystem.ts has 509 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import * as cbor from "@ipld/dag-cbor"
import * as uint8arrays from "uint8arrays"
import { CID } from "multiformats/cid"
import { SymmAlg } from "keystore-idb/lib/types.js"
import { throttle } from "throttle-debounce"
Severity: Major
Found in src/fs/filesystem.ts - About 1 day to fix

    FileSystem has 26 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class FileSystem {
    
      root: RootTree
      readonly localOnly: boolean
    
    
    Severity: Minor
    Found in src/fs/filesystem.ts - About 3 hrs to fix

      Function runOnNode has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

        async runOnNode<a>(
          path: DistinctivePath,
          isMutation: boolean,
          fn: (node: Tree | File, relPath: Path) => Promise<a>
        ): Promise<a> {
      Severity: Minor
      Found in src/fs/filesystem.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 runOnNode has 56 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        async runOnNode<a>(
          path: DistinctivePath,
          isMutation: boolean,
          fn: (node: Tree | File, relPath: Path) => Promise<a>
        ): Promise<a> {
      Severity: Major
      Found in src/fs/filesystem.ts - About 2 hrs to fix

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

          async symlink(
            args:
            { at: DirectoryPath; referringTo: DistinctivePath; name: string; username?: string }
          ): Promise<this> {
            const { at, referringTo, name } = args
        Severity: Minor
        Found in src/fs/filesystem.ts - About 1 hr to fix

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

            constructor({ root, permissions, localOnly }: ConstructorParams) {
              this.localOnly = localOnly || false
              this.proofs = {}
              this.publishHooks = []
              this.root = root
          Severity: Minor
          Found in src/fs/filesystem.ts - About 1 hr to fix

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

              async loadShare({ shareId, sharedBy }: { shareId: string; sharedBy: string }): Promise<PrivateTree> {
                const ourExchangeDid = await did.exchange()
                const theirRootDid = await did.root(sharedBy)
            
                // Share key
            Severity: Minor
            Found in src/fs/filesystem.ts - About 1 hr to fix

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

                async add(
                  path: DistinctivePath,
                  content: FileContent | SoftLink | SoftLink[] | Record<string, SoftLink>,
                  options: MutationOptions = {}
                ): Promise<this> {
              Severity: Minor
              Found in src/fs/filesystem.ts - About 1 hr to fix

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

                  async loadShare({ shareId, sharedBy }: { shareId: string; sharedBy: string }): Promise<PrivateTree> {
                    const ourExchangeDid = await did.exchange()
                    const theirRootDid = await did.root(sharedBy)
                
                    // Share key
                Severity: Minor
                Found in src/fs/filesystem.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 sharePrivate has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  async sharePrivate(paths: DistinctivePath[], { sharedBy, shareWith }: { sharedBy?: SharedBy; shareWith: string | string[] }): Promise<ShareDetails> {
                    const verifiedPaths = paths.filter(path => {
                      return pathing.isBranch(pathing.Branch.Private, path)
                    })
                
                
                Severity: Minor
                Found in src/fs/filesystem.ts - About 1 hr to fix

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

                    async sharePrivate(paths: DistinctivePath[], { sharedBy, shareWith }: { sharedBy?: SharedBy; shareWith: string | string[] }): Promise<ShareDetails> {
                      const verifiedPaths = paths.filter(path => {
                        return pathing.isBranch(pathing.Branch.Private, path)
                      })
                  
                  
                  Severity: Minor
                  Found in src/fs/filesystem.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

                  Function constructor has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                    constructor({ root, permissions, localOnly }: ConstructorParams) {
                      this.localOnly = localOnly || false
                      this.proofs = {}
                      this.publishHooks = []
                      this.root = root
                  Severity: Minor
                  Found in src/fs/filesystem.ts - About 35 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 runOnChildTree has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                    async runOnChildTree(node: Tree, relPath: Path, fn: (tree: Tree) => Promise<Tree>): Promise<Tree> {
                      let tree = node
                  
                      if (relPath.length) {
                        if (!await tree.exists(relPath)) await tree.mkdir(relPath)
                  Severity: Minor
                  Found in src/fs/filesystem.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 2 locations. Consider refactoring.
                  Open

                      await this.runOnNode(path, true, (node, relPath) => {
                        if (typeCheck.isFile(node)) {
                          throw new Error("Cannot `rm` a file you've asked permission for")
                        } else {
                          return node.rm(relPath)
                  Severity: Major
                  Found in src/fs/filesystem.ts and 1 other location - About 1 hr to fix
                  src/fs/filesystem.ts on lines 215..221

                  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

                      await this.runOnNode(path, true, (node, relPath) => {
                        if (typeCheck.isFile(node)) {
                          throw new Error("Tried to `mkdir` a file")
                        } else {
                          return node.mkdir(relPath)
                  Severity: Major
                  Found in src/fs/filesystem.ts and 1 other location - About 1 hr to fix
                  src/fs/filesystem.ts on lines 352..358

                  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

                  There are no issues that match your filters.

                  Category
                  Status