markdown-note/markdown-notes

View on GitHub
src/browser/notes/note.js

Summary

Maintainability
F
3 days
Test Coverage

Function Notes has 264 lines of code (exceeds 25 allowed). Consider refactoring.
Open

var Notes = function() {
  /**
   * Fetches the notes present in the given notebook.
   * @param  {String} notebookID Notebook ID
   * @param  {function} cbMain   Callback method that is sent an errror object
Severity: Major
Found in src/browser/notes/note.js - About 1 day to fix

    Function Notes has a Cognitive Complexity of 66 (exceeds 5 allowed). Consider refactoring.
    Open

    var Notes = function() {
      /**
       * Fetches the notes present in the given notebook.
       * @param  {String} notebookID Notebook ID
       * @param  {function} cbMain   Callback method that is sent an errror object
    Severity: Minor
    Found in src/browser/notes/note.js - About 1 day 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 note.js has 273 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /*************************************************
     * Contains code to communicate with the Notes
     * database.
     * @author : Abijeet Patro
     *************************************************/
    Severity: Minor
    Found in src/browser/notes/note.js - About 2 hrs to fix

      Function changeNoteDate has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        function changeNoteDate(noteID, updatedDate, isComplete, cbMain) {
          var notesDb = _app.getNotesDb();
          var err = null;
          if (!noteID) {
            err = new _appError(new Error('Please provide the note ID.'),
      Severity: Minor
      Found in src/browser/notes/note.js - About 1 hr to fix

        Function _modifyNote has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          function _modifyNote(noteObj, isNewNote, cbMain) {
            if (!_validateNote(noteObj, isNewNote)) {
              return cbMain(new _appError(new Error('Invalid note object'),
                _i18n.__('error.notes_save_validation_err')));
            }
        Severity: Minor
        Found in src/browser/notes/note.js - About 1 hr to fix

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

            function getAllActiveNotes(notebookID, cbMain) {
              var notesDb = _app.getNotesDb();
              var dtNow = new Date();
              notesDb.find({
                $where: function() {
          Severity: Minor
          Found in src/browser/notes/note.js - About 1 hr to fix

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

              function getCompletedNotesForDate(notebookID, date, cbMain) {
                var notesDb = _app.getNotesDb();
                var dtSelectedDate = date;
                notesDb.find({
                  $where: function() {
            Severity: Minor
            Found in src/browser/notes/note.js - About 1 hr to fix

              Use path.join() or path.resolve() instead of + to create paths.
              Open

              var _appConfig = require(__dirname + '/../../../config.js');
              Severity: Minor
              Found in src/browser/notes/note.js by eslint

              Disallow string concatenation when using __dirname and __filename (no-path-concat)

              In Node.js, the __dirname and __filename global variables contain the directory path and the file path of the currently executing script file, respectively. Sometimes, developers try to use these variables to create paths to other files, such as:

              var fullPath = __dirname + "/foo.js";

              However, there are a few problems with this. First, you can't be sure what type of system the script is running on. Node.js can be run on any computer, including Windows, which uses a different path separator. It's very easy, therefore, to create an invalid path using string concatenation and assuming Unix-style separators. There's also the possibility of having double separators, or otherwise ending up with an invalid path.

              In order to avoid any confusion as to how to create the correct path, Node.js provides the path module. This module uses system-specific information to always return the correct value. So you can rewrite the previous example as:

              var fullPath = path.join(__dirname, "foo.js");

              This example doesn't need to include separators as path.join() will do it in the most appropriate manner. Alternately, you can use path.resolve() to retrieve the fully-qualified path:

              var fullPath = path.resolve(__dirname, "foo.js");

              Both path.join() and path.resolve() are suitable replacements for string concatenation wherever file or directory paths are being created.

              Rule Details

              This rule aims to prevent string concatenation of directory paths in Node.js

              Examples of incorrect code for this rule:

              /*eslint no-path-concat: "error"*/
              
              var fullPath = __dirname + "/foo.js";
              
              var fullPath = __filename + "/foo.js";

              Examples of correct code for this rule:

              /*eslint no-path-concat: "error"*/
              
              var fullPath = dirname + "/foo.js";

              When Not To Use It

              If you want to allow string concatenation of path names. Source: http://eslint.org/docs/rules/

              TODO found
              Open

                    // TODO Add proper error.
              Severity: Minor
              Found in src/browser/notes/note.js by fixme

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

                  notesDb.findOne({
                    _id: noteID
                  }, function(err, noteObj) {
                    if (err) {
                      return cbMain(new _appError(err, _i18n.__('error.note_fetch_error')));
              Severity: Major
              Found in src/browser/notes/note.js and 1 other location - About 1 hr to fix
              src/browser/notebooks/notebook.js on lines 74..81

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

              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

                return {
                  getNoteByID: getNoteByID,
                  modifyNote: _modifyNote,
                  deleteNote: deleteNote,
                  getAllActiveNotes: getAllActiveNotes,
              Severity: Major
              Found in src/browser/notes/note.js and 2 other locations - About 40 mins to fix
              src/browser/notebooks/notebook-utils.js on lines 74..84
              src/browser/notebooks/notebook.js on lines 168..178

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

              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(err, numReplaced) {
                    if (numReplaced <= 0) {
                      err = new _appError(err, _i18n.__('error.notes_update_err'));
                    }
                    return cbMain(err, noteObj);
              Severity: Minor
              Found in src/browser/notes/note.js and 1 other location - About 35 mins to fix
              src/browser/notes/note.js on lines 90..95

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

              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

                    }, noteObj, function(err, numReplaced) {
                      if (numReplaced <= 0) {
                        err = new _appError(err, _i18n.__('error.notes_update_err'));
                      }
                      return cbNoteModified(err, noteObj);
              Severity: Minor
              Found in src/browser/notes/note.js and 1 other location - About 35 mins to fix
              src/browser/notes/note.js on lines 335..340

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

              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