maa123/mastodon

View on GitHub
streaming/index.js

Summary

Maintainability
F
1 wk
Test Coverage

Function startServer has 812 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const startServer = async () => {
  const app = express();

  app.set('trust proxy', process.env.TRUSTED_PROXY_IP ? process.env.TRUSTED_PROXY_IP.split(/(?:\s*,\s*|\s+)/) : 'loopback,uniquelocal');

Severity: Major
Found in streaming/index.js - About 4 days to fix

    Function startServer has a Cognitive Complexity of 122 (exceeds 5 allowed). Consider refactoring.
    Open

    const startServer = async () => {
      const app = express();
    
      app.set('trust proxy', process.env.TRUSTED_PROXY_IP ? process.env.TRUSTED_PROXY_IP.split(/(?:\s*,\s*|\s+)/) : 'loopback,uniquelocal');
    
    
    Severity: Minor
    Found in streaming/index.js - About 2 days 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

    File index.js has 953 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    // @ts-check
    
    const fs = require('fs');
    const http = require('http');
    const url = require('url');
    Severity: Major
    Found in streaming/index.js - About 2 days to fix

      Function streamFrom has 133 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        const streamFrom = (ids, req, output, attachCloseHandler, destinationType, needsFiltering = false) => {
          const accountId = req.accountId || req.remoteAddress;
      
          log.verbose(req.requestId, `Starting stream from ${ids.join(', ')} for ${accountId}`);
      
      
      Severity: Major
      Found in streaming/index.js - About 5 hrs to fix

        Function listener has 116 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            const listener = message => {
              const { event, payload } = message;
        
              // Streaming only needs to apply filtering to some channels and only to
              // some events. This is because majority of the filtering happens on the
        Severity: Major
        Found in streaming/index.js - About 4 hrs to fix

          Function channelNameToIds has 88 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            const channelNameToIds = (req, name, params) => new Promise((resolve, reject) => {
              switch (name) {
              case 'user':
                resolve({
                  channelIds: channelsForUserStream(req),
          Severity: Major
          Found in streaming/index.js - About 3 hrs to fix

            Function pgConfigFromEnv has 45 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            const pgConfigFromEnv = (env) => {
              const pgConfigs = {
                development: {
                  user:     env.DB_USER || pg.defaults.user,
                  password: env.DB_PASS || pg.defaults.password,
            Severity: Minor
            Found in streaming/index.js - About 1 hr to fix

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

              const pgConfigFromEnv = (env) => {
                const pgConfigs = {
                  development: {
                    user:     env.DB_USER || pg.defaults.user,
                    password: env.DB_PASS || pg.defaults.password,
              Severity: Minor
              Found in streaming/index.js - 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 attachServerWithConfig has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

              const attachServerWithConfig = (server, onSuccess) => {
                if (process.env.SOCKET || process.env.PORT && isNaN(+process.env.PORT)) {
                  server.listen(process.env.SOCKET || process.env.PORT, () => {
                    if (onSuccess) {
                      fs.chmodSync(server.address(), 0o666);
              Severity: Minor
              Found in streaming/index.js - 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 parseJSON has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              const parseJSON = (json, req) => {
                try {
                  return JSON.parse(json);
                } catch (err) {
                  /* FIXME: This logging isn't great, and should probably be done at the
              Severity: Minor
              Found in streaming/index.js - 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

              Consider simplifying this complex logical expression.
              Open

                if (process.env.SOCKET || process.env.PORT && isNaN(+process.env.PORT)) {
                  server.listen(process.env.SOCKET || process.env.PORT, () => {
                    if (onSuccess) {
                      fs.chmodSync(server.address(), 0o666);
                      onSuccess(server.address());
              Severity: Major
              Found in streaming/index.js - About 40 mins to fix

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

                    case 'hashtag:local':
                      if (!params.tag || params.tag.length === 0) {
                        reject('No tag for stream provided');
                      } else {
                        resolve({
                Severity: Major
                Found in streaming/index.js and 1 other location - About 2 hrs to fix
                streaming/index.js on lines 1216..1226

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

                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

                    case 'hashtag':
                      if (!params.tag || params.tag.length === 0) {
                        reject('No tag for stream provided');
                      } else {
                        resolve({
                Severity: Major
                Found in streaming/index.js and 1 other location - About 2 hrs to fix
                streaming/index.js on lines 1227..1237

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

                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

                      redisSubscribeClient.subscribe(channel, (err, count) => {
                        if (err) {
                          log.error(`Error subscribing to ${channel}`);
                        }
                        else {
                Severity: Major
                Found in streaming/index.js and 1 other location - About 1 hr to fix
                streaming/index.js on lines 381..388

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

                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

                      redisSubscribeClient.unsubscribe(channel, (err, count) => {
                        if (err) {
                          log.error(`Error unsubscribing to ${channel}`);
                        }
                        else {
                Severity: Major
                Found in streaming/index.js and 1 other location - About 1 hr to fix
                streaming/index.js on lines 353..360

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

                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

                  new metrics.Gauge({
                    name: 'pg_pool_idle_connections',
                    help: 'The number of clients which are not checked out but are currently idle in the pool',
                    collect() {
                      this.set(pgPool.idleCount);
                Severity: Minor
                Found in streaming/index.js and 2 other locations - About 30 mins to fix
                streaming/index.js on lines 198..204
                streaming/index.js on lines 214..220

                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

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

                  new metrics.Gauge({
                    name: 'pg_pool_total_connections',
                    help: 'The total number of clients existing within the pool',
                    collect() {
                      this.set(pgPool.totalCount);
                Severity: Minor
                Found in streaming/index.js and 2 other locations - About 30 mins to fix
                streaming/index.js on lines 206..212
                streaming/index.js on lines 214..220

                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

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

                  new metrics.Gauge({
                    name: 'pg_pool_waiting_queries',
                    help: 'The number of queued requests waiting on a client when all clients are checked out',
                    collect() {
                      this.set(pgPool.waitingCount);
                Severity: Minor
                Found in streaming/index.js and 2 other locations - About 30 mins to fix
                streaming/index.js on lines 198..204
                streaming/index.js on lines 206..212

                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