jiahaog/nativefier

View on GitHub

Showing 148 of 148 total issues

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

  if (options.packager.platform === 'linux') {
    if (iconIsPng(options.packager.icon)) {
      log.debug(
        'Building for Linux and icon is already a .png, no conversion needed',
      );
Severity: Major
Found in src/build/buildIcon.ts and 1 other location - About 4 hrs to fix
src/build/buildIcon.ts on lines 36..52

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

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

export async function buildNativefierApp(
  rawOptions: RawOptions,
): Promise<string> {
  // early-suppress potential logging before full options handling
  if (rawOptions.quiet) {
Severity: Major
Found in src/build/buildNativefierApp.ts - About 3 hrs to fix

    File playwright-test.ts has 325 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import { once } from 'events';
    import * as fs from 'fs';
    import * as path from 'path';
    
    import { Shell } from 'electron';
    Severity: Minor
    Found in src/playwright-test.ts - About 3 hrs to fix

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

      function setupScreenSharePickerStyles(id: string): void {
        const screenShareStyles = document.createElement('style');
        screenShareStyles.id = id;
        screenShareStyles.innerHTML = `
        .desktop-capturer-selection {
      Severity: Major
      Found in app/src/preload.ts - About 3 hrs to fix

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

        jest.mock('./helpers');
        jest.mock('./windowEvents');
        jest.mock('./windowHelpers');
        
        import { dialog, BrowserWindow, HandlerDetails, WebContents } from 'electron';
        Severity: Minor
        Found in app/src/helpers/windowEvents.test.ts - About 3 hrs to fix

          File windowHelpers.ts has 303 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import path from 'path';
          
          import {
            dialog,
            BrowserWindow,
          Severity: Minor
          Found in app/src/helpers/windowHelpers.ts - About 3 hrs to fix

            Function createMainWindow has 80 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export async function createMainWindow(
              nativefierOptions: OutputOptions,
              setDockBadge: (value: number | string, bounce?: boolean) => void,
            ): Promise<BrowserWindow> {
              const options = { ...nativefierOptions };
            Severity: Major
            Found in app/src/components/mainWindow.ts - About 3 hrs to fix

              Function pickElectronAppArgs has 79 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function pickElectronAppArgs(options: AppOptions): OutputOptions {
                return {
                  accessibilityPrompt: options.nativefier.accessibilityPrompt,
                  alwaysOnTop: options.nativefier.alwaysOnTop,
                  appBundleId: options.packager.appBundleId,
              Severity: Major
              Found in src/build/prepareElectronApp.ts - About 3 hrs to fix

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

                import { shell } from 'electron';
                jest.mock('./windowHelpers');
                
                import {
                  cleanupPlainText,
                Severity: Minor
                Found in app/src/helpers/helpers.test.ts - About 3 hrs to fix

                  Function generateMenu has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
                  Open

                  export function generateMenu(
                    options: {
                      disableDevTools: boolean;
                      nativefierVersion: string;
                      zoom?: number;
                  Severity: Minor
                  Found in app/src/components/menu.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

                  File preload.ts has 295 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  /**
                   * Preload file that will be executed in the renderer process.
                   * Note: This needs to be attached **prior to imports**, as imports
                   * would delay the attachment till after the event has been raised.
                   */
                  Severity: Minor
                  Found in app/src/preload.ts - About 3 hrs to fix

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

                    import 'source-map-support/register';
                    
                    import { initArgs, parseArgs } from './cli';
                    import { parseJson } from './utils/parseUtils';
                    
                    
                    Severity: Minor
                    Found in src/cli.test.ts - About 2 hrs to fix

                      Function onReady has 70 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      async function onReady(): Promise<void> {
                        // Warning: `mainWindow` below is the *global* unique `mainWindow`, created at init time
                        mainWindow = await createMainWindow(appArgs, setDockBadge);
                      
                        createTrayIcon(appArgs, mainWindow);
                      Severity: Major
                      Found in app/src/main.ts - About 2 hrs to fix

                        Function spawnApp has 70 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          const spawnApp = async (
                            playwrightConfig: NativefierOptions = { ...DEFAULT_CONFIG },
                            awaitFirstWindow = true,
                            preventNavigation = false,
                          ): Promise<Page | undefined> => {
                        Severity: Major
                        Found in src/playwright-test.ts - About 2 hrs to fix

                          Function buildNativefierApp has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                          Open

                          export async function buildNativefierApp(
                            rawOptions: RawOptions,
                          ): Promise<string> {
                            // early-suppress potential logging before full options handling
                            if (rawOptions.quiet) {
                          Severity: Minor
                          Found in src/build/buildNativefierApp.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 findSync has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                          Open

                          function findSync(
                            pattern: RegExp,
                            basePath: string,
                            limitSearchToDirectories = false,
                          ): string[] {
                          Severity: Minor
                          Found in app/src/helpers/inferFlash.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 createTrayIcon has 66 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          export function createTrayIcon(
                            nativefierOptions: OutputOptions,
                            mainWindow: BrowserWindow,
                          ): Tray | undefined {
                            const options = { ...nativefierOptions };
                          Severity: Major
                          Found in app/src/components/trayIcon.ts - About 2 hrs to fix

                            File mainWindow.ts has 275 lines of code (exceeds 250 allowed). Consider refactoring.
                            Open

                            import * as fs from 'fs';
                            import * as path from 'path';
                            
                            import {
                              desktopCapturer,
                            Severity: Minor
                            Found in app/src/components/mainWindow.ts - About 2 hrs to fix

                              Function getAllowedIconFormats has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
                              Open

                              export function getAllowedIconFormats(platform: string): string[] {
                                const hasIdentify = hasbin.sync('identify') || hasbin.sync('gm');
                                const hasConvert = hasbin.sync('convert') || hasbin.sync('gm');
                                const hasIconUtil = hasbin.sync('iconutil');
                              
                              
                              Severity: Minor
                              Found in src/helpers/helpers.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 2 locations. Consider refactoring.
                              Open

                                test('--help forces exit', () => {
                                  // Mock console.log to not pollute the log with the yargs help text
                                  const mockLog = jest.spyOn(console, 'log').mockImplementation();
                                  initArgs(['https://www.google.com', '--help']);
                                  expect(mockExit).toHaveBeenCalledTimes(1);
                              Severity: Major
                              Found in src/cli.test.ts and 1 other location - About 2 hrs to fix
                              src/cli.test.ts on lines 26..33

                              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