kumabook/stickynotes

View on GitHub
src/background.js

Summary

Maintainability
F
5 days
Test Coverage

File background.js has 580 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* global setTimeout: false, clearTimeout: false */
/* eslint no-use-before-define: ["error", { "functions": false }] */
import browser from 'webextension-polyfill';
import idb     from './utils/indexedDB';
import logger  from './utils/logger';
Severity: Major
Found in src/background.js - About 1 day to fix

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

    function handleContentScriptMessage(msg) {
      logger.info(`handleContentScriptMessage ${JSON.stringify(msg)}`);
      const port = getPort(msg.portName);
      switch (msg.type) {
        case 'load-options': {
    Severity: Major
    Found in src/background.js - About 3 hrs to fix

      Function handlePopupMessage has 84 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function handlePopupMessage(msg) {
        logger.info(`handlePopupMessage ${msg.type} from ${msg.portName}`);
        const port = getPort(msg.portName);
        switch (msg.type) {
          case 'list-menu': {
      Severity: Major
      Found in src/background.js - About 3 hrs to fix

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

        function importStickies(stickies, db) {
          const createdStickies = [];
          const updatedStickies = [];
          return stickies.reduce((p, s) => {
            s = Sticky.normalize(s);
        Severity: Major
        Found in src/background.js - About 2 hrs to fix

          Function setupContextMenus has 42 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function setupContextMenus() {
            browser.contextMenus.create({
              id:       'create-sticky',
              title:    'create sticky',
              contexts: ['all'],
          Severity: Minor
          Found in src/background.js - About 1 hr to fix

            Function handleSidebarMessage has 42 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function handleSidebarMessage(msg) {
              const port = getPort(msg.portName);
              switch (msg.type) {
                case 'fetch-stickies': {
                  idb.open(dbName).then(db => Promise.all([
            Severity: Minor
            Found in src/background.js - About 1 hr to fix

              Function handleOptionsUIMessage has 37 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function handleOptionsUIMessage(msg) {
                const port = getPort(msg.portName);
                switch (msg.type) {
                  case 'import': {
                    const stickies = msg.payload;
              Severity: Minor
              Found in src/background.js - About 1 hr to fix

                Avoid too many return statements within this function.
                Open

                    return optionsUIPorts[name];
                Severity: Major
                Found in src/background.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                    return null;
                  Severity: Major
                  Found in src/background.js - About 30 mins to fix

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

                    function createStickyOnActiveTab() {
                      browser.tabs.query({ currentWindow: true, active: true }).then((tabs) => {
                        if (tabs.length > 0) {
                          getContentScriptPorts().forEach(p => p.postMessage({
                            type:      'create-sticky',
                    Severity: Major
                    Found in src/background.js and 1 other location - About 3 hrs to fix
                    src/background.js on lines 55..64

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

                    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

                    function toggleStickies() {
                      browser.tabs.query({ currentWindow: true, active: true }).then((tabs) => {
                        if (tabs.length > 0) {
                          getContentScriptPorts().forEach(p => p.postMessage({
                            type:      'toggle-visibility',
                    Severity: Major
                    Found in src/background.js and 1 other location - About 3 hrs to fix
                    src/background.js on lines 44..53

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

                    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

                      } else if (name.startsWith('sidebar')) {
                        sidebarPorts[port.name] = port;
                        port.onDisconnect.addListener(() => {
                          delete sidebarPorts[port.name];
                          port.onMessage.removeListener(handleSidebarMessage);
                    Severity: Major
                    Found in src/background.js and 2 other locations - About 2 hrs to fix
                    src/background.js on lines 467..496
                    src/background.js on lines 489..496

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

                    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

                      } else if (name.startsWith('options-ui')) {
                        optionsUIPorts[port.name] = port;
                        port.onDisconnect.addListener(() => {
                          delete optionsUIPorts[port.name];
                          port.onMessage.removeListener(handleOptionsUIMessage);
                    Severity: Major
                    Found in src/background.js and 2 other locations - About 2 hrs to fix
                    src/background.js on lines 467..496
                    src/background.js on lines 482..496

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

                    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

                      if (name.startsWith('content-script')) {
                        contentScriptPorts[port.name] = port;
                        port.onDisconnect.addListener(() => {
                          delete contentScriptPorts[port.name];
                          port.onMessage.removeListener(handleContentScriptMessage);
                    Severity: Major
                    Found in src/background.js and 2 other locations - About 2 hrs to fix
                    src/background.js on lines 482..496
                    src/background.js on lines 489..496

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

                    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

                              return Sticky.update(item, db)
                                .then((v) => {
                                  logger.trace(`Updated ${v.id}`);
                                  updatedStickies.push(v);
                                })
                    Severity: Major
                    Found in src/background.js and 1 other location - About 1 hr to fix
                    src/background.js on lines 400..406

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

                    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

                            return Sticky.new(s, db).then((st) => {
                              logger.trace(`Created ${s.id}`);
                              createdStickies.push(st);
                            }).catch((e) => {
                              logger.fatal(`Failed to created ${s.id}`);
                    Severity: Major
                    Found in src/background.js and 1 other location - About 1 hr to fix
                    src/background.js on lines 386..391

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

                    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

                          idb.open(dbName)
                            .then(db => Sticky.update(sticky, db))
                            .then(() => {
                              getSidebarPorts().concat(port).forEach(p => p.postMessage({
                                type:    'saved-sticky',
                    Severity: Minor
                    Found in src/background.js and 1 other location - About 50 mins to fix
                    src/background.js on lines 137..149

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

                    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

                          api.isLoggedIn().then((isLoggedIn) => {
                            if (isLoggedIn) {
                              sticky.state = Sticky.State.Deleted;
                              sticky.updated_at = new Date();
                              return idb.open(dbName).then(db => Sticky.update(sticky, db));
                    Severity: Minor
                    Found in src/background.js and 1 other location - About 50 mins to fix
                    src/background.js on lines 122..129

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

                    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