microfleet/core

View on GitHub

Showing 88 of 88 total issues

Function performMigration has 51 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export async function performMigration(redis: Redis.Redis | Redis.Cluster, service: Microfleet, scripts: unknown): Promise<boolean> {
  let files: Migration[]
  if (typeof scripts === 'string') {
    debug('looking for files in %s', scripts)
    files = await glob('*{.js,/}', { cwd: scripts, withFileTypes: true })
Severity: Major
Found in packages/plugin-redis-core/src/migrate.ts - About 2 hrs to fix

    Function getAMQPRouterAdapter has 46 lines of code (exceeds 25 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

      Function attach has 44 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export async function attach(
        this: Microfleet,
        opts: Partial<Config> = {}
      ): Promise<PluginInterface> {
        assert(this.hasPlugin('logger'), new NotFoundError('logger module must be included'))
      Severity: Minor
      Found in packages/plugin-aws-elasticsearch/src/plugin.ts - About 1 hr to fix

        Function attachConsulPlugin has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

        export const attach = async function attachConsulPlugin(
          this: Microfleet,
          opts: Partial<ConsulConfig> = {}
        ): Promise<PluginInterface> {
          assert(this.hasPlugin('logger'), new NotFoundError('log module must be included'))
        Severity: Minor
        Found in packages/plugin-consul/src/plugin.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 attach has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export async function attach(
          this: Microfleet,
          opts: ValidatorConfig,
          parentFile: string
        ): Promise<void> {
        Severity: Minor
        Found in packages/plugin-validator/src/validator.ts - About 1 hr to fix

          Function auditLogFactory has 42 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export default function auditLogFactory(params: AuditLogExtensionParams = {}): LifecycleExtensions {
            const { getErrorLevel } = params
            const disableLogErrorsForNames: string[] = params.disableLogErrorsForNames || []
          
            return [
          Severity: Minor
          Found in packages/plugin-router/src/extensions/audit/log.ts - About 1 hr to fix

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

            export async function attach(
              this: Microfleet,
              options: Partial<RouterPluginConfig>
            ): Promise<PluginInterface> {
              assert(this.hasPlugin('logger'), 'log module must be included')
            Severity: Minor
            Found in packages/plugin-router/src/plugin.ts - About 1 hr to fix

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

              export async function attach(this: Microfleet, opts: Partial<Config> = {}): Promise<PluginInterface> {
                assert(this.hasPlugin('validator'), new NotFoundError('validator module must be included'))
                await this.validator.addLocation(resolve(__dirname, '../schemas'))
              
                const bird = Bluebird.getNewLibraryCopy()
              Severity: Minor
              Found in packages/plugin-redis-cluster/src/redis-cluster.ts - About 1 hr to fix

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

                  private async readLoop(): Promise<void> {
                    while (!this.consumerDisconnected() && !this.endEmitted) {
                      // when consumer disconnecting it throws Error: KafkaConsumer is not connected
                      const bufferAvailable = this.readableHighWaterMark - this.readableLength
                      const fetchSize = this.config.streamAsBatch ? this.fetchSize : bufferAvailable
                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 responseHandler has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                export default async function responseHandler(this: Microfleet, request: ServiceRequest): Promise<void> {
                  const { error, reformatError } = request
                
                  if (error !== undefined) {
                    if (reformatError === true) {
                Severity: Minor
                Found in packages/plugin-router/src/lifecycle/handlers/response.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 attach has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                export async function attach(this: Microfleet, opts: Partial<Config> = {}): Promise<PluginInterface> {
                  assert(this.hasPlugin('validator'), new NotFoundError('validator module must be included'))
                  await this.validator.addLocation(resolve(__dirname, '../schemas'))
                
                  // @ts-expect-error - promise not defined, but can be used
                Severity: Minor
                Found in packages/plugin-redis-sentinel/src/redis-sentinel.ts - About 1 hr to fix

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

                  export default async function responseHandler(this: Microfleet, request: ServiceRequest): Promise<void> {
                    const { error, reformatError } = request
                  
                    if (error !== undefined) {
                      if (reformatError === true) {
                  Severity: Minor
                  Found in packages/plugin-router/src/lifecycle/handlers/response.ts - About 1 hr to fix

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

                    export async function attach(
                      this: Microfleet,
                      options: Partial<AMQPPluginConfig> = {}
                    ): Promise<PluginInterface> {
                      assert(this.hasPlugin('logger'), new NotFoundError('log module must be included'))
                    Severity: Minor
                    Found in packages/plugin-amqp/src/plugin.ts - About 1 hr to fix

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

                        public async initPlugin<T extends Record<string, unknown>>(mod: ns.Plugin<T>, conf?: any): Promise<void> {
                          const pluginName = mod.name
                          debug('initializing', pluginName)
                      
                          let expose: ns.PluginInterface
                      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 commitMessages has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                      Open

                        public async commitMessages(messages: Message[]): Promise<void> {
                          const offsets: TopicPartitionOffset[] = messages.map(m => ({
                            topic: m.topic,
                            partition: m.partition,
                            offset: m.offset + 1,
                      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 getMigrationFile has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                      Open

                      const getMigrationFile = async (script: Path) => {
                        let file = script.fullpath()
                      
                        if (script.isDirectory()) {
                          const files = await script.readdir()
                      Severity: Minor
                      Found in packages/plugin-redis-core/src/migrate.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 constructor has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        constructor(consumer: KafkaConsumer, config: ConsumerStreamOptions, log?: Logger) {
                          assert(consumer.isConnected(), 'consumer should be connected')
                          assert(consumer instanceof KafkaConsumer, 'should be intance of KafkaConsumer')
                          const fetchSize = config.fetchSize || 1
                          const highWaterMark = config.streamAsBatch ? 1 : fetchSize
                      Severity: Minor
                      Found in packages/plugin-kafka/src/custom/consumer-stream.ts - About 1 hr to fix

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

                          public async initPlugin<T extends Record<string, unknown>>(mod: ns.Plugin<T>, conf?: any): Promise<void> {
                            const pluginName = mod.name
                            debug('initializing', pluginName)
                        
                            let expose: ns.PluginInterface
                        Severity: Minor
                        Found in packages/core/src/index.ts - About 1 hr to fix

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

                          async function factory(this: Microfleet, Cassandra: Cassandra, config: Config) {
                            const { models } = config.service
                            const reconnectOpts = {
                              interval: 500,
                              backoff: 2,
                          Severity: Minor
                          Found in packages/plugin-cassandra/src/cassandra.ts - About 1 hr to fix

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

                                  async handler(this: Microfleet, request: ServiceRequest) {
                                    const { requestStarted, error, response } = request
                                    const requestEnded = request.requestEnded = process.hrtime()
                            
                                    const meta: MetaLog = {
                            Severity: Minor
                            Found in packages/plugin-router/src/extensions/audit/log.ts - About 1 hr to fix
                              Severity
                              Category
                              Status
                              Source
                              Language