prismicio/javascript-kit

View on GitHub

Showing 126 of 126 total issues

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

  asText: function(linkResolver) {
    var output = "";
    for (var i = 0; i < this.value.length; i++) {
      output += this.value[i].asText(linkResolver) + '\n';
    }
Severity: Major
Found in lib/fragments.js and 1 other location - About 2 hrs to fix
lib/fragments.js on lines 691..697

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

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 ajaxRequest has a Cognitive Complexity of 17 (exceeds 5 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 2 hrs 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 submit has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

  submit: function(callback) {
    var self = this;
    var url = this.form.action;

    if (this.data) {
Severity: Minor
Found in lib/api.js - About 2 hrs 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 parse has 56 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  parse: function(data) {
    var refs,
        master,
        forms = {},
        form,
Severity: Major
Found in lib/api.js - About 2 hrs to fix

    prototype has 21 functions (exceeds 20 allowed). Consider refactoring.
    Open

    Api.prototype = {
    
      // Predicates
      AT: "at",
      ANY: "any",
    Severity: Minor
    Found in lib/api.js - About 2 hrs to fix

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

      var nodeJSRequest = (function() {
        if(typeof require == 'function' && require('http')) {
          var http = require('http'),
              https = require('https'),
              url = require('url'),
      Severity: Major
      Found in lib/requests.js - About 2 hrs to fix

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

              Api.form('everything').ref(Api.master()).orderings('[my.product.price desc]').submit(function (err, documents) {
                if (err) { console.log(err); }
                assert.equal(documents.results.length, 20);
                assert.equal(documents.results[0].id, 'UlfoxUnM0wkXYXbj');
                done();
        Severity: Major
        Found in browsertests/browser.js and 1 other location - About 2 hrs to fix
        browsertests/browser.js on lines 158..165

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

        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()).orderings(['my.product.price desc']).submit(function (err, documents) {
                if (err) {
                  console.log(err);
                }
                assert.equal(documents.results.length, 20);
        Severity: Major
        Found in browsertests/browser.js and 1 other location - About 2 hrs to fix
        browsertests/browser.js on lines 143..148

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

        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

          asHtml: function (linkResolver) {
            var output = "";
            for (var i = 0; i < this.value.length; i++) {
              output += this.value[i].asHtml(linkResolver);
            }
        Severity: Major
        Found in lib/fragments.js and 1 other location - About 2 hrs to fix
        lib/fragments.js on lines 669..675

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

        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

          asHtml: function(linkResolver) {
            var output = "";
            for (var i = 0; i < this.value.length; i++) {
              output += this.value[i].asHtml(linkResolver);
            }
        Severity: Major
        Found in lib/fragments.js and 1 other location - About 2 hrs to fix
        lib/fragments.js on lines 1203..1209

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

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

        function serialize(element, content, htmlSerializer) {
          // Return the user customized output (if available)
          if (htmlSerializer) {
            var custom = htmlSerializer(element, content);
            if (custom) {
        Severity: Minor
        Found in lib/fragments.js - About 2 hrs to fix

          Function asHtml has 49 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            asHtml: function(linkResolver, htmlSerializer) {
              var blockGroups = [],
                  blockGroup,
                  block,
                  html = [];
          Severity: Minor
          Found in lib/fragments.js - About 1 hr to fix

            Function initField has 47 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function initField(field) {
            
              var classForType = {
                "Color": Color,
                "Number": Num,
            Severity: Minor
            Found in lib/fragments.js - About 1 hr to fix

              Function linkedDocuments has 44 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                linkedDocuments: function() {
                  var i, j, link;
                  var result = [];
                  var Fragments = require('./fragments');
                  for (var field in this.data) {
              Severity: Minor
              Found in lib/documents.js - About 1 hr to fix

                Function previewSession has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  previewSession: function(token, linkResolver, defaultUrl, callback) {
                    var api = this;
                    return new Promise(function(resolve, reject) {
                      var cb = function(err, value, xhr) {
                        if (callback) callback(err, value, xhr);
                Severity: Minor
                Found in lib/api.js - About 1 hr to fix

                  Function insertSpans has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function insertSpans(text, spans, linkResolver, htmlSerializer) {
                    if (!spans || !spans.length) {
                      return htmlEscape(text);
                    }
                  
                  
                  Severity: Minor
                  Found in lib/fragments.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 Document has 12 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                  function Document(id, uid, type, href, tags, slugs, firstPublicationDate, lastPublicationDate, lang, alternateLanguages, data, rawJSON) {
                  Severity: Major
                  Found in lib/documents.js - About 1 hr to fix

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

                    function getApi(url, options) {
                      options = options || {};
                      if (typeof arguments[1] == 'function') {
                        // Legacy (1) the second argument is the callback
                        options = {
                    Severity: Minor
                    Found in lib/prismic.js - About 1 hr to fix

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

                      Text.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 269..288
                      lib/fragments.js on lines 303..322

                      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

                      Select.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 303..322

                      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

                      Severity
                      Category
                      Status
                      Source
                      Language