jiahaog/nativefier

View on GitHub

Showing 148 of 148 total issues

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

  test('--version 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', '--version']);
    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 17..24

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

Function getAllowedIconFormats has 63 lines of code (exceeds 25 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: Major
Found in src/helpers/helpers.ts - About 2 hrs to fix

    Function checkApp has 61 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    async function checkApp(
      appRoot: string,
      inputOptions: RawOptions,
    ): Promise<void> {
      const arch = inputOptions.arch ? inputOptions.arch : inferArch();
    Severity: Major
    Found in src/integration-test.ts - About 2 hrs to fix

      Function convertIconIfNecessary has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function convertIconIfNecessary(options: AppOptions): void {
        if (!options.packager.icon) {
          log.debug('Option "icon" not set, skipping icon conversion.');
          return;
        }
      Severity: Major
      Found in src/build/buildIcon.ts - About 2 hrs to fix

        Function convertIconIfNecessary has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        export function convertIconIfNecessary(options: AppOptions): void {
          if (!options.packager.icon) {
            log.debug('Option "icon" not set, skipping icon conversion.');
            return;
          }
        Severity: Minor
        Found in src/build/buildIcon.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 setupSessionInteraction has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function setupSessionInteraction(window: BrowserWindow): void {
          // See API.md / "Accessing The Electron Session"
          ipcMain.on(
            'session-interaction',
            (event, request: SessionInteractionRequest) => {
        Severity: Major
        Found in app/src/components/mainWindow.ts - About 2 hrs to fix

          Function getLatestSafariVersion has 50 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export async function getLatestSafariVersion(
            url = SAFARI_VERSIONS_HISTORY_URL,
          ): Promise<SafariVersion> {
            try {
              log.debug('Grabbing apple version data from', url);
          Severity: Minor
          Found in src/infer/browsers/inferSafariVersion.ts - About 2 hrs to fix

            Function injectBookmarks has 50 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function injectBookmarks(menuTemplate: MenuItemConstructorOptions[]): void {
              const bookmarkConfigPath = path.join(__dirname, '..', 'bookmarks.json');
            
              if (!fs.existsSync(bookmarkConfigPath)) {
                return;
            Severity: Minor
            Found in app/src/components/menu.ts - About 2 hrs to fix

              Function onNewWindowHelper has 50 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              export function onNewWindowHelper(
                options: WindowOptions,
                setupWindow: (options: WindowOptions, window: BrowserWindow) => void,
                details: HandlerDetails,
                parent?: BrowserWindow,
              Severity: Minor
              Found in app/src/helpers/windowEvents.ts - About 2 hrs to fix

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

                  if (
                    options.nativefier.maxWidth &&
                    options.nativefier.width &&
                    options.nativefier.width > options.nativefier.maxWidth
                  ) {
                Severity: Major
                Found in src/options/optionsMain.ts and 1 other location - About 1 hr to fix
                src/options/optionsMain.ts on lines 221..227

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

                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.nativefier.maxHeight &&
                    options.nativefier.height &&
                    options.nativefier.height > options.nativefier.maxHeight
                  ) {
                Severity: Major
                Found in src/options/optionsMain.ts and 1 other location - About 1 hr to fix
                src/options/optionsMain.ts on lines 213..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 74.

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

                async function checkApp(
                  appRoot: string,
                  inputOptions: RawOptions,
                ): Promise<void> {
                  const arch = inputOptions.arch ? inputOptions.arch : inferArch();
                Severity: Minor
                Found in src/integration-test.ts - 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 createTrayIcon has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                export function createTrayIcon(
                  nativefierOptions: OutputOptions,
                  mainWindow: BrowserWindow,
                ): Tray | undefined {
                  const options = { ...nativefierOptions };
                Severity: Minor
                Found in app/src/components/trayIcon.ts - 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 getInfoPListOptions has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function getInfoPListOptions(
                  appResourcesDir: string,
                  priorOptions: NativefierOptions,
                ): NativefierOptions {
                  if (!fileExists(path.join(appResourcesDir, '..', '..', 'Info.plist'))) {
                Severity: Minor
                Found in src/helpers/upgrade/upgrade.ts - About 1 hr to fix

                  Function injectBookmarks has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function injectBookmarks(menuTemplate: MenuItemConstructorOptions[]): void {
                    const bookmarkConfigPath = path.join(__dirname, '..', 'bookmarks.json');
                  
                    if (!fs.existsSync(bookmarkConfigPath)) {
                      return;
                  Severity: Minor
                  Found in app/src/components/menu.ts - 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 setupScreenSharePicker has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function setupScreenSharePicker(
                    resolve: (value: MediaStream | PromiseLike<MediaStream>) => void,
                    reject: (reason?: unknown) => void,
                    sources: Electron.DesktopCapturerSource[],
                  ): void {
                  Severity: Minor
                  Found in app/src/preload.ts - About 1 hr to fix

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

                      test('it should allow non-ascii characters', () => {
                        const expectedResult = '微信读书';
                        const param = `${reserved}${expectedResult}`;
                        const result = sanitizeFilename('', param);
                        expect(result).toBe(expectedResult);
                    Severity: Major
                    Found in src/utils/sanitizeFilename.test.ts and 1 other location - About 1 hr to fix
                    src/utils/sanitizeFilename.test.ts on lines 7..12

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

                    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('it should return a result without reserved characters', () => {
                        const expectedResult = 'abc';
                        const param = `${reserved}${expectedResult}`;
                        const result = sanitizeFilename('', param);
                        expect(result).toBe(expectedResult);
                    Severity: Major
                    Found in src/utils/sanitizeFilename.test.ts and 1 other location - About 1 hr to fix
                    src/utils/sanitizeFilename.test.ts on lines 14..19

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

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

                    export function initContextMenu(
                      options: OutputOptions,
                      window?: BrowserWindow,
                    ): void {
                      log.debug('initContextMenu');
                    Severity: Minor
                    Found in app/src/components/contextMenu.ts - About 1 hr to fix

                      Function onReady has a Cognitive Complexity of 13 (exceeds 5 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: Minor
                      Found in app/src/main.ts - 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

                      Severity
                      Category
                      Status
                      Source
                      Language