meteor/meteor

View on GitHub
packages/accounts-base/accounts_server.js

Summary

Maintainability
F
1 wk
Test Coverage

File accounts_server.js has 1072 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import crypto from 'crypto';
import { Meteor } from 'meteor/meteor'
import {
  AccountsCommon,
  EXPIRE_TOKENS_INTERVAL_MS,
Severity: Major
Found in packages/accounts-base/accounts_server.js - About 2 days to fix

    AccountsServer has 55 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class AccountsServer extends AccountsCommon {
      // Note that this constructor is less likely to be instantiated multiple
      // times than the `AccountsClient` constructor, because a single server
      // can provide only one set of methods.
      constructor(server, options) {
    Severity: Major
    Found in packages/accounts-base/accounts_server.js - About 7 hrs to fix

      Function _initServerMethods has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

        _initServerMethods() {
          // The methods created in this function need to be created here so that
          // this variable is available in their scope.
          const accounts = this;
      
      
      Severity: Minor
      Found in packages/accounts-base/accounts_server.js - About 3 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 _initServerMethods has 65 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        _initServerMethods() {
          // The methods created in this function need to be created here so that
          // this variable is available in their scope.
          const accounts = this;
      
      
      Severity: Major
      Found in packages/accounts-base/accounts_server.js - About 2 hrs to fix

        Function defaultResumeLoginHandler has 64 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const defaultResumeLoginHandler = (accounts, options) => {
          if (!options.resume)
            return undefined;
        
          check(options.resume, String);
        Severity: Major
        Found in packages/accounts-base/accounts_server.js - About 2 hrs to fix

          Function updateOrCreateUserFromExternalService has 52 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            updateOrCreateUserFromExternalService(
              serviceName,
              serviceData,
              options
            ) {
          Severity: Major
          Found in packages/accounts-base/accounts_server.js - About 2 hrs to fix

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

              constructor(server, options) {
                super(options || {});
            
                this._server = server || Meteor.server;
                // Set up the server's methods, as if by calling Meteor.methods.
            Severity: Minor
            Found in packages/accounts-base/accounts_server.js - About 1 hr to fix

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

                _initServerPublications() {
                  // Bring into lexical scope for publish callbacks that need `this`
                  const { users, _autopublishFields, _defaultPublishFields } = this;
              
                  // Publish all login service configuration fields other than secret.
              Severity: Minor
              Found in packages/accounts-base/accounts_server.js - About 1 hr to fix

                Function _attemptLogin has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  async _attemptLogin(
                    methodInvocation,
                    methodName,
                    methodArgs,
                    result
                Severity: Minor
                Found in packages/accounts-base/accounts_server.js - About 1 hr to fix

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

                    updateOrCreateUserFromExternalService(
                      serviceName,
                      serviceData,
                      options
                    ) {
                  Severity: Minor
                  Found in packages/accounts-base/accounts_server.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 insertUserDoc has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                  Open

                    insertUserDoc(options, user) {
                      // - clone user document, to protect from modification
                      // - add createdAt timestamp
                      // - prepare an _id, so that you can modify other collections (eg
                      // create a first task for every new user)
                  Severity: Minor
                  Found in packages/accounts-base/accounts_server.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 insertUserDoc has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    insertUserDoc(options, user) {
                      // - clone user document, to protect from modification
                      // - add createdAt timestamp
                      // - prepare an _id, so that you can modify other collections (eg
                      // create a first task for every new user)
                  Severity: Minor
                  Found in packages/accounts-base/accounts_server.js - About 1 hr to fix

                    Function expirePasswordToken has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    const expirePasswordToken = (
                      accounts,
                      oldestValidDate,
                      tokenFilter,
                      userId
                    Severity: Minor
                    Found in packages/accounts-base/accounts_server.js - About 1 hr to fix

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

                        _setLoginToken(userId, connection, newToken) {
                          this._removeTokenFromConnection(connection.id);
                          this._setAccountData(connection.id, 'loginToken', newToken);
                      
                          if (newToken) {
                      Severity: Minor
                      Found in packages/accounts-base/accounts_server.js - About 1 hr to fix

                        Function _attemptLogin has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                        Open

                          async _attemptLogin(
                            methodInvocation,
                            methodName,
                            methodArgs,
                            result
                        Severity: Minor
                        Found in packages/accounts-base/accounts_server.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 constructor has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                          constructor(server, options) {
                            super(options || {});
                        
                            this._server = server || Meteor.server;
                            // Set up the server's methods, as if by calling Meteor.methods.
                        Severity: Minor
                        Found in packages/accounts-base/accounts_server.js - 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 defaultResumeLoginHandler has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                        const defaultResumeLoginHandler = (accounts, options) => {
                          if (!options.resume)
                            return undefined;
                        
                          check(options.resume, String);
                        Severity: Minor
                        Found in packages/accounts-base/accounts_server.js - 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 _expireTokens has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                          _expireTokens(oldestValidDate, userId) {
                            const tokenLifetimeMs = this._getTokenLifetimeMs();
                        
                            // when calling from a test with extra arguments, you must specify both!
                            if ((oldestValidDate && !userId) || (!oldestValidDate && userId)) {
                        Severity: Minor
                        Found in packages/accounts-base/accounts_server.js - 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

                        Function defaultValidateNewUserHook has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                        function defaultValidateNewUserHook(user) {
                          const domain = this._options.restrictCreationByEmailDomain;
                          if (!domain) {
                            return true;
                          }
                        Severity: Minor
                        Found in packages/accounts-base/accounts_server.js - 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

                            if (typeof this.emailTemplates[reason].text === 'function') {
                              options.text = this.emailTemplates[reason].text(user, url, extra);
                            }
                        Severity: Minor
                        Found in packages/accounts-base/accounts_server.js and 1 other location - About 55 mins to fix
                        packages/accounts-base/accounts_server.js on lines 1421..1423

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

                        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 (typeof this.emailTemplates[reason].html === 'function') {
                              options.html = this.emailTemplates[reason].html(user, url, extra);
                            }
                        Severity: Minor
                        Found in packages/accounts-base/accounts_server.js and 1 other location - About 55 mins to fix
                        packages/accounts-base/accounts_server.js on lines 1417..1419

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

                        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

                          _failedLogin(connection, attempt) {
                            this._onLoginFailureHook.each(callback => {
                              callback(cloneAttemptWithConnection(connection, attempt));
                              return true;
                            });
                        Severity: Minor
                        Found in packages/accounts-base/accounts_server.js and 1 other location - About 35 mins to fix
                        packages/accounts-base/accounts_server.js on lines 248..253

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

                        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

                          _successfulLogin(connection, attempt) {
                            this._onLoginHook.each(callback => {
                              callback(cloneAttemptWithConnection(connection, attempt));
                              return true;
                            });
                        Severity: Minor
                        Found in packages/accounts-base/accounts_server.js and 1 other location - About 35 mins to fix
                        packages/accounts-base/accounts_server.js on lines 255..260

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

                        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

                          } else {
                            accounts.users.update({...userFilter, ...expireFilter}, {
                              $unset: {
                                "services.password.reset": ""
                              }
                        Severity: Minor
                        Found in packages/accounts-base/accounts_server.js and 1 other location - About 30 mins to fix
                        packages/accounts-base/accounts_server.js on lines 1678..1684

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

                          if(isEnroll) {
                            accounts.users.update({...userFilter, ...expireFilter}, {
                              $unset: {
                                "services.password.enroll": ""
                              }
                        Severity: Minor
                        Found in packages/accounts-base/accounts_server.js and 1 other location - About 30 mins to fix
                        packages/accounts-base/accounts_server.js on lines 1684..1690

                        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