realpython/members

View on GitHub

Showing 83 of 83 total issues

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

function getUsers(callback) {
  return knex('users')
  .select('*')
  .then((users) => {
    callback(null, users);
Severity: Major
Found in src/server/db/queries/users.js and 1 other location - About 1 hr to fix
src/server/db/queries/users.js on lines 56..65

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

function getTotalUsers(callback) {
  return knex('users')
  .count('*')
  .then((users) => {
    callback(null, users);
Severity: Major
Found in src/server/db/queries/users.js and 1 other location - About 1 hr to fix
src/server/db/queries/users.js on lines 45..54

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

  function insertMessages(userID) {
    return Promise.all([
      knex('messages')
      .insert({
        content: 'Awesome lesson!',
Severity: Minor
Found in src/server/db/_seed_helpers.js - About 1 hr to fix

    Function addNewLesson has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function addNewLesson(req, res, next) {
      // TODO: Add server side validation
      const payload = req.body;
      const chapterID = parseInt(payload.chapter);
      const lesson = {
    Severity: Minor
    Found in src/server/routes/admin/admin.lessons.js - About 1 hr to fix

      Function ensureVerified has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        function ensureVerified(req, res, next) {
          if (req.user) {
            if (req.user.verified) {
              const userID = parseInt(req.user.id);
              userQueries.getSingleUserByID(userID, (err, user) => {
      Severity: Minor
      Found in src/server/auth/helpers.js - About 1 hr to fix

        Function insertCodes has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          function insertCodes() {
            return Promise.all([
              knex('codes').insert({
                verify_code: 'oGvufQsOUL7264B8M0g4J5lkr1VcyYiR'
              }),
        Severity: Minor
        Found in src/server/db/_seed_helpers.js - About 1 hr to fix

          Function expandFirstUnreadChapter has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

          function expandFirstUnreadChapter() {
            var current = (location.pathname).split('/');
            if (current[1] !== 'lessons' && current[1] !== 'search') {
              var elements = $('.sidebar-chapter-name');
              for (var i = 0; i < elements.length; i++) {
          Severity: Minor
          Found in src/client/js/user.js - 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

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

                return lessonQueries.deactivateLessonsFromChapterID(chapterID)
                .then(function(lessons) {
                  req.flash('messages', {
                    status: 'success',
                    value: 'Chapter deactivated.'
          Severity: Major
          Found in src/server/routes/admin/admin.chapters.js and 1 other location - About 1 hr to fix
          src/server/routes/lessons.js on lines 63..70

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

          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 lessonQueries.getLessonsFromChapterID(chapterID)
                .then(function(lessons) {
                  req.flash('messages', {
                    status: 'success',
                    value: 'Status updated.'
          Severity: Major
          Found in src/server/routes/lessons.js and 1 other location - About 1 hr to fix
          src/server/routes/admin/admin.chapters.js on lines 136..143

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

          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

              var renderObject = {
                title: 'Textbook LMS - search',
                pageTitle: 'Search',
                user: req.user,
                sortedChapters: data.sortedChapters,
          Severity: Major
          Found in src/server/routes/search.js and 1 other location - About 1 hr to fix
          src/server/routes/contact.js on lines 22..29

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

          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

              const renderObject = {
                title: 'Textbook LMS - contact',
                pageTitle: 'Contact',
                user: req.user,
                sortedChapters: data.sortedChapters,
          Severity: Major
          Found in src/server/routes/contact.js and 1 other location - About 1 hr to fix
          src/server/routes/search.js on lines 19..26

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

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

            function ensureAdmin(req, res, next) {
              if (req.user) {
                if (req.user.admin) {
                  const userID = parseInt(req.user.id);
                  // return next();
          Severity: Minor
          Found in src/server/auth/helpers.js - About 1 hr to fix

            Function init has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              routeConfig.init = (app) => {
            
                // *** routes *** //
                const routes = require('../routes/index');
                const contactRoutes = require('../routes/contact');
            Severity: Minor
            Found in src/server/config/route.config.js - About 1 hr to fix

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

                    return messageQueries.deactivateChildMessagesFromParent(messageID)
                    .then(function(messages) {
                      req.flash('messages', {
                        status: 'success',
                        value: 'Message(s) deactivated.'
              Severity: Major
              Found in src/server/routes/admin/admin.messages.js and 1 other location - About 1 hr to fix
              src/server/routes/admin/admin.messages.js on lines 14..21

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

              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 messageQueries.updateMessageUpdatedAt(messageID)
                .then(function(message) {
                  req.flash('messages', {
                    status: 'success',
                    value: 'Message updated.'
              Severity: Major
              Found in src/server/routes/admin/admin.messages.js and 1 other location - About 1 hr to fix
              src/server/routes/admin/admin.messages.js on lines 39..46

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

              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

                const lessonObject = {
                  lesson_order_number: payload.lessonOrderNumber,
                  chapter_order_number: payload.chapterOrderNumber,
                  name: payload.lessonName,
                  content: payload.lessonContent,
              Severity: Major
              Found in src/server/routes/admin/admin.lessons.js and 1 other location - About 1 hr to fix
              src/server/routes/_helpers.js on lines 27..34

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

              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

                  acc[val.chapterID].lessons.push({
                    lessonID: val.lessonID,
                    lessonLessonOrder: val.lessonLessonOrder,
                    lessonChapterOrder: val.lessonChapterOrder,
                    lessonName: val.lessonName,
              Severity: Major
              Found in src/server/routes/_helpers.js and 1 other location - About 1 hr to fix
              src/server/routes/admin/admin.lessons.js on lines 91..98

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

              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 createLesson has 8 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  lessonOrder, chapterOrder, lessonName,
                  lessonContent, chapterID, lessonActive,
                  knex, Promise
              Severity: Major
              Found in src/server/db/_seed_helpers.js - About 1 hr to fix

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

                  staging: {
                    client: 'postgresql',
                    connection: process.env.DATABASE_URL,
                    migrations: {
                      directory: __dirname + '/build/server/db/migrations'
                Severity: Minor
                Found in knexfile.js and 1 other location - About 55 mins to fix
                knexfile.js on lines 32..41

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

                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

                  production: {
                    client: 'postgresql',
                    connection: process.env.DATABASE_URL,
                    migrations: {
                      directory: __dirname + '/build/server/db/migrations'
                Severity: Minor
                Found in knexfile.js and 1 other location - About 55 mins to fix
                knexfile.js on lines 22..31

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

                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