Showing 1,756 of 3,886 total issues
Function formatRelativeTime
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
Open
export function formatRelativeTime(dateString: string, t: TranslationFunction): string {
const date = new Date(dateString);
const now = new Date();
// Diff is in seconds
- Read upRead up
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 PopupModal.js
has 281 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
import React from 'react';
import Frame from './Frame';
import {hasMode} from '../utils/check-mode';
import AppContext from '../AppContext';
import {getFrameStyles} from './Frame.styles';
File api.ts
has 281 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
import {AddComment, Comment} from '../AppContext';
function setupGhostApi({siteUrl = window.location.origin, apiUrl, apiKey}: {siteUrl: string, apiUrl: string, apiKey: string}) {
const apiPath = 'members/api';
File EditOfferModal.tsx
has 281 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
import NiceModal from '@ebay/nice-modal-react';
import PortalFrame from '../../membership/portal/PortalFrame';
import toast from 'react-hot-toast';
import {Button, ConfirmationModal, Form, PreviewModalContent, TextArea, TextField, showToast} from '@tryghost/admin-x-design-system';
import {ErrorMessages, useForm, useHandleError} from '@tryghost/admin-x-framework/hooks';
Function generate
has 68 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
generate() {
const title = faker.lorem.sentence();
const content = faker.lorem.paragraphs(faker.datatype.number({
min: 3,
max: 10
Function getAdapter
has 68 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
getAdapter(adapterName, adapterClassName, config) {
if (!adapterName || !adapterClassName) {
throw new errors.IncorrectUsageError({
message: 'getAdapter must be called with a adapterName and a adapterClassName.'
});
Function countRelations
has 68 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
countRelations() {
return {
signups(modelOrCollection) {
modelOrCollection.query('columns', 'posts.*', (qb) => {
qb.count('members_created_events.id')
Function createSessionFromMagicLink
has 68 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
const createSessionFromMagicLink = async function createSessionFromMagicLink(req, res, next) {
if (!req.url.includes('token=')) {
return next();
}
File PreviewModal.tsx
has 280 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
import NiceModal, {useModal} from '@ebay/nice-modal-react';
import clsx from 'clsx';
import React, {useEffect, useState} from 'react';
import useGlobalDirtyState from '../../hooks/useGlobalDirtyState';
import {confirmIfDirty} from '../../utils/modals';
Function AddIntegrationModal
has 67 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
const AddIntegrationModal: React.FC<RoutingModalProps> = () => {
const modal = useModal();
const {updateRoute} = useRouting();
const [name, setName] = useState('');
const [errors, setErrors] = useState({name: ''});
OfferPage
has 24 functions (exceeds 20 allowed). Consider refactoring. Open
Open
export default class OfferPage extends React.Component {
static contextType = AppContext;
constructor(props, context) {
super(props, context);
SignupPage
has 24 functions (exceeds 20 allowed). Consider refactoring. Open
Open
class SignupPage extends React.Component {
static contextType = AppContext;
constructor(props) {
super(props);
File members.js
has 277 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
import faker from 'faker';
import moment from 'moment-timezone';
import nql from '@tryghost/nql';
import {Response} from 'miragejs';
import {
Function getDescription
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function getDescription(data, root, options = {}) {
const context = root ? root.context : null;
let description = '';
Function up
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async function up(knex) {
logging.info('Resolving the orphaned webhooks');
const orphanedWebhooks = await knex('webhooks')
.select('webhooks.id')
Function fetchOembedDataFromUrl
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async fetchOembedDataFromUrl(url, type, options = {}) {
try {
const urlObject = new URL(url);
// Trimming solves the difference of url validation between `new URL(url)`
Function getReferrerDetails
has 65 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
getReferrerDetails(history) {
// Empty history will return null as it means script is not loaded
if (history.length === 0) {
return {
referrerSource: null,
Function onSaving
has 65 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
onSaving: function onSaving(newPage, attr, options) {
const self = this;
const tasks = [];
let passwordValidation = {};
Function apiKeyAuthenticateWithToken
has 65 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
const authenticateWithToken = async function apiKeyAuthenticateWithToken(originalUrl, token, ignoreMaxAge) {
const decoded = jwt.decode(token, {complete: true});
const jwtValidationOptions = ignoreMaxAge ? _.omit(JWT_OPTIONS_DEFAULTS, 'maxAge') : JWT_OPTIONS_DEFAULTS;
if (!decoded || !decoded.header) {
Function ping
has 65 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function ping(post) {
let pingXML;
const title = post.title;
const url = urlService.getUrlByResourceId(post.id, {absolute: true});