bugsnag/bugsnag-js

View on GitHub

Showing 343 of 352 total issues

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

  try {
    await insertValueAfterPattern(
      appBuildGradlePath,
      [/^apply from: ["']\.\.\/\.\.\/node_modules\/react-native\/react\.gradle["']$/m, /^apply from: file\(["']..\/\.\.\/node_modules\/@react-native-community\/cli-platform-android\/native_modules\.gradle["']\); applyNativeModulesAppBuildGradle\(project\)$/m],
      GRADLE_PLUGIN_APPLY,
Severity: Major
Found in packages/react-native-cli/src/lib/Gradle.ts and 2 other locations - About 3 hrs to fix
packages/react-native-cli/src/lib/Gradle.ts on lines 175..215
packages/react-native-cli/src/lib/Gradle.ts on lines 219..259

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

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

async function updateBuildReactNativeTask (buildPhaseMap: Record<string, Record<string, unknown>>, iosDir: string, reactNativeVersion: string | undefined, logger: Logger): Promise<boolean> {
  let didAnythingUpdate = false
  let didThisUpdate

  for (const shellBuildPhaseKey in buildPhaseMap) {
Severity: Minor
Found in packages/react-native-cli/src/lib/Xcode.ts - 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

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

test('cli: prints help', async () => {
  const logSpy = jest.spyOn(global.console, 'log').mockImplementation(jest.fn())
  await run(['--help'])
  expect(logSpy).toHaveBeenCalled()
  expect(logSpy).toHaveBeenCalledWith(expect.stringContaining('bugsnag-react-native-cli <command>'))
Severity: Major
Found in packages/react-native-cli/src/bin/__test__/cli.test.ts and 1 other location - About 3 hrs to fix
packages/react-native-cli/src/bin/__test__/cli.test.ts on lines 17..22

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

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

test('cli: version', async () => {
  const logSpy = jest.spyOn(global.console, 'log').mockImplementation(jest.fn())
  await run(['--version'])
  expect(logSpy).toHaveBeenCalled()
  expect(logSpy).toHaveBeenCalledWith(expect.stringContaining('bugsnag-react-native-cli v'))
Severity: Major
Found in packages/react-native-cli/src/bin/__test__/cli.test.ts and 1 other location - About 3 hrs to fix
packages/react-native-cli/src/bin/__test__/cli.test.ts on lines 10..15

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

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

  load: (client) => {
    const emitter = new EventEmitter()

    // proxy all state updates from within the main process
    // so that we can emit events for the changes
Severity: Major
Found in packages/plugin-electron-client-state-manager/client-state-manager.js - About 3 hrs to fix

    File Insert.test.ts has 291 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import { insertJs, insertAndroid, insertIos } from '../Insert'
    import logger from '../../Logger'
    import path from 'path'
    import { promises as fs } from 'fs'
    import glob from 'glob'
    Severity: Minor
    Found in packages/react-native-cli/src/lib/__test__/Insert.test.ts - About 3 hrs to fix

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

      package com.bugsnagreactnativeclitest;
      
      import com.bugsnag.android.Bugsnag;
      import android.app.Application;
      import android.content.Context;
      packages/react-native-cli/src/lib/__test__/fixtures/MainApplication-after-2.java on lines 1..82

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

      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

      package com.bugsnagreactnativeclitest;
      
      import com.bugsnag.android.Bugsnag;
      import android.app.Application;
      import android.content.Context;
      packages/react-native-cli/src/lib/__test__/fixtures/MainApplication-after.java on lines 1..82

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

      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

      test('detectInstalled(): not installed', async () => {
        const readFileMock = fs.readFile as jest.MockedFunction<typeof fs.readFile>
        readFileMock.mockResolvedValue('{"dependencies": { "react-native": "~1.0.0"} }')
        expect(await detectInstalled('@bugsnag/test-package', '/example/dir')).toBe(false)
        expect(readFileMock).toHaveBeenCalledWith('/example/dir/package.json', 'utf8')
      Severity: Major
      Found in packages/react-native-cli/src/lib/__test__/Npm.test.ts and 2 other locations - About 2 hrs to fix
      packages/react-native-cli/src/lib/__test__/Npm.test.ts on lines 36..41
      packages/react-native-cli/src/lib/__test__/Npm.test.ts on lines 43..48

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

      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

      test('detectInstalled(): installed in dev deps', async () => {
        const readFileMock = fs.readFile as jest.MockedFunction<typeof fs.readFile>
        readFileMock.mockResolvedValue('{"devDependencies": { "@bugsnag/test-package": "~1.0.0"} }')
        expect(await detectInstalled('@bugsnag/test-package', '/example/dir')).toBe(true)
        expect(readFileMock).toHaveBeenCalledWith('/example/dir/package.json', 'utf8')
      Severity: Major
      Found in packages/react-native-cli/src/lib/__test__/Npm.test.ts and 2 other locations - About 2 hrs to fix
      packages/react-native-cli/src/lib/__test__/Npm.test.ts on lines 36..41
      packages/react-native-cli/src/lib/__test__/Npm.test.ts on lines 50..55

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

      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

      test('detectInstalled(): installed in deps', async () => {
        const readFileMock = fs.readFile as jest.MockedFunction<typeof fs.readFile>
        readFileMock.mockResolvedValue('{"dependencies": { "@bugsnag/test-package": "~1.0.0"} }')
        expect(await detectInstalled('@bugsnag/test-package', '/example/dir')).toBe(true)
        expect(readFileMock).toHaveBeenCalledWith('/example/dir/package.json', 'utf8')
      Severity: Major
      Found in packages/react-native-cli/src/lib/__test__/Npm.test.ts and 2 other locations - About 2 hrs to fix
      packages/react-native-cli/src/lib/__test__/Npm.test.ts on lines 43..48
      packages/react-native-cli/src/lib/__test__/Npm.test.ts on lines 50..55

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

      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

      package com.bugsnagreactnativeclitest;
      
      import android.app.Application;
      import android.content.Context;
      import com.facebook.react.PackageList;
      packages/react-native-cli/src/lib/__test__/fixtures/MainApplication-before-2.java on lines 1..80

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

      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

      package com.bugsnagreactnativeclitest;
      
      import android.app.Application;
      import android.content.Context;
      import com.facebook.react.PackageList;
      packages/react-native-cli/src/lib/__test__/fixtures/MainApplication-before.java on lines 1..80

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

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

      module.exports = function (data) {
        const seen = []
      
        const visit = (obj) => {
          if (obj === null || obj === undefined) return obj
      Severity: Minor
      Found in packages/core/lib/derecursify.js - 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

      BugsnagReactNativeImpl has 24 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class BugsnagReactNativeImpl {
      
        static final String MODULE_NAME = "BugsnagReactNative";
      
        private static final String UPDATE_CONTEXT = "ContextUpdate";

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

            if (options.notifyEndpoint) {
              bugsnag.endpoints = bugsnag.endpoints || {}
        
              if (bugsnag.endpoints.notify) {
                logger.warn('Notify endpoint is already present, skipping')
        Severity: Major
        Found in packages/react-native-cli/src/lib/InfoPlist.ts and 1 other location - About 2 hrs to fix
        packages/react-native-cli/src/lib/InfoPlist.ts on lines 63..72

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

        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 (options.sessionsEndpoint) {
              bugsnag.endpoints = bugsnag.endpoints || {}
        
              if (bugsnag.endpoints.sessions) {
                logger.warn('Sessions endpoint is already present, skipping')
        Severity: Major
        Found in packages/react-native-cli/src/lib/InfoPlist.ts and 1 other location - About 2 hrs to fix
        packages/react-native-cli/src/lib/InfoPlist.ts on lines 52..61

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

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

        module.exports = (doc = document, win = window) => ({
          load: (client) => {
            if (!client._config.trackInlineScripts) return
        
            const originalLocation = win.location.href
        Severity: Minor
        Found in packages/plugin-inline-script-content/inline-script-content.js - 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 exports has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

        module.exports = (BugsnagIpcRenderer = window.__bugsnag_ipc__) => ({
          load: client => {
            client.addOnError(async (event) => {
              const {
                app,
        Severity: Minor
        Found in packages/plugin-electron-renderer-event-data/renderer-event-data.js - 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 2 locations. Consider refactoring.
        Open

                onUnhandled: (id, rejection = {}) => {
                  const event = client.Event.create(rejection, false, {
                    severity: 'error',
                    unhandled: true,
                    severityReason: { type: 'unhandledPromiseRejection' }
        packages/plugin-react-native-unhandled-rejection/rejection-handler.js on lines 39..48

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

        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

        Severity
        Category
        Status
        Source
        Language