DemocracyOS/democracyos

View on GitHub

Showing 430 of 430 total issues

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

exports.removeReply = (function () {
  function verifyPrivileges (forum, user, replyId, comment) {
    if (privileges.canDeleteComments(forum, user)) return comment

    const reply = comment.replies.id(replyId)
Severity: Minor
Found in lib/api-v2/db-api/comments/index.js - About 1 hr to fix

    Function xssFilter has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    module.exports = function xssFilter (opts) {
      var defaults = {
        fontFace: false,
        fontSize: true,
        fontWidth: true,
    Severity: Minor
    Found in lib/richtext/lib/xss-filter.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

    Function signin has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function signin (req, res, next) {
      var email = normalizeEmail(req.body.email)
      auth(email, req.body.password, function (err, user, info) {
        if (err) return res.status(200).json({ error: t(err.message) })
    
    
    Severity: Minor
    Found in lib/api/signin/index.js - About 1 hr to fix

      Function onload has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          reader.onload = (event) => {
            const content = event.target.result
            fetch(`/api/v2/topics.csv?forum=${this.props.forum.id}`, {
              method: 'POST',
              credentials: 'same-origin',
      Severity: Minor
      Found in lib/admin/admin-topics/export-update/component.js - About 1 hr to fix

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

          _oninsert () {
            if (this.switchOn && typeof this.switchOn === 'function') {
              this.switchOn()
            }
            removed(this.el, this._onremove.bind(this))
        Severity: Major
        Found in lib/view/mixin.js and 1 other location - About 1 hr to fix
        lib/view/mixin.js on lines 44..49

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

        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 getUser (email) {
           return new Promise((resolve, reject) => {
             User.getByEmail(email, function (err, user) {
               if (err) {
                 return reject(err)
        Severity: Major
        Found in lib/db-api/notification.js and 1 other location - About 1 hr to fix
        lib/db-api/notification.js on lines 177..187

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

        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 getTopic (id) {
           return new Promise((resolve, reject) => {
             Topic.searchOne(id, function (err, topic) {
               if (err) {
                 return reject(err)
        Severity: Major
        Found in lib/db-api/notification.js and 1 other location - About 1 hr to fix
        lib/db-api/notification.js on lines 149..159

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

        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

          _onremove () {
            if (this.switchOff && typeof this.switchOff === 'function') {
              this.switchOff()
            }
            inserted(this.el, this._oninsert.bind(this))
        Severity: Major
        Found in lib/view/mixin.js and 1 other location - About 1 hr to fix
        lib/view/mixin.js on lines 32..37

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

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

          user: function user () {
            return function (req, res, next) {
              var qs = req.query ? req.query.access_token : ''
              var encoded = req.cookies.token || qs || req.headers['x-access-token']
        
        
        Severity: Minor
        Found in lib/jwt/index.js - About 1 hr to fix

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

                negative: new Array(parseInt(topic.action.results.find((o) => o.value === 'negative').percentage * topic.action.count)) || [],
          Severity: Major
          Found in lib/site/topic-layout/topic-article/vote/component.js and 2 other locations - About 1 hr to fix
          lib/site/topic-layout/topic-article/vote/component.js on lines 44..44
          lib/site/topic-layout/topic-article/vote/component.js on lines 46..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 62.

          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

                positive: new Array(parseInt(topic.action.results.find((o) => o.value === 'positive').percentage * topic.action.count)) || [],
          Severity: Major
          Found in lib/site/topic-layout/topic-article/vote/component.js and 2 other locations - About 1 hr to fix
          lib/site/topic-layout/topic-article/vote/component.js on lines 45..45
          lib/site/topic-layout/topic-article/vote/component.js on lines 46..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 62.

          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

                  {
                    topic.action.method && topic.action.method === 'slider' && (
                      <div className='topic-article-content'>
                        <Slider topic={topic} />
                      </div>
          Severity: Major
          Found in lib/site/topic-layout/topic-article/component.js and 3 other locations - About 1 hr to fix
          lib/site/topic-layout/topic-article/component.js on lines 112..118
          lib/site/topic-layout/topic-article/component.js on lines 119..125
          lib/site/topic-layout/topic-article/component.js on lines 133..139

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

          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 doUnvote (user, comment) {
            return new Promise((resolve, reject) => {
              comment.unvote(user, function (err) {
                if (err) return reject(err)
                resolve(comment)
          Severity: Major
          Found in lib/api-v2/db-api/comments/index.js and 1 other location - About 1 hr to fix
          lib/api-v2/db-api/comments/index.js on lines 422..429

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

          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

                  {
                    topic.action.method && topic.action.method === 'hierarchy' && (
                      <div className='topic-article-content'>
                        <Hierarchy topic={topic} />
                      </div>
          Severity: Major
          Found in lib/site/topic-layout/topic-article/component.js and 3 other locations - About 1 hr to fix
          lib/site/topic-layout/topic-article/component.js on lines 112..118
          lib/site/topic-layout/topic-article/component.js on lines 119..125
          lib/site/topic-layout/topic-article/component.js on lines 126..132

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

          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

                  {
                    topic.action.method && topic.action.method === 'poll' && (
                      <div className='topic-article-content'>
                        <Poll topic={topic} />
                      </div>
          Severity: Major
          Found in lib/site/topic-layout/topic-article/component.js and 3 other locations - About 1 hr to fix
          lib/site/topic-layout/topic-article/component.js on lines 119..125
          lib/site/topic-layout/topic-article/component.js on lines 126..132
          lib/site/topic-layout/topic-article/component.js on lines 133..139

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

          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

                neutral: new Array(parseInt(topic.action.results.find((o) => o.value === 'neutral').percentage * topic.action.count)) || []
          Severity: Major
          Found in lib/site/topic-layout/topic-article/vote/component.js and 2 other locations - About 1 hr to fix
          lib/site/topic-layout/topic-article/vote/component.js on lines 44..44
          lib/site/topic-layout/topic-article/vote/component.js on lines 45..45

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

          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 doUnflag (user, comment) {
            return new Promise((resolve, reject) => {
              comment.unflag(user, function (err) {
                if (err) return reject(err)
                resolve(comment)
          Severity: Major
          Found in lib/api-v2/db-api/comments/index.js and 1 other location - About 1 hr to fix
          lib/api-v2/db-api/comments/index.js on lines 155..162

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

          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

                  {
                    topic.action.method && topic.action.method === 'cause' && (
                      <div className='topic-article-content'>
                        <Cause topic={topic} />
                      </div>
          Severity: Major
          Found in lib/site/topic-layout/topic-article/component.js and 3 other locations - About 1 hr to fix
          lib/site/topic-layout/topic-article/component.js on lines 112..118
          lib/site/topic-layout/topic-article/component.js on lines 126..132
          lib/site/topic-layout/topic-article/component.js on lines 133..139

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

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

          module.exports = function listen (opts, callback) {
            if (!callback) callback = () => {}
          
            const servers = serverFactory(app, opts)
          
          
          Severity: Minor
          Found in lib/server/index.js - About 1 hr to fix

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

            exports.up = function up (done) {
              dbReady()
                .then(() => Topic.collection.find({}).toArray())
                .then(mapPromises(function (topic) {
                  if (!topic.action || !Object.keys(topic.action).includes('box')) return Promise.resolve(0)
            Severity: Minor
            Found in migrations/1503256241267-update-topic-votes.js - About 1 hr to fix
              Severity
              Category
              Status
              Source
              Language