Kinvey/js-sdk

View on GitHub

Showing 349 of 349 total issues

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

  if (tables.length > 0) {
    await Promise.all(tables.map((tableName: string) => {
      if (exclude.indexOf(tableName) === -1) {
        return execute(dbName, tableName, [['DROP TABLE IF EXISTS #{table}']], true);
      }
Severity: Major
Found in packages/nativescript-sdk/src/nativescript/storage/sqlite.ts and 1 other location - About 2 hrs to fix
packages/html5-sdk/src/storage/websql.ts on lines 135..143

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

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

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

  if (tables.length > 0) {
    await Promise.all(tables.map((tableName: string) => {
      if (exclude.indexOf(tableName) === -1) {
        return execute(dbName, tableName, [['DROP TABLE IF EXISTS #{table}']], true);
      }
Severity: Major
Found in packages/html5-sdk/src/storage/websql.ts and 1 other location - About 2 hrs to fix
packages/nativescript-sdk/src/nativescript/storage/sqlite.ts on lines 116..124

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

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

    const batchCreateEntities = async (): Promise<any> => {
      const localIdsToRemove = [];
      const entitiesForInsert = await Promise.all(
        syncDocsForInsert.map(async (doc, index) => {
          const entity = await cache.findById(doc.entityId);
Severity: Major
Found in packages/js-sdk/src/datastore/sync.ts - About 2 hrs to fix

    Function removeById has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

      async removeById(id: string, options: any = {}) {
        const autoSync = options.autoSync === true || this.autoSync;
        const cache = new DataStoreCache(this.collectionName, this.tag);
        const sync = new Sync(this.collectionName, this.tag);
        let count = 0;
    Severity: Minor
    Found in packages/js-sdk/src/datastore/cachestore.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 3 locations. Consider refactoring.
    Open

      containsAll(field: string, values: any) {
        if (!values) {
          throw new QueryError('You must supply a value.');
        }
    
    
    Severity: Major
    Found in packages/js-sdk/src/query.ts and 2 other locations - About 2 hrs to fix
    packages/js-sdk/src/query.ts on lines 192..202
    packages/js-sdk/src/query.ts on lines 214..224

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

    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

      contains(field: string, values: any) {
        if (!values) {
          throw new QueryError('You must supply a value.');
        }
    
    
    Severity: Major
    Found in packages/js-sdk/src/query.ts and 2 other locations - About 2 hrs to fix
    packages/js-sdk/src/query.ts on lines 214..224
    packages/js-sdk/src/query.ts on lines 236..246

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

    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

      notContainedIn(field: string, values: any) {
        if (!values) {
          throw new QueryError('You must supply a value.');
        }
    
    
    Severity: Major
    Found in packages/js-sdk/src/query.ts and 2 other locations - About 2 hrs to fix
    packages/js-sdk/src/query.ts on lines 192..202
    packages/js-sdk/src/query.ts on lines 236..246

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

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

      process(docs: object[] = []) {
        const queryPlainObject = this.toPlainObject();
    
        if (!Array.isArray(docs)) {
          throw new Error('data argument must be of type: Array.');
    Severity: Major
    Found in packages/js-sdk/src/query.ts - About 2 hrs to fix

      UserService has 22 functions (exceeds 20 allowed). Consider refactoring.
      Open

      @Injectable({
        providedIn: 'root'
      })
      export class UserService {
        constructor(@Inject(KinveyConfigToken) config: any) {
      Severity: Minor
      Found in packages/angular-sdk/src/user.service.ts - About 2 hrs to fix

        UserService has 22 functions (exceeds 20 allowed). Consider refactoring.
        Open

        @Injectable({
          providedIn: 'root'
        })
        export class UserService {
          constructor(@Inject(KinveyConfigToken) config: any) {
        Severity: Minor
        Found in packages/nativescript-sdk/src/angular/user.service.ts - About 2 hrs to fix

          User has 22 functions (exceeds 20 allowed). Consider refactoring.
          Open

          export class User extends KinveyUser {
            static exists(username: string, options?: ExistsOptions) {
              return exists(username, options);
            }
          
          
          Severity: Minor
          Found in packages/js-sdk/src/user/index.ts - About 2 hrs to fix

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

                } else if (auth === KinveyHttpAuth.SessionOrMFASessionTokenOrMaster) {
                  try {
                    return await this.setAuthorization(KinveyHttpAuth.Session);
                  } catch (error) {
                    try {
            Severity: Major
            Found in packages/js-sdk/src/http/headers.ts and 1 other location - About 2 hrs to fix
            packages/js-sdk/src/http/headers.ts on lines 187..219

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

            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 if (auth === KinveyHttpAuth.All) {
                  try {
                    return await this.setAuthorization(KinveyHttpAuth.Session);
                  } catch (error) {
                    try {
            Severity: Major
            Found in packages/js-sdk/src/http/headers.ts and 1 other location - About 2 hrs to fix
            packages/js-sdk/src/http/headers.ts on lines 209..219

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

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

              process(docs: object[] = []) {
                const queryPlainObject = this.toPlainObject();
            
                if (!Array.isArray(docs)) {
                  throw new Error('data argument must be of type: Array.');
            Severity: Minor
            Found in packages/js-sdk/src/query.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

            Function open has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
            Open

              open(objectStoreName: string, write = false, success: any, error: any, force = false) {
                try {
                  if (this.db) {
                    if (this.db.objectStoreNames.contains(objectStoreName)) {
                      const mode = write ? IndexedDBTransactionMode.readWrite : IndexedDBTransactionMode.readOnly;
            Severity: Minor
            Found in packages/html5-sdk/src/storage/indexeddb.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

            Function open has 56 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              async open(url = '/', options: PopupOptions = {}) {
                if (this._open !== true) {
                  const activity = Application.android.startActivity || Application.android.foregroundActivity;
                  let shouldClose = false;
                  let success = false;
            Severity: Major
            Found in packages/nativescript-sdk/src/nativescript/popup/popup.android.ts - About 2 hrs to fix

              Function execute has 53 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function execute(dbName, tableName, sqlQueries, write = false) {
                const escapedTableName = `"${tableName}"`;
                const isMaster = tableName === MASTER_TABLE_NAME;
              
                return new SQLite(dbName)
              Severity: Major
              Found in packages/nativescript-sdk/src/nativescript/storage/sqlite.ts - About 2 hrs to fix

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

                      const request = new KinveyHttpRequest({
                        method: HttpRequestMethod.POST,
                        auth: KinveyHttpAuth.Session,
                        url: formatKinveyBaasUrl(KinveyBaasNamespace.User, `/${this._id}/unregister-realtime`),
                        body: { deviceId },
                Severity: Major
                Found in packages/js-sdk/src/user/user.ts and 1 other location - About 2 hrs to fix
                packages/js-sdk/src/user/user.ts on lines 196..202

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

                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 request = new KinveyHttpRequest({
                        method: HttpRequestMethod.POST,
                        auth: KinveyHttpAuth.Session,
                        url: formatKinveyBaasUrl(KinveyBaasNamespace.User, `/${this._id}/register-realtime`),
                        body: { deviceId },
                Severity: Major
                Found in packages/js-sdk/src/user/user.ts and 1 other location - About 2 hrs to fix
                packages/js-sdk/src/user/user.ts on lines 219..225

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

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

                  findById(id: string, options: any = {}) {
                    const stream = Observable.create(async (observer: any) => {
                      try {
                        // if (!id) {
                        //   throw new Error('No id was provided. A valid id is required.');
                Severity: Minor
                Found in packages/js-sdk/src/datastore/cachestore.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

                Severity
                Category
                Status
                Source
                Language