Skip to content

Commit

Permalink
Remove init() method from initAll function and component example
Browse files Browse the repository at this point in the history
Because we're not storing the object we create using `new`, we're getting a `no-new` failure from eslint.
  • Loading branch information
colinrotherham committed Jul 27, 2023
1 parent bcdbb5f commit 408e5e3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/javascripts/application-example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ initAll({
notificationBanner: { disableAutoFocus: true }
})

new ExamplePage(document).init()
// eslint-disable-next-line no-new
new ExamplePage(document)
20 changes: 11 additions & 9 deletions src/javascripts/application.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-new */

import { initAll } from 'govuk-frontend'

import Analytics from './components/analytics.mjs'
Expand All @@ -18,7 +20,7 @@ initAll()
// Initialise cookie banner
const $cookieBanner = document.querySelector('[data-module="govuk-cookie-banner"]')
if ($cookieBanner) {
new CookieBanner($cookieBanner).init()
new CookieBanner($cookieBanner)
}

// Initialise analytics if consent is given
Expand All @@ -30,41 +32,41 @@ if (userConsent && isValidConsentCookie(userConsent) && userConsent.analytics) {
// Initialise example frames
const $examples = document.querySelectorAll('[data-module="app-example-frame"]')
$examples.forEach(($example) => {
new Example($example).init()
new Example($example)
})

// Initialise tabs
const $tabs = document.querySelectorAll('[data-module="app-tabs"]')
$tabs.forEach(($tabs) => {
new AppTabs($tabs).init()
new AppTabs($tabs)
})

// Do this after initialising tabs
new OptionsTable().init()
new OptionsTable()

// Add copy to clipboard to code blocks inside tab containers
const $codeBlocks = document.querySelectorAll('[data-module="app-copy"] pre')
$codeBlocks.forEach(($codeBlock) => {
new Copy($codeBlock).init()
new Copy($codeBlock)
})

// Initialise mobile navigation
new Navigation(document).init()
new Navigation(document)

// Initialise search
const $searchContainer = document.querySelector('[data-module="app-search"]')
if ($searchContainer) {
new Search($searchContainer).init()
new Search($searchContainer)
}

// Initialise back to top
const $backToTop = document.querySelector('[data-module="app-back-to-top"]')
if ($backToTop) {
new BackToTop($backToTop).init()
new BackToTop($backToTop)
}

// Initialise cookie page
const $cookiesPage = document.querySelector('[data-module="app-cookies-page"]')
if ($cookiesPage) {
new CookiesPage($cookiesPage).init()
new CookiesPage($cookiesPage)
}

0 comments on commit 408e5e3

Please sign in to comment.