prismicio/javascript-kit

View on GitHub

Showing 126 of 126 total issues

File fragments.js has 774 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"use strict";

var documents = require('./documents');
var DateUtils = require('./utils/date');
var WithFragments = documents.WithFragments;
Severity: Major
Found in lib/fragments.js - About 1 day to fix

    File api.js has 526 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    'use strict';
    
    var Requests = require('./requests'),
        Cookies = require('./cookies'),
        documents = require('./documents'),
    Severity: Major
    Found in lib/api.js - About 1 day to fix

      Function linkedDocuments has a Cognitive Complexity of 47 (exceeds 5 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 7 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

      File browser.js has 394 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      /*eslint-env node, mocha */
      /*global chai, Prismic */
      /*eslint no-unused-vars: 0 */
      
      var assert = chai.assert;
      Severity: Minor
      Found in browsertests/browser.js - About 5 hrs to fix

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

          it('Submit the `products` form with a predicate', function (done) {
            Prismic.api(testRepository, function (err, Api) {
              if (err) throw err;
              Api.form('products').ref(Api.master()).query('[[:d = at(my.product.flavour, "Chocolate")]]').submit(function (err, documents) {
                if (err) {
        Severity: Major
        Found in browsertests/browser.js and 2 other locations - About 4 hrs to fix
        browsertests/browser.js on lines 259..271
        browsertests/browser.js on lines 381..393

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

        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

          it('Submit the `products` form with an empty query', function (done) {
            Prismic.api(testRepository, function (err, Api) {
              if (err) throw err;
              Api.form('products').ref(Api.master()).query('').submit(function (err, documents) {
                if (err) {
        Severity: Major
        Found in browsertests/browser.js and 2 other locations - About 4 hrs to fix
        browsertests/browser.js on lines 259..271
        browsertests/browser.js on lines 367..379

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

        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

          it('Submit the `everything` form with a predicate that give no results', function (done) {
            Prismic.api(testRepository, function (err, Api) {
              if (err) throw err;
              Api.form('everything').ref(Api.master()).query('[[:d = at(document.type, "youhou")]]').submit(function (err, documents) {
                if (err) {
        Severity: Major
        Found in browsertests/browser.js and 2 other locations - About 4 hrs to fix
        browsertests/browser.js on lines 367..379
        browsertests/browser.js on lines 381..393

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

        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

        File documents.js has 341 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        "use strict";
        
        var DateUtils = require('./utils/date');
        
        /**
        Severity: Minor
        Found in lib/documents.js - About 4 hrs to fix

          Function getText has a Cognitive Complexity of 25 (exceeds 5 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 3 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

          exports has 29 functions (exceeds 20 allowed). Consider refactoring.
          Open

          module.exports = {
          
            /**
             * Convert a predicate (array of 3 elements) into a query for prismic.io (string)
             */
          Severity: Minor
          Found in lib/predicates.js - About 3 hrs to fix

            Function asHtml has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
            Open

              asHtml: function(linkResolver, htmlSerializer) {
                var blockGroups = [],
                    blockGroup,
                    block,
                    html = [];
            Severity: Minor
            Found in lib/fragments.js - About 3 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 serialize has a Cognitive Complexity of 22 (exceeds 5 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 3 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

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

            DateFragment.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 2 hrs to fix
            lib/fragments.js on lines 377..400
            lib/fragments.js on lines 455..478

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

            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

            Timestamp.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 2 hrs to fix
            lib/fragments.js on lines 377..400
            lib/fragments.js on lines 416..439

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

            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

            Num.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 2 hrs to fix
            lib/fragments.js on lines 416..439
            lib/fragments.js on lines 455..478

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

            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

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

            WithFragments.prototype = {
              /**
               * Gets the fragment in the current Document object. Since you most likely know the type
               * of this fragment, it is advised that you use a dedicated method, like get StructuredText() or getDate(),
               * for instance.
            Severity: Minor
            Found in lib/documents.js - About 2 hrs to fix

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

              function Ref(ref, label, isMaster, scheduledAt, id) {
                /**
                 * @field
                 * @description the ID of the ref
                 */
              Severity: Major
              Found in lib/api.js and 1 other location - About 2 hrs to fix
              lib/fragments.js on lines 581..607

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

              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 ImageView(url, width, height, alt, copyright) {
                /**
                 * @field
                 * @description the URL of the ImageView (useable as it, in a <img> tag in HTML, for instance)
                 */
              Severity: Major
              Found in lib/fragments.js and 1 other location - About 2 hrs to fix
              lib/api.js on lines 833..859

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

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

              function insertSpans(text, spans, linkResolver, htmlSerializer) {
                if (!spans || !spans.length) {
                  return htmlEscape(text);
                }
              
              
              Severity: Major
              Found in lib/fragments.js - About 2 hrs to fix

                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 1216..1222

                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

                Severity
                Category
                Status
                Source
                Language