prismicio/javascript-kit

View on GitHub

Showing 126 of 126 total issues

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

Color.prototype = {
  /**
   * Turns the fragment into a useable HTML version of it.
   * If the native HTML code doesn't suit your design, this function is meant to be overriden.
   *
Severity: Major
Found in lib/fragments.js and 2 other locations - About 1 hr to fix
lib/fragments.js on lines 17..36
lib/fragments.js on lines 269..288

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

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

  getText: function(name, after) {
    var Fragments = require('./fragments');
    var fragment = this.get(name);

    if (fragment instanceof Fragments.StructuredText) {
Severity: Minor
Found in lib/documents.js - About 1 hr to fix

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

      request: function(url, callback) {
        var api = this;
        var cacheKey = url + (this.accessToken ? ('#' + this.accessToken) : '');
        var cache = this.apiCache;
        function run(cb) {
    Severity: Minor
    Found in lib/api.js - About 1 hr to fix

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

      var fetchRequest = (function() {
        if (typeof fetch == "function") {
          var pjson = require('../package.json');
          return function(requestUrl, callback) {
            fetch(requestUrl, {
      Severity: Minor
      Found in lib/requests.js - About 1 hr to fix

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

        var ajaxRequest = (function() {
          if(typeof XMLHttpRequest != 'undefined' && 'withCredentials' in new XMLHttpRequest()) {
            return function(url, callback) {
        
              var xhr = new XMLHttpRequest();
        Severity: Minor
        Found in lib/requests.js - About 1 hr to fix

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

              var nonRepeatText = Object.keys(this.nonRepeat).reduce(function(acc, key) {
                return acc + self.nonRepeat[key].asText(linkResolver);
              }, "");
          Severity: Major
          Found in lib/fragments.js and 1 other location - About 1 hr to fix
          lib/fragments.js on lines 1089..1091

          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 nonRepeatHtml = Object.keys(this.nonRepeat).reduce(function(acc, key) {
                return acc + self.nonRepeat[key].asHtml(linkResolver);
              }, "");
          Severity: Major
          Found in lib/fragments.js and 1 other location - About 1 hr to fix
          lib/fragments.js on lines 1106..1108

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

            getFirstParagraph: function() {
              return this.toArray().reduce(function(st, fragment) {
                if (st) return st;
                else {
                  return fragment.getFirstParagraph();
          Severity: Major
          Found in lib/fragments.js and 2 other locations - About 1 hr to fix
          lib/fragments.js on lines 699..706
          lib/fragments.js on lines 708..715

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

            getFirstTitle: function() {
              return this.toArray().reduce(function(st, fragment) {
                if (st) return st;
                else {
                  return fragment.getFirstTitle();
          Severity: Major
          Found in lib/fragments.js and 2 other locations - About 1 hr to fix
          lib/fragments.js on lines 699..706
          lib/fragments.js on lines 717..724

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

            getFirstImage: function() {
              return this.toArray().reduce(function(image, fragment) {
                if (image) return image;
                else {
                  return fragment.getFirstImage();
          Severity: Major
          Found in lib/fragments.js and 2 other locations - About 1 hr to fix
          lib/fragments.js on lines 708..715
          lib/fragments.js on lines 717..724

          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

          Function get has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

          LRUCache.prototype.get = function(key, returnEntry) {
            // First, find our cache entry
            var entry = this._keymap[key];
            if (entry === undefined) return null; // Not cached. Sorry.
            // As <key> was found in the cache, register it as being requested recently
          Severity: Minor
          Found in lib/lru.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 get has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            get: function(callback) {
              var self = this;
              var cacheKey = this.apiCacheKey;
          
              return new Promise(function (resolve, reject) {
          Severity: Minor
          Found in lib/api.js - About 1 hr to fix

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

              getNumber: function(name) {
                var Fragments = require('./fragments');
                var fragment = this.get(name);
            
                if (fragment instanceof Fragments.Number) {
            Severity: Major
            Found in lib/documents.js and 3 other locations - About 1 hr to fix
            lib/documents.js on lines 167..175
            lib/documents.js on lines 185..193
            lib/documents.js on lines 319..327

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

            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

              getTimestamp: function(name) {
                var Fragments = require('./fragments');
                var fragment = this.get(name);
            
                if (fragment instanceof Fragments.Timestamp) {
            Severity: Major
            Found in lib/documents.js and 3 other locations - About 1 hr to fix
            lib/documents.js on lines 185..193
            lib/documents.js on lines 302..310
            lib/documents.js on lines 319..327

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

            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

              getDate: function(name) {
                var Fragments = require('./fragments');
                var fragment = this.get(name);
            
                if (fragment instanceof Fragments.Date) {
            Severity: Major
            Found in lib/documents.js and 3 other locations - About 1 hr to fix
            lib/documents.js on lines 167..175
            lib/documents.js on lines 302..310
            lib/documents.js on lines 319..327

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

            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

              getColor: function(name) {
                var Fragments = require('./fragments');
                var fragment = this.get(name);
            
                if (fragment instanceof Fragments.Color) {
            Severity: Major
            Found in lib/documents.js and 3 other locations - About 1 hr to fix
            lib/documents.js on lines 167..175
            lib/documents.js on lines 185..193
            lib/documents.js on lines 302..310

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

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

            function Response(page, results_per_page, results_size, total_results_size, total_pages, next_page, prev_page, results) {
            Severity: Major
            Found in lib/api.js - About 1 hr to fix

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

                getFirstParagraph: function() {
                  return this.value.reduce(function(paragraph, slice) {
                    if (paragraph) return paragraph;
                    else {
                      return slice.getFirstParagraph();
              Severity: Major
              Found in lib/fragments.js and 2 other locations - About 55 mins to fix
              lib/fragments.js on lines 1224..1231
              lib/fragments.js on lines 1233..1240

              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

                if (desc) {
                  entry = this.tail;
                  while (entry) {
                    fun.call(context, entry.key, entry.value, this);
                    entry = entry.older;
              Severity: Minor
              Found in lib/lru.js and 1 other location - About 55 mins to fix
              lib/lru.js on lines 221..227

              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

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

                    Api.form('everything').ref(Api.master()).query(
                      Predicates.has("my.doc.title")
                    ).submit(function (err, documents) {
                      if (err) {
                        console.log(err);
              Severity: Minor
              Found in browsertests/browser.js and 1 other location - About 55 mins to fix
              browsertests/browser.js on lines 309..316

              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