TryGhost/Ghost

View on GitHub

Showing 1,820 of 4,015 total issues

Function getLastEventTimestamp has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    async getLastEventTimestamp(jobName, events = ['delivered', 'opened', 'failed']) {
        const startDate = new Date();
        
        let maxOpenedAt;
        let maxDeliveredAt;
Severity: Minor
Found in ghost/core/core/server/services/email-analytics/lib/queries.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 trimSameAs has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

function trimSameAs(data, context) {
    const sameAs = [];

    if (context === 'post' || context === 'page') {
        if (data[context].primary_author.website) {
Severity: Minor
Found in ghost/core/core/frontend/meta/schema.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 optimiseFilterCacheability has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

function optimiseFilterCacheability(resource, options) {
    const noOptimisation = {
        options,
        parseResult(result) {
            return result;
Severity: Minor
Found in ghost/core/core/frontend/helpers/get.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 transformApiSiteData has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

export function transformApiSiteData({site}) {
    try {
        if (!site) {
            return null;
        }
Severity: Minor
Found in apps/portal/src/utils/helpers.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 PortalLinks has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

const PortalLinks: React.FC = () => {
    const [isDataAttributes, setIsDataAttributes] = useState(false);
    const [selectedTier, setSelectedTier] = useState('');
    const {siteData} = useGlobalData();
    const {data: {tiers: allTiers} = {}} = useBrowseTiers();

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 NewsletterDetailModalContent has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

const NewsletterDetailModalContent: React.FC<{newsletter: Newsletter; onlyOne: boolean;}> = ({newsletter, onlyOne}) => {
    const {config} = useGlobalData();
    const {mutateAsync: editNewsletter} = useEditNewsletter();
    const {updateRoute} = useRouting();
    const handleError = useHandleError();

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 URLTextField has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

const URLTextField: React.FC<URLTextFieldProps> = ({baseUrl, value, transformPathWithoutSlash, nullable, onChange, ...props}) => {
    const [displayedUrl, setDisplayedUrl] = useState('');
    const {setFocusState} = useFocusContext();

    useEffect(() => {
Severity: Minor
Found in apps/admin-x-design-system/src/global/form/URLTextField.tsx - 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 ContentBox has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

const ContentBox: React.FC<Props> = ({done}) => {
    const luminance = (r: number, g: number, b: number) => {
        const a = [r, g, b].map(function (v) {
            v /= 255;
            return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
Severity: Minor
Found in apps/comments-ui/src/components/ContentBox.tsx - 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 btnStyles has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function btnStyles(options = {}) {
    let button = 'dib midgrey btn-base br3 ba b--lightgrey-l1 pointer glow';
    let span = 'f8 fw5 tracked-2 dib pt0 pb0 tc';

    // Set style
Severity: Minor
Found in ghost/admin/app/helpers/ui-btn.js - About 1 hr to fix

    Function chartOptions has 43 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        get chartOptions() {
            return {
                cutoutPercentage: 70,
                title: {
                    display: false
    Severity: Minor
    Found in ghost/admin/app/components/posts/feedback-events-chart.js - About 1 hr to fix

      Function mockMembersStats has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function mockMembersStats(server) {
          server.get('/members/stats/count', withPermissionsCheck(ALLOWED_ROLES, function (db, {queryParams}) {
              let {days} = queryParams;
      
              let firstSubscriberDays = faker.datatype.number({min: 30, max: 600});
      Severity: Minor
      Found in ghost/admin/mirage/config/members.js - About 1 hr to fix

        Function mockThemes has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export default function mockThemes(server) {
            server.get('/themes');
        
            server.get('/themes/active/', function ({themes}) {
                const theme = themes.findBy({active: true});
        Severity: Minor
        Found in ghost/admin/mirage/config/themes.js - About 1 hr to fix

          Function getDonationEvents has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              async getDonationEvents(options = {}, filter) {
                  options = {
                      ...options,
                      withRelated: [
                          'member',
          Severity: Minor
          Found in ghost/members-api/lib/repositories/EventRepository.js - About 1 hr to fix

            Function sanitizeData has 43 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    sanitizeData: function sanitizeData(data) {
                        const tableName = _.result(this.prototype, 'tableName');
                        let date;
            
                        _.each(data, (value, property) => {
            Severity: Minor
            Found in ghost/core/core/server/models/base/plugins/sanitize.js - About 1 hr to fix

              Function init has 43 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  init() {
                      if (this.service) {
                          return;
                      }
              
              

                Function constructor has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    constructor({SettingsModel, settingsCache, labsService, mail, singleUseTokenProvider, urlUtils, emailAddressService}) {
                        this.SettingsModel = SettingsModel;
                        this.settingsCache = settingsCache;
                        this.labs = labsService;
                        this.emailAddressService = emailAddressService;
                Severity: Minor
                Found in ghost/core/core/server/services/settings/SettingsBREADService.js - About 1 hr to fix

                  Function add has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      add({notifications}) {
                          const defaults = {
                              dismissible: true,
                              location: 'bottom',
                              status: 'alert',
                  Severity: Minor
                  Found in ghost/core/core/server/services/notifications/Notifications.js - About 1 hr to fix

                    Function addTableColumn has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    function addTableColumn(tableName, tableBuilder, columnName, columnSpec = schema[tableName][columnName]) {
                        let column;
                    
                        // creation distinguishes between text with fieldtype, string with maxlength and all others
                        if (columnSpec.type === 'text' && Object.prototype.hasOwnProperty.call(columnSpec, 'fieldtype')) {
                    Severity: Minor
                    Found in ghost/core/core/server/data/schema/commands.js - About 1 hr to fix

                      Function getStructuredData has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      function getStructuredData(metaData) {
                          let structuredData;
                          let card = 'summary';
                      
                          if (metaData.twitterImage || metaData.coverImage.url) {
                      Severity: Minor
                      Found in ghost/core/core/frontend/meta/structured-data.js - About 1 hr to fix

                        Function mockIntegrations has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        export default function mockIntegrations(server) {
                            server.get('/integrations/', paginatedResponse('integrations'));
                        
                            server.post('/integrations/', function ({integrations}, {requestBody}) {
                                let body = JSON.parse(requestBody);
                        Severity: Minor
                        Found in ghost/admin/mirage/config/integrations.js - About 1 hr to fix
                          Severity
                          Category
                          Status
                          Source
                          Language