TryGhost/Ghost

View on GitHub

Showing 1,820 of 4,015 total issues

Function content has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

module.exports = function content(options = {}) {
    let self = this;
    let args = arguments;

    const hash = options.hash || {};
Severity: Minor
Found in ghost/core/core/frontend/helpers/content.js - About 45 mins 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 pickTemplate has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

_private.pickTemplate = function pickTemplate(templateList, fallback) {
    let template;

    if (!_.isArray(templateList)) {
        templateList = [templateList];
Severity: Minor
Found in ghost/core/core/frontend/services/rendering/templates.js - About 45 mins 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

Avoid deeply nested control flow statements.
Open

    } else if (_.includes(context, 'page') && data.post) {
        // Page description dependent on legacy object formatting (https://github.com/TryGhost/Ghost/issues/10042)
        if (options.property) {
            description = data.post[`${options.property}_description`]
                || data.post.custom_excerpt
Severity: Major
Found in ghost/core/core/frontend/meta/description.js - About 45 mins to fix

    Function getAnnouncementBarHelper has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    function getAnnouncementBarHelper(data) {
        const preview = data?.site?._preview;
        const isFilled = settingsCache.get('announcement_content') && settingsCache.get('announcement_visibility').length;
    
        if (!isFilled && !preview) {
    Severity: Minor
    Found in ghost/core/core/frontend/helpers/ghost_head.js - About 45 mins 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 match has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    module.exports = function match(...attrs) {
        // options = options || {};
        // options.hash = options.hash || {};
        // options.data = options.data || {};
    
    
    Severity: Minor
    Found in ghost/core/core/frontend/helpers/match.js - About 45 mins 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

    Avoid deeply nested control flow statements.
    Open

            if (options.property) {
                description = data.post[`${options.property}_description`]
                    || data.post.custom_excerpt
                    || data.post.meta_description
                    || generateExcerpt(data.post.excerpt || '', {words: 50})
    Severity: Major
    Found in ghost/core/core/frontend/meta/description.js - About 45 mins to fix

      Function getCoverImage has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      function getCoverImage(data) {
          const context = data.context ? data.context : null;
          const contextObject = getContextObject(data, context);
      
          if (_.includes(context, 'home') || _.includes(context, 'author')) {
      Severity: Minor
      Found in ghost/core/core/frontend/meta/cover-image.js - About 45 mins 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 getSchema has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      function getSchema(metaData, data) {
          if (!config.isPrivacyDisabled('useStructuredData')) {
              const context = data.context ? data.context : null;
              if (_.includes(context, 'post') || _.includes(context, 'page') || _.includes(context, 'amp')) {
                  return getPostSchema(metaData, data);
      Severity: Minor
      Found in ghost/core/core/frontend/meta/schema.js - About 45 mins 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 _doGet has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          _doGet(key, options) {
              // NOTE: "!this.settingsCache" is for when setting's cache is used
              //       before it had a chance to initialize. Should be fixed when
              //       it is decoupled from the model layer
              if (!this.settingsCache) {
      Severity: Minor
      Found in ghost/core/core/shared/settings-cache/CacheManager.js - About 45 mins 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 memberCountRounding has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      const memberCountRounding = (memberCount) => {
          if (memberCount <= 50) {
              return memberCount;
          }
      
      
      Severity: Minor
      Found in ghost/core/core/frontend/utils/member-count.js - About 45 mins 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 handle has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          async handle(argv = {}) {
              const _ = require('lodash');
              // knex has to be loaded _after_ the call to setup()
              // the db connection requires nconf which passes argv to yargs,
              // which intercepts --help and stops execution
      Severity: Minor
      Found in ghost/core/core/cli/timetravel.js - About 45 mins 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 fromApiResponse has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          static async fromApiResponse(res) {
              // Bad request + Too many requests
              if (res.status === 400 || res.status === 429) {
                  try {
                      const json = await res.json();
      Severity: Minor
      Found in apps/portal/src/utils/errors.js - About 45 mins 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 getQueryPrice has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      export function getQueryPrice({site = {}, priceId}) {
          const prices = getAvailablePrices({site});
          if (priceId === 'free') {
              return !prices || prices.length === 0 || prices.find(p => p.type === 'free');
          } else if (prices && prices.length > 0 && priceId === 'monthly') {
      Severity: Minor
      Found in apps/portal/src/utils/helpers.js - About 45 mins 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 handler has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      module.exports = function handler(siteApp) {
          const verifyResourceType = function verifyResourceType(req, res, next) {
              const resourceWithoutPage = req.params.resource.replace(/-\d+$/, '');
              if (!Object.prototype.hasOwnProperty.call(manager, resourceWithoutPage)) {
                  return res.sendStatus(404);
      Severity: Minor
      Found in ghost/core/core/frontend/services/sitemap/handler.js - About 45 mins 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 fetchBookmarkData has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          async fetchBookmarkData(url, html) {
              const gotOpts = {
                  headers: {
                      'User-Agent': USER_AGENT
                  }
      Severity: Minor
      Found in ghost/oembed-service/lib/OEmbedService.js - About 45 mins 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 invertColor has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      function invertColor(hex = '', bw = true) {
          if (!hex || !hex.match(/#[0-9A-Fa-f]{6}$/)) {
              // Return white in case not a valid hex
              return '#000000';
          }
      Severity: Minor
      Found in apps/portal/src/utils/contrast-color.js - About 45 mins 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 onPlanCheckout has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          onPlanCheckout(e, priceId) {
              const {onAction, member} = this.context;
              let {confirmationPlan, selectedPlan} = this.state;
              if (priceId) {
                  selectedPlan = priceId;
      Severity: Minor
      Found in apps/portal/src/components/pages/AccountPlanPage.js - About 45 mins 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 ProductsSection has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      function ProductsSection({onPlanSelect, products, type = null, handleChooseSignup, errors}) {
          const {site, member, t} = useContext(AppContext);
          const {portal_plans: portalPlans, portal_default_plan: portalDefaultPlan} = site;
          const defaultProductId = products.length > 0 ? products[0].id : 'free';
      
      
      Severity: Minor
      Found in apps/portal/src/components/common/ProductsSection.js - About 45 mins 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 equals has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      function equals(a: unknown, b: unknown) {
          if (a === null || b === null) {
              return a === b;
          }
          if (a === undefined || b === undefined) {
      Severity: Minor
      Found in ghost/ghost/src/common/entity.base.ts - About 45 mins 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 addPost has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          addPost(post: CollectionPost, index: number = -0) {
              if (this.slug === 'latest') {
                  return false;
              }
              if (this.type === 'automatic') {
      Severity: Minor
      Found in ghost/collections/src/Collection.ts - About 45 mins 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

      Severity
      Category
      Status
      Source
      Language