microfleet/core

View on GitHub

Showing 88 of 88 total issues

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

function getSocketIORouterAdapter(router: Router, log: Logger): (socket: Socket) => void {
  return function socketIORouterAdapter(socket: Socket): void {
    socket.onAny(async (actionName: string, params: unknown, callback: CallableFunction): Promise<void> => {
      // @todo if (callback !== undefined && typeof callback !== 'function') {
      if (typeof callback !== 'function') {
Severity: Minor
Found in packages/plugin-router-socketio/src/adapter.ts - About 1 hr to fix

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

      const reformatError = (error: any) => {
        let statusCode
        let errorMessage
    
        const { errors } = error
    Severity: Minor
    Found in packages/plugin-router-hapi/src/adapter.ts - About 1 hr to fix

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

        private handleIncomingMessages(messages: Message[]): void {
          const { unacknowledgedTracker, autoStore } = this
      
          if (!this.consumerDisconnected()) {
            this.consumer.pause(this.consumer.assignments())
      Severity: Minor
      Found in packages/plugin-kafka/src/custom/consumer-stream.ts - About 1 hr to fix

        Function processAndEmit has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

          private async processAndEmit(collection: ns.StartStopTree, event: string, priority = ConnectorsPriority): Promise<any[]> {
            const responses = []
            for (const connectorType of priority) {
              const connectors: ns.PluginConnector[] | void = collection[connectorType]
              if (!connectors) {
        Severity: Minor
        Found in packages/core/src/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 startupHandlers has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

        const startupHandlers = (
          service: Microfleet,
          nano: CouchDB.ServerScope,
          database: string,
          indices: Config['indexDefinitions'] = []
        Severity: Minor
        Found in packages/plugin-couchdb/src/couchdb.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 attachRouter has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export default function attachRouter(service: Microfleet, config: RouterHapiPluginConfig): ServerRegisterPluginObject<any> {
          return {
            plugin: {
              name: 'microfleetRouter',
              version: '1.0.0',
        Severity: Minor
        Found in packages/plugin-router-hapi/src/attach.ts - About 1 hr to fix

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

          consul.Lock.prototype._wait = function (ctx: any) {
            const retry = () => {
              utils.setTimeoutContext(() => {
                this._run(ctx)
              }, ctx, ctx.lockRetryTime)
          Severity: Minor
          Found in packages/plugin-consul/src/patch.ts - About 1 hr to fix

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

            function retrieveStrategy(request: ServiceRequest, strategies: AuthConfig['strategies']): AuthStrategyConfig {
              const { action } = request
              const { auth: authConfig } = action
            
              // for ```MicrofleetAction.auth = (request) => assert(request.param)```
            Severity: Minor
            Found in packages/plugin-router/src/lifecycle/handlers/auth.ts - About 1 hr to fix

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

                return function socketIORouterAdapter(socket: Socket): void {
                  socket.onAny(async (actionName: string, params: unknown, callback: CallableFunction): Promise<void> => {
                    // @todo if (callback !== undefined && typeof callback !== 'function') {
                    if (typeof callback !== 'function') {
                      // ignore malformed rpc call
              Severity: Minor
              Found in packages/plugin-router-socketio/src/adapter.ts - About 1 hr to fix

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

                  public addRoute(route: string, handler: ServiceAction): void {
                    const { routes, config } = this
                    let name: string = route
                
                    if (config !== undefined) {
                Severity: Minor
                Found in packages/plugin-router/src/router.ts - About 1 hr to fix

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

                    async connect() {
                      assert(!service.couchdb, 'couchdb has already been initialized')
                  
                      const db = nano.use(database)
                      const establishConnection = async () => {
                  Severity: Minor
                  Found in packages/plugin-couchdb/src/couchdb.ts - About 1 hr to fix

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

                      public addConnector(type: ns.ConnectorsTypes, handler: ns.PluginConnector, plugin?: string): void {
                        this.addHandler(CONNECTORS_PROPERTY, type, handler, plugin)
                      }
                    Severity: Major
                    Found in packages/core/src/index.ts and 1 other location - About 1 hr to fix
                    packages/core/src/index.ts on lines 327..329

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

                    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

                      public addDestructor(type: ns.ConnectorsTypes, handler: ns.PluginConnector, plugin?: string): void {
                        this.addHandler(DESTRUCTORS_PROPERTY, type, handler, plugin)
                      }
                    Severity: Major
                    Found in packages/core/src/index.ts and 1 other location - About 1 hr to fix
                    packages/core/src/index.ts on lines 317..319

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

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

                    export const transformFileToAction = (input: any, handler?: any): ServiceAction => {
                      const omitProps = ['length', 'name', 'default', '__esModule']
                      const props = Object.getOwnPropertyNames(input)
                      const action = Object.create(null)
                      for (const prop of props) {
                    Severity: Minor
                    Found in packages/plugin-router/src/utils.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 getAMQPRouterAdapter has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                    function getAMQPRouterAdapter(
                      service: Microfleet,
                      config: RouterAMQPPluginConfig,
                      onComplete?: (this: Microfleet, err: Error | null | undefined, data: any, actionName: string, raw: Message) => Promise<any>
                    ): MessageConsumer {
                    Severity: Minor
                    Found in packages/plugin-router-amqp/src/adapter.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 handleOffsetCommit has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                      private async handleOffsetCommit(err: LibrdKafkaError | null | undefined , partitions: TopicPartitionOffset[]): Promise<void> {
                        if (err) {
                          const wrappedError = new OffsetCommitError(partitions, this.trackerMeta, err)
                    
                          this.log?.warn({ err: wrappedError }, '[commit] offset commit error')
                    Severity: Minor
                    Found in packages/plugin-kafka/src/custom/consumer-stream.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 checkEof has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                      private async checkEof(): Promise<void> {
                        if (this.inDestroyingState() || !this.config.stopOnPartitionsEOF) {
                          this.log?.debug('checkEof: destroying')
                          return
                        }
                    Severity: Minor
                    Found in packages/plugin-kafka/src/custom/consumer-stream.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 loadLuaScripts has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                    export async function loadLuaScripts<T extends Redis.Redis | Redis.Cluster>(
                      ctx: Microfleet,
                      dir: string | string[],
                      redis: T
                    ): Promise<void> {
                    Severity: Minor
                    Found in packages/plugin-redis-core/src/utils.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 whatBump has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    const whatBump = (commits) => {
                      let level = undefined
                      let breakings = 0
                      let features = 0
                      let patches = 0
                    Severity: Minor
                    Found in ci/conventional-changelog-microfleet.js - About 1 hr to fix

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

                        private async handleOffsetCommit(err: LibrdKafkaError | null | undefined , partitions: TopicPartitionOffset[]): Promise<void> {
                          if (err) {
                            const wrappedError = new OffsetCommitError(partitions, this.trackerMeta, err)
                      
                            this.log?.warn({ err: wrappedError }, '[commit] offset commit error')
                      Severity: Minor
                      Found in packages/plugin-kafka/src/custom/consumer-stream.ts - About 1 hr to fix
                        Severity
                        Category
                        Status
                        Source
                        Language