lipp/node-jet

View on GitHub

Showing 29 of 29 total issues

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

    if (this.config.wsPort || this.config.server) {
      this.wsServer = new WebsocketServer(this.config)
      this.wsServer.addListener('connection', (sock: Socket) => {
        const jsonRpc = new JsonRPC(this.log, { batches: this.batches }, sock)
        this.connections[sock.id] = jsonRpc
Severity: Major
Found in src/2_jsonrpc/server.ts and 1 other location - About 7 hrs to fix
src/2_jsonrpc/server.ts on lines 28..40

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

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 (this.config.tcpPort) {
      this.tcpServer = new TCPServer(this.config)
      this.tcpServer.addListener('connection', (sock: Socket) => {
        const jsonRpc = new JsonRPC(this.log, { batches: this.batches }, sock)
        this.connections[sock.id] = jsonRpc
Severity: Major
Found in src/2_jsonrpc/server.ts and 1 other location - About 7 hrs to fix
src/2_jsonrpc/server.ts on lines 41..53

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

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

      newPeer.addListener(
        'set',
        (peer: JsonRPC, id: string, params: PathParams) =>
          this.forward('set', peer.user, params)
            .then((res) => newPeer.respond(id, res, true))
Severity: Major
Found in src/3_jet/daemon/index.ts and 1 other location - About 3 hrs to fix
src/3_jet/daemon/index.ts on lines 341..348

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

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

      newPeer.addListener(
        'call',
        (peer: JsonRPC, id: string, params: PathParams) =>
          this.forward('call', peer.user, params)
            .then((res) => newPeer.respond(id, res, true))
Severity: Major
Found in src/3_jet/daemon/index.ts and 1 other location - About 3 hrs to fix
src/3_jet/daemon/index.ts on lines 333..340

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

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

File index.ts has 305 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict'

import { Logger, logger } from '../log.js'
import {
  AddRequest,
Severity: Minor
Found in src/3_jet/daemon/index.ts - About 3 hrs to fix

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

    const containsOneOf = (whatArray: string[]) => {
      return (path: string) => {
        let i
        for (i = 0; i < whatArray.length; i = i + 1) {
          if (path.indexOf(whatArray[i]) !== -1) {
    Severity: Major
    Found in src/3_jet/daemon/path_matcher.ts and 1 other location - About 3 hrs to fix
    src/3_jet/daemon/path_matcher.ts on lines 11..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 99.

    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

    const containsAllOf = (whatArray: string[]) => {
      return (path: string) => {
        let i
        for (i = 0; i < whatArray.length; i = i + 1) {
          if (path.indexOf(whatArray[i]) === -1) {
    Severity: Major
    Found in src/3_jet/daemon/path_matcher.ts and 1 other location - About 3 hrs to fix
    src/3_jet/daemon/path_matcher.ts on lines 23..33

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

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

    export const castMessage = <T extends MethodRequest>(msg: MethodRequest): T => {
      if (!('method' in msg)) throw new invalidRequest('No method')
      const method = msg.method as EventType
      const params = msg.params
      switch (method) {
    Severity: Minor
    Found in src/3_jet/messages.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

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

        occupied: [{ req: addRequest('foo'), res: {} },{ req: addRequest('foo'), throws: {
          "code":-32602,
          "message":"A State/Method with the same path has already been added",
          "data":{
            "name":"jet.Occupied",
    Severity: Major
    Found in bench/validation.js and 1 other location - About 2 hrs to fix
    bench/validation.js on lines 46..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 78.

    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

          notfound: [{ req: removeRequest('foo'), res: {} },{ req: removeRequest('foo'), throws: {
            "code":-32602,
            "message":"No State/Method matching the specified path",
            "data":{
              "name":"jet.NotFound",
    Severity: Major
    Found in bench/validation.js and 1 other location - About 2 hrs to fix
    bench/validation.js on lines 37..45

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

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

    export const castMessage = <T extends MethodRequest>(msg: MethodRequest): T => {
      if (!('method' in msg)) throw new invalidRequest('No method')
      const method = msg.method as EventType
      const params = msg.params
      switch (method) {
    Severity: Minor
    Found in src/3_jet/messages.ts - About 1 hr to fix

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

        constructor(port: number | Socket, ip = '') {
          super()
          if (port instanceof Socket) {
            this.socket = port
          } else {
      Severity: Minor
      Found in src/1_socket/message-socket.ts - About 1 hr to fix

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

          errorCb = (id: string, error: JsonRPCError) => {
            if (id in this.openRequests) {
              this.openRequests[id].reject(error)
              delete this.openRequests[id]
            }
        Severity: Major
        Found in src/2_jsonrpc/index.ts and 1 other location - About 1 hr to fix
        src/2_jsonrpc/index.ts on lines 269..274

        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

          successCb = (id: string, result: ValueType) => {
            if (id in this.openRequests) {
              this.openRequests[id].resolve(result)
              delete this.openRequests[id]
            }
        Severity: Major
        Found in src/2_jsonrpc/index.ts and 1 other location - About 1 hr to fix
        src/2_jsonrpc/index.ts on lines 275..280

        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 3 locations. Consider refactoring.
        Open

          ascending = () => {
            if (!this.message.sort) {
              this.message.sort = {}
            }
            this.message.sort.descending = false
        Severity: Major
        Found in src/3_jet/peer/fetcher.ts and 2 other locations - About 1 hr to fix
        src/3_jet/peer/fetcher.ts on lines 55..61
        src/3_jet/peer/fetcher.ts on lines 71..77

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

        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

          descending = () => {
            if (!this.message.sort) {
              this.message.sort = {}
            }
            this.message.sort.descending = true
        Severity: Major
        Found in src/3_jet/peer/fetcher.ts and 2 other locations - About 1 hr to fix
        src/3_jet/peer/fetcher.ts on lines 55..61
        src/3_jet/peer/fetcher.ts on lines 63..69

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

        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

          differential = () => {
            if (!this.message.sort) {
              this.message.sort = {}
            }
            this.message.sort.asArray = false
        Severity: Major
        Found in src/3_jet/peer/fetcher.ts and 2 other locations - About 1 hr to fix
        src/3_jet/peer/fetcher.ts on lines 63..69
        src/3_jet/peer/fetcher.ts on lines 71..77

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

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

          listen() {
            this.wsServer = new WsServer({
              port: this.config.wsPort,
              server: this.config.server,
              path: this.config.wsPath,
        Severity: Minor
        Found in src/1_socket/wsserver.ts - About 1 hr to fix

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

          export const createPathMatcher = (options: FetchParams) => {
            if (!options.path) {
              return () => true
            }
            const po = options.path
          Severity: Minor
          Found in src/3_jet/daemon/path_matcher.ts - About 1 hr to fix

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

                if(!_.isEqual(ex,req.throws)){
                  throw new Error(`\n Expected:${JSON.stringify(ex)} \n Received ${JSON.stringify(req.throws)} `)
                 }
            Severity: Major
            Found in bench/validation.js and 1 other location - About 1 hr to fix
            bench/validation.js on lines 66..68

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

            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

            Severity
            Category
            Status
            Source
            Language