Skip to content

Commit

Permalink
Ban non-relative imports from utils (#1626)
Browse files Browse the repository at this point in the history
* Ban non-relative imports from utils

* Changeset
  • Loading branch information
emma-imber authored Oct 18, 2024
1 parent 629b29e commit 53d892b
Show file tree
Hide file tree
Showing 48 changed files with 72 additions and 62 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-tigers-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@guardian/commercial': minor
---

Use relative imports when importing from utils
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
{
patterns: [
{
group: ['core/*'],
group: ['core/*', 'utils/*'],
message:
'Paths starting with “core”, are forbidden. Please use a relative path instead',
},
Expand Down
2 changes: 1 addition & 1 deletion src/core/messenger/background.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { isObject } from '@guardian/libs';
import fastdom from 'utils/fastdom-promise';
import {
renderAdvertLabel,
renderStickyScrollForMoreLabel,
} from '../../events/render-advert-label';
import fastdom from '../../utils/fastdom-promise';
import {
initVideoProgressReporting,
updateVideoProgress,
Expand Down
2 changes: 1 addition & 1 deletion src/core/messenger/passback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { log } from '@guardian/libs';
import { breakpoints } from '@guardian/source/foundations';
import { getCurrentBreakpoint } from 'lib/detect/detect-breakpoint';
import { getAdvertById } from 'lib/dfp/get-advert-by-id';
import fastdom from 'utils/fastdom-promise';
import { adSlotIdPrefix } from '../../lib/dfp/dfp-env-globals';
import fastdom from '../../utils/fastdom-promise';
import { adSizes } from '../ad-sizes';
import type { RegisterListener } from '../messenger';

Expand Down
2 changes: 1 addition & 1 deletion src/core/messenger/resize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isObject, isString } from '@guardian/libs';
import fastdom from 'utils/fastdom-promise';
import fastdom from '../../utils/fastdom-promise';
import type { RegisterListener } from '../messenger';

interface Styles {
Expand Down
2 changes: 1 addition & 1 deletion src/core/messenger/scroll.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { noop } from 'utils/noop';
import { noop } from '../../utils/noop';
import { _ as testExports } from './scroll';

const addScrollListener = testExports.addScrollListener;
Expand Down
2 changes: 1 addition & 1 deletion src/core/messenger/scroll.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Viewport } from 'lib/detect/detect-viewport';
import { getViewport } from 'lib/detect/detect-viewport';
import { addEventListener } from 'lib/events';
import fastdom from 'utils/fastdom-promise';
import fastdom from '../../utils/fastdom-promise';
import type { RegisterListener } from '../messenger';

type Respond = (...args: unknown[]) => void;
Expand Down
2 changes: 1 addition & 1 deletion src/core/messenger/type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isString } from '@guardian/libs';
import fastdom from 'utils/fastdom-promise';
import fastdom from '../../utils/fastdom-promise';
import type { RegisterListener } from '../messenger';

const setType = (adSlotType: string, adSlot: Element) =>
Expand Down
2 changes: 1 addition & 1 deletion src/core/messenger/viewport.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getViewport } from 'lib/detect/detect-viewport';
import type { Viewport } from 'lib/detect/detect-viewport';
import fastdom from 'utils/fastdom-promise';
import fastdom from '../../utils/fastdom-promise';
import type { RegisterPersistentListener, RespondProxy } from '../messenger';

type IFrameMapValue = {
Expand Down
2 changes: 1 addition & 1 deletion src/define/Advert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { breakpoints as sourceBreakpoints } from '@guardian/source/foundations';
import fastdom from 'utils/fastdom-promise';
import {
createAdSize,
findAppliedSizesForBreakpoint,
Expand All @@ -10,6 +9,7 @@ import { concatSizeMappings } from '../core/create-ad-slot';
import type { Breakpoint } from '../core/lib/breakpoint';
import { breakpointNameToAttribute } from '../lib/breakpoint-name-to-attribute';
import type { HeaderBiddingSize } from '../lib/header-bidding/prebid-types';
import fastdom from '../utils/fastdom-promise';
import { buildGoogletagSizeMapping, defineSlot } from './define-slot';

const stringToTuple = (size: string): [number, number] => {
Expand Down
2 changes: 1 addition & 1 deletion src/define/define-slot.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { toGoogleTagSize } from 'utils/googletag-ad-size';
import type { SizeMapping } from '../core/ad-sizes';
import { adSizes, createAdSize } from '../core/ad-sizes';
import { toGoogleTagSize } from '../utils/googletag-ad-size';
import {
buildGoogletagSizeMapping,
collectSizes,
Expand Down
4 changes: 2 additions & 2 deletions src/define/define-slot.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { breakpoints as sourceBreakpoints } from '@guardian/source/foundations';
import { once } from 'lodash-es';
import { EventTimer } from 'core';
import { toGoogleTagSize } from 'utils/googletag-ad-size';
import { getUrlVars } from 'utils/url';
import type { SizeMapping, SlotName } from '../core/ad-sizes';
import { toGoogleTagSize } from '../utils/googletag-ad-size';
import { getUrlVars } from '../utils/url';
import { initSlotIas } from './init-slot-ias';

const breakpointViewports: Record<keyof SizeMapping, [number, number]> = {
Expand Down
2 changes: 1 addition & 1 deletion src/define/init-slot-ias.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { once } from 'lodash-es';
import type { IasPETSlot, IasTargeting } from 'types/ias';
import { getUrlVars } from 'utils/url';
import { getUrlVars } from '../utils/url';

const adUnit = once((): string => {
const urlVars = getUrlVars();
Expand Down
4 changes: 2 additions & 2 deletions src/events/on-slot-viewable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { log } from '@guardian/libs';
import { EventTimer } from 'core';
import fastdom from 'utils/fastdom-promise';
import { getUrlVars } from 'utils/url';
import { outstreamSizes } from '../core/ad-sizes';
import { AD_LABEL_HEIGHT } from '../core/constants/ad-label-height';
import type { Advert } from '../define/Advert';
Expand All @@ -10,6 +8,8 @@ import { enableLazyLoad } from '../display/lazy-load';
import { getAdvertById } from '../lib/dfp/get-advert-by-id';
import { memoizedFetchNonRefreshableLineItemIds } from '../lib/dfp/non-refreshable-line-items';
import { shouldRefresh } from '../lib/dfp/should-refresh';
import fastdom from '../utils/fastdom-promise';
import { getUrlVars } from '../utils/url';

const ADVERT_REFRESH_RATE = 30_000; // 30 seconds. The minimum time allowed by Google.

Expand Down
2 changes: 1 addition & 1 deletion src/events/render-advert-label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
-- "Promise returned in function argument where a void return was expected"
*/
import { getCookie } from '@guardian/libs';
import fastdom from 'utils/fastdom-promise';
import crossIcon from '../../static/svg/icon/cross.svg';
import fastdom from '../utils/fastdom-promise';

const templatesWithoutLabels = [
10077207, // CAPI_MULTIPLE_HOSTED
Expand Down
4 changes: 2 additions & 2 deletions src/events/render-advert.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { $$ } from 'utils/$$';
import fastdom from 'utils/fastdom-promise';
import { adSizes } from '../core/ad-sizes';
import type { Advert } from '../define/Advert';
import { getAdIframe } from '../lib/dfp/get-ad-iframe';
import { $$ } from '../utils/$$';
import fastdom from '../utils/fastdom-promise';
import { reportError } from '../utils/report-error';
import { renderAdvertLabel } from './render-advert-label';

Expand Down
2 changes: 1 addition & 1 deletion src/init/consented/prepare-a9.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { commercialFeatures } from 'lib/commercial-features';
import { isInCanada } from 'utils/geo-utils';
import { a9 } from '../../lib/header-bidding/a9/a9';
import { isInCanada } from '../../utils/geo-utils';
import { _ } from './prepare-a9';

const { setupA9 } = _;
Expand Down
2 changes: 1 addition & 1 deletion src/init/consented/prepare-a9.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { getConsentFor, log, onConsent } from '@guardian/libs';
import { once } from 'lodash-es';
import { commercialFeatures } from 'lib/commercial-features';
import { isGoogleProxy } from 'lib/detect/detect-google-proxy';
import { isInCanada } from 'utils/geo-utils';
import { a9Apstag } from '../../core/__vendor/a9-apstag';
import { a9 } from '../../lib/header-bidding/a9/a9';
import { shouldIncludeOnlyA9 } from '../../lib/header-bidding/utils';
import { isInCanada } from '../../utils/geo-utils';

const shouldLoadA9 = () =>
// There are two articles that InfoSec would like to avoid loading scripts on
Expand Down
2 changes: 1 addition & 1 deletion src/init/consented/prepare-prebid.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type {
} from '@guardian/libs';
import { getConsentFor, log, onConsent } from '@guardian/libs';
import { commercialFeatures } from 'lib/commercial-features';
import { isInCanada } from 'utils/geo-utils';
import { prebid } from '../../lib/header-bidding/prebid/prebid';
import { isInCanada } from '../../utils/geo-utils';
import { _ } from './prepare-prebid';

const { setupPrebid } = _;
Expand Down
2 changes: 1 addition & 1 deletion src/init/consented/prepare-prebid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { getConsentFor, log, onConsent } from '@guardian/libs';
import { once } from 'lodash-es';
import { commercialFeatures } from 'lib/commercial-features';
import { isGoogleProxy } from 'lib/detect/detect-google-proxy';
import { isInCanada } from 'utils/geo-utils';
import { prebid } from '../../lib/header-bidding/prebid/prebid';
import { shouldIncludeOnlyA9 } from '../../lib/header-bidding/utils';
import { isInCanada } from '../../utils/geo-utils';

const shouldLoadPrebid = () =>
!isGoogleProxy() &&
Expand Down
2 changes: 1 addition & 1 deletion src/init/consented/static-ad-slots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { setupPrebidOnce } from 'init/consented/prepare-prebid';
import { removeDisabledSlots } from 'init/consented/remove-slots';
import { commercialFeatures } from 'lib/commercial-features';
import { getCurrentBreakpoint } from 'lib/detect/detect-breakpoint';
import { isInUk, isInUsa } from 'utils/geo-utils';
import { adSizes, createAdSize } from '../../core/ad-sizes';
import type { SizeMapping } from '../../core/ad-sizes';
import { createAdvert } from '../../define/create-advert';
import { displayAds } from '../../display/display-ads';
import { displayLazyAds } from '../../display/display-lazy-ads';
import { dfpEnv } from '../../lib/dfp/dfp-env';
import { queueAdvert } from '../../lib/dfp/queue-advert';
import { isInUk, isInUsa } from '../../utils/geo-utils';

const decideAdditionalSizes = (adSlot: HTMLElement): SizeMapping => {
const { contentType } = window.guardian.config.page;
Expand Down
2 changes: 1 addition & 1 deletion src/init/consentless/dynamic/exclusion-slot.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fastdom from 'utils/fastdom-promise';
import { createAdSlot } from '../../../core/create-ad-slot';
import fastdom from '../../../utils/fastdom-promise';
import { defineSlot } from '../define-slot';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/init/consentless/render-advert-label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- Nested fastdom measure-mutate promises throw the error:
-- "Promise returned in function argument where a void return was expected"
*/
import fastdom from 'utils/fastdom-promise';
import fastdom from '../../utils/fastdom-promise';

const shouldRenderConsentlessLabel = (adSlotNode: HTMLElement): boolean => {
if (
Expand Down
4 changes: 2 additions & 2 deletions src/insert/article-aside-adverts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { $$ } from 'utils/$$';
import fastdom from 'utils/fastdom-promise';
import { $$ } from '../utils/$$';
import fastdom from '../utils/fastdom-promise';

const minArticleHeight = 1300;

Expand Down
2 changes: 1 addition & 1 deletion src/insert/spacefinder/liveblog-adverts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import type {
} from 'insert/spacefinder/spacefinder';
import { commercialFeatures } from 'lib/commercial-features';
import { getCurrentBreakpoint } from 'lib/detect/detect-breakpoint';
import fastdom from 'utils/fastdom-promise';
import { adSizes } from '../../core/ad-sizes';
import { createAdSlot } from '../../core/create-ad-slot';
import fastdom from '../../utils/fastdom-promise';

/**
* Maximum number of inline ads to display on the page
Expand Down
4 changes: 2 additions & 2 deletions src/insert/spacefinder/spacefinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import { log } from '@guardian/libs';
import { memoize } from 'lodash-es';
import fastdom from 'utils/fastdom-promise';
import { getUrlVars } from 'utils/url';
import fastdom from '../../utils/fastdom-promise';
import { getUrlVars } from '../../utils/url';

type RuleSpacing = {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/insert/sticky-inlines.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isUndefined } from '@guardian/libs';
import { breakpoints } from '@guardian/source/foundations';
import fastdom from 'utils/fastdom-promise';
import fastdom from '../utils/fastdom-promise';

/**
* Represents an element that has some presence in the right column that we need to account for
Expand Down
2 changes: 1 addition & 1 deletion src/lib/dfp/dfp-env.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getCurrentBreakpoint as getCurrentBreakpoint_ } from 'lib/detect/detect-breakpoint';
import { getUrlVars as getUrlVars_ } from 'utils/url';
import { getUrlVars as getUrlVars_ } from '../../utils/url';
import { dfpEnv } from './dfp-env';

const getCurrentBreakpoint = getCurrentBreakpoint_ as jest.MockedFunction<
Expand Down
2 changes: 1 addition & 1 deletion src/lib/dfp/dfp-env.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getCurrentBreakpoint } from 'lib/detect/detect-breakpoint';
import { getUrlVars as _getUrlVars } from 'utils/url';
import type { Advert } from '../../define/Advert';
import { getUrlVars as _getUrlVars } from '../../utils/url';

const getUrlVars = _getUrlVars as (arg?: string) => Record<string, string>;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/header-bidding/a9/a9.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { flatten } from 'lodash-es';
import type { Advert } from 'define/Advert';
import type { A9AdUnitInterface } from 'types/global';
import { noop } from 'utils/noop';
import { noop } from '../../../utils/noop';
import type { HeaderBiddingSlot, SlotFlatMap } from '../prebid-types';
import { getHeaderBiddingAdSlots } from '../slot-config';

Expand Down
4 changes: 2 additions & 2 deletions src/lib/header-bidding/prebid/appnexus.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createAdSize } from '../../../core/ad-sizes';
import {
isInAuOrNz as isInAuOrNz_,
isInRow as isInRow_,
isInUk as isInUk_,
isInUsa as isInUsa_,
} from 'utils/geo-utils';
import { createAdSize } from '../../../core/ad-sizes';
} from '../../../utils/geo-utils';
import {
containsBillboard as containsBillboard_,
containsBillboardNotLeaderboard as containsBillboardNotLeaderboard_,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/header-bidding/prebid/appnexus.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { buildAppNexusTargetingObject } from 'lib/build-page-targeting';
import { isInAuOrNz, isInRow } from 'utils/geo-utils';
import type { PageTargeting } from '../../../core/targeting/build-page-targeting';
import { isInAuOrNz, isInRow } from '../../../utils/geo-utils';
import type { HeaderBiddingSize } from '../prebid-types';
import {
containsBillboardNotLeaderboard,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/header-bidding/prebid/bid-config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { isUserInVariant as isUserInVariant_ } from 'experiments/ab';
import config from 'lib/config';
import { createAdSize } from '../../../core/ad-sizes';
import type { PageTargeting } from '../../../core/targeting/build-page-targeting';
import {
isInAuOrNz as isInAuOrNz_,
isInRow as isInRow_,
isInUk as isInUk_,
isInUsa as isInUsa_,
isInUsOrCa as isInUsOrCa_,
} from 'utils/geo-utils';
import { createAdSize } from '../../../core/ad-sizes';
import type { PageTargeting } from '../../../core/targeting/build-page-targeting';
} from '../../../utils/geo-utils';
import type { HeaderBiddingSize, PrebidBidder } from '../prebid-types';
import {
containsBillboard as containsBillboard_,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/header-bidding/prebid/bid-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import {
} from 'lib/build-page-targeting';
import { dfpEnv } from 'lib/dfp/dfp-env';
import type { PrebidIndexSite } from 'types/global';
import type { PageTargeting } from '../../../core/targeting/build-page-targeting';
import {
isInAuOrNz,
isInRow,
isInUk,
isInUsa,
isInUsOrCa,
} from 'utils/geo-utils';
import { pbTestNameMap } from 'utils/url';
import type { PageTargeting } from '../../../core/targeting/build-page-targeting';
} from '../../../utils/geo-utils';
import { pbTestNameMap } from '../../../utils/url';
import type {
BidderCode,
HeaderBiddingSize,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/header-bidding/prebid/improve-digital.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createAdSize } from '../../../core/ad-sizes';
import {
isInAuOrNz as isInAuOrNz_,
isInRow as isInRow_,
isInUk as isInUk_,
isInUsOrCa as isInUsOrCa_,
} from 'utils/geo-utils';
import { createAdSize } from '../../../core/ad-sizes';
} from '../../../utils/geo-utils';
import { getBreakpointKey as getBreakpointKey_ } from '../utils';
import {
getImprovePlacementId,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/header-bidding/prebid/improve-digital.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isInRow, isInUk } from 'utils/geo-utils';
import { isInRow, isInUk } from '../../../utils/geo-utils';
import type { HeaderBiddingSize } from '../prebid-types';
import {
containsBillboardNotLeaderboard,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/header-bidding/prebid/magnite.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createAdSize } from '../../../core/ad-sizes';
import {
isInAuOrNz as isInAuOrNz_,
isInRow as isInRow_,
isInUk as isInUk_,
isInUsOrCa as isInUsOrCa_,
} from 'utils/geo-utils';
import { createAdSize } from '../../../core/ad-sizes';
} from '../../../utils/geo-utils';
import { getBreakpointKey as getBreakpointKey_ } from '../utils';
import { getMagniteSiteId, getMagniteZoneId } from './magnite';

Expand Down
7 changes: 6 additions & 1 deletion src/lib/header-bidding/prebid/magnite.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { isInAuOrNz, isInRow, isInUk, isInUsOrCa } from 'utils/geo-utils';
import {
isInAuOrNz,
isInRow,
isInUk,
isInUsOrCa,
} from '../../../utils/geo-utils';
import type { HeaderBiddingSize } from '../prebid-types';
import {
containsBillboard,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/header-bidding/slot-config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Advert } from 'define/Advert';
import { isInUk } from 'utils/geo-utils';
import type { AdSize } from '../../core/ad-sizes';
import { adSizes, createAdSize } from '../../core/ad-sizes';
import { isInUk } from '../../utils/geo-utils';
import type {
HeaderBiddingSizeKey,
HeaderBiddingSizeMapping,
Expand Down
Loading

0 comments on commit 53d892b

Please sign in to comment.