shawkinsl/mtga-tracker

View on GitHub
electron/main.js

Summary

Maintainability
F
1 wk
Test Coverage

File main.js has 913 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const console = require('console');
const jwt = require('jsonwebtoken');
const { inspectorRouter } = require("./inspectorApi")

global.updateReady = false
Severity: Major
Found in electron/main.js - About 2 days to fix

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

    function windowStateKeeper(windowName) {
      let window, windowState;
      function setBounds() {
        // Restore from settings
        if (settings.has(`windowState.${windowName}`)) {
    Severity: Minor
    Found in electron/main.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 windowStateKeeper has 51 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function windowStateKeeper(windowName) {
      let window, windowState;
      function setBounds() {
        // Restore from settings
        if (settings.has(`windowState.${windowName}`)) {
    Severity: Major
    Found in electron/main.js - About 2 hrs to fix

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

      const createMainWindow = () => {
        const mainWindowStateMgr = windowStateKeeper('main')
        mainWindow = new BrowserWindow({width: window_width,
                                        height: window_height,
                                        show: false,
      Severity: Minor
      Found in electron/main.js - About 1 hr to fix

        Function createPyProc has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const createPyProc = () => {
          let script = getScriptPath()
          let pbPath = getPyBinPath()
        
          let args = generateArgs()
        Severity: Minor
        Found in electron/main.js - About 1 hr to fix

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

          let openHistoryWindow = () => {
            if(historyWindow == null) {
              let historyWidth = debug ? 1200 : 400;
          
              const historyWindowStateMgr = windowStateKeeper('history')
          Severity: Minor
          Found in electron/main.js - About 1 hr to fix

            Function openSettingsWindow has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            let openSettingsWindow = () => {
              if(settingsWindow == null) {
                let settingsWidth = debug ? 1400 : 1025;
            
                const settingsWindowStateMgr = windowStateKeeper('settings')
            Severity: Minor
            Found in electron/main.js - About 1 hr to fix

              Function openInspectorWindow has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              let openInspectorWindow = () => {
                if(inspectorWindow == null) {
                  let settingsWidth = debug ? 1400 : 1100;
              
                  const inspectorWindowStateMgr = windowStateKeeper('settings')
              Severity: Minor
              Found in electron/main.js - About 1 hr to fix

                Function openCollectionWindow has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                let openCollectionWindow = () => {
                  if(collectionWindow == null) {
                    let collectionWidth = debug ? 1400 : 1025;
                
                    const collectionWindowStateMgr = windowStateKeeper('collection')
                Severity: Minor
                Found in electron/main.js - About 1 hr to fix

                  Function setBounds has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    function setBounds() {
                      // Restore from settings
                      if (settings.has(`windowState.${windowName}`)) {
                  
                        windowState = settings.get(`windowState.${windowName}`);
                  Severity: Minor
                  Found in electron/main.js - About 1 hr to fix

                    Function createPyProc has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                    const createPyProc = () => {
                      let script = getScriptPath()
                      let pbPath = getPyBinPath()
                    
                      let args = generateArgs()
                    Severity: Minor
                    Found in electron/main.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 killServer has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                    const killServer = () => {
                        console.log("killServer called")
                        if (!server_killed && kill_server) {
                            server_killed = true;
                            if (!no_server) {
                    Severity: Minor
                    Found in electron/main.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 openHistoryWindow has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                    let openHistoryWindow = () => {
                      if(historyWindow == null) {
                        let historyWidth = debug ? 1200 : 400;
                    
                        const historyWindowStateMgr = windowStateKeeper('history')
                    Severity: Minor
                    Found in electron/main.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(settingsWindow == null) {
                        let settingsWidth = debug ? 1400 : 1025;
                    
                        const settingsWindowStateMgr = windowStateKeeper('settings')
                        settingsWindow = new BrowserWindow({width: settingsWidth,
                    Severity: Major
                    Found in electron/main.js and 1 other location - About 1 day to fix
                    electron/main.js on lines 494..521

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

                    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(collectionWindow == null) {
                        let collectionWidth = debug ? 1400 : 1025;
                    
                        const collectionWindowStateMgr = windowStateKeeper('collection')
                        collectionWindow = new BrowserWindow({width: collectionWidth,
                    Severity: Major
                    Found in electron/main.js and 1 other location - About 1 day to fix
                    electron/main.js on lines 459..486

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

                    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

                        pyProc.stderr.on('data', function(data) {
                          console.log("py stderr: " + data.toString());
                          if (mainWindow) {
                            try {
                              mainWindow.webContents.send('stdout', {text: "py stderr:" + data.toString()})
                    Severity: Major
                    Found in electron/main.js and 1 other location - About 3 hrs to fix
                    electron/main.js on lines 751..760

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

                    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

                        pyProc.stdout.on('data', function(data) {
                          console.log("py stdout:" + data.toString());
                          if (mainWindow) {
                            try {
                              mainWindow.webContents.send('stdout', {text: "py stdout:" + data.toString()})
                    Severity: Major
                    Found in electron/main.js and 1 other location - About 3 hrs to fix
                    electron/main.js on lines 741..750

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

                    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

                            nameList.forEach(function(proc) {
                                if (proc.pid != 0 && !killedList.includes(proc.pid)) {
                                    console.log("leftover python process (name) @ " + proc.pid + ", killing...")
                                    process.kill(proc.pid)
                                    killedList.push(proc.pid)
                    Severity: Major
                    Found in electron/main.js and 1 other location - About 3 hrs to fix
                    electron/main.js on lines 705..711

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

                    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

                            portList.forEach(function(proc) {
                                if (proc.pid != 0 && !killedList.includes(proc.pid)) {
                                    console.log("leftover python process (port) @ " + proc.pid + ", killing...")
                                    process.kill(proc.pid)
                                    killedList.push(proc.pid)
                    Severity: Major
                    Found in electron/main.js and 1 other location - About 3 hrs to fix
                    electron/main.js on lines 698..704

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

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

                    function focusMTGATrackerSettings() {
                      if(settingsWindow) {
                        settingsWindow.show();
                        if(settingsWindow.isMinimized()) {
                          settingsWindow.restore();
                    Severity: Major
                    Found in electron/main.js and 3 other locations - About 1 hr to fix
                    electron/main.js on lines 972..982
                    electron/main.js on lines 984..995
                    electron/main.js on lines 997..1007

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

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

                    function focusCollection() {
                      if(collectionWindow) {
                        collectionWindow.show();
                        if(collectionWindow.isMinimized()) {
                          collectionWindow.restore();
                    Severity: Major
                    Found in electron/main.js and 3 other locations - About 1 hr to fix
                    electron/main.js on lines 960..970
                    electron/main.js on lines 984..995
                    electron/main.js on lines 997..1007

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

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

                    function focusInspector() {
                      if(inspectorWindow) {
                        inspectorWindow.show();
                        if(inspectorWindow.isMinimized()) {
                          inspectorWindow.restore();
                    Severity: Major
                    Found in electron/main.js and 3 other locations - About 1 hr to fix
                    electron/main.js on lines 960..970
                    electron/main.js on lines 972..982
                    electron/main.js on lines 997..1007

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

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

                    function focusMTGAHistory() {
                      if(historyWindow) {
                        historyWindow.show();
                        if(historyWindow.isMinimized()) {
                          historyWindow.restore();
                    Severity: Major
                    Found in electron/main.js and 3 other locations - About 1 hr to fix
                    electron/main.js on lines 960..970
                    electron/main.js on lines 972..982
                    electron/main.js on lines 984..995

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

                    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 (historyWindow) {
                        try {
                          historyWindow.webContents.send('hideRequest', arg)
                        } catch (error) {
                          console.log("couldn't send stdout message to history window, likely already destroyed")
                    Severity: Minor
                    Found in electron/main.js and 1 other location - About 40 mins to fix
                    electron/main.js on lines 438..444

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

                    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 (historyWindow) {
                        try {
                          historyWindow.webContents.send('gameHistoryEventSend', arg)
                        } catch (error) {
                          console.log("couldn't send stdout message to main window, likely already destroyed")
                    Severity: Minor
                    Found in electron/main.js and 1 other location - About 40 mins to fix
                    electron/main.js on lines 416..422

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

                    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