Skip to content

Commit

Permalink
Feature/65543 upgrade eslint to v9 (#2975)
Browse files Browse the repository at this point in the history
* add all attempts as text files, with my scratch build as the active one

* basic eslint config. 5k~ issues

* remove output file

* separate rulesets and concerns

* remove header imports for jest

* update globals and exclude minified sources

* remove standard. progress with eslint 9 fixes

* fix more errors

* add notes

* final lint errors fixed

* add stylistic. fix issues

* finish off stylistic fixes on codebase

* narrow global usage

* narrow scope on globals.  tighten up browser js rules

* remove superfluous rules

* introduce jest plugin.  build out existing ts rules from old config file

* code updates based on eslint/ts rules

* target proper integration test call

* remove all tsignore where no longer relevant

* remove test block that has been disabled for 3+ years

* tslib: upgradeESLint to v9 and convert existing config, with fixes

* narrow restrictions on lint rules

* revert to strict

* update build-agent to 3.248.0

* Pr comment fixes

* disable import rule for app insights

* remove redis param docs

* put back unused next var as removal causes rendering failure of error page

* update chrome and selenium version

---------

Co-authored-by: Mohsen Qureshi <[email protected]>
  • Loading branch information
GuyHarwood and activemq authored Jan 22, 2025
1 parent dd87e82 commit ead6f1d
Show file tree
Hide file tree
Showing 316 changed files with 3,185 additions and 4,014 deletions.
2 changes: 1 addition & 1 deletion admin/.babelrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
// See https://babeljs.io/docs/en/babel-preset-env#targets
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript'
]
}
74 changes: 0 additions & 74 deletions admin/.eslintrc.js

This file was deleted.

1 change: 1 addition & 0 deletions admin/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ dependency-graphs

# typescript output directory
dist
tsconfig.tsbuildinfo
3 changes: 1 addition & 2 deletions admin/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,8 @@ if (config.Auth.mode === authModes.dfeSignIn) {

app.use(function (req, res, next) {
// make the user and isAuthenticated vars available in the view templates
// @ts-ignore
if (req.isAuthenticated()) {
res.locals.isAuthenticated = true
// @ts-ignore
res.locals.user = req.user
} else {
res.locals.isAuthenticated = false
Expand Down Expand Up @@ -387,6 +385,7 @@ app.use(function (req, res, next) {
})

// error handler
// eslint-disable-next-line @typescript-eslint/no-unused-vars
app.use(function (err, req, res, next) {
const errorId = uuidv4()
res.locals.errorId = errorId
Expand Down
1 change: 0 additions & 1 deletion admin/assets/javascripts/cookie-form.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
document.addEventListener('DOMContentLoaded', function () {
const cookieSettingsElement = document.querySelectorAll('form[data-module=cookie-settings]')
if (cookieSettingsElement && cookieSettingsElement.length > 0) {
// eslint-disable-next-line no-undef
const cookieSettingsModule = new GOVUK.Modules.CookieSettings()
cookieSettingsModule.start(cookieSettingsElement)
}
Expand Down
19 changes: 9 additions & 10 deletions admin/assets/javascripts/custom-file-upload.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
/**
* File upload customisation.
*/
/* global $ */
/* eslint-disable no-var */

$(function () {
'use strict'

function customFileUpload (e) {
var $formElement = $('#upload-form')
var $removeElement = $('#removeUploadedFile')
var isSubmitted = false
function customFileUpload () {
const $formElement = $('#upload-form')
const $removeElement = $('#removeUploadedFile')
let isSubmitted = false

$removeElement.on('click', function (e) {
$removeElement.on('click', function () {
$removeElement.css('visibility', 'hidden')
$removeElement.hide()
})

$('input:file').change(function (e) {
var hasFileForUpload = !!e.target.value
const hasFileForUpload = !!e.target.value
if (!hasFileForUpload) {
return $removeElement.click()
}
$removeElement.css('visibility', 'visible')
$removeElement.show()
var $fileName = $(this).val()
const $fileName = $(this).val()
$('.filename').html($fileName)
})

Expand All @@ -32,7 +31,7 @@ $(function () {
return false
}
// Update the form submit button to say it's uploading
var submitButton = $('#upload-form-submit')
const submitButton = $('#upload-form-submit')
if (submitButton.text) {
$('#upload-form-submit').text('Sending...')
} else if (submitButton.val) {
Expand Down
6 changes: 2 additions & 4 deletions admin/assets/javascripts/gds-print-popup.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
'use strict'
/* eslint-disable no-var */

/**
* Print popup.
*/
if (!window.MTCAdmin) {
window.MTCAdmin = {}
}

/* global $ window */

(function () {
window.MTCAdmin.printPopup = {
hideUncheckedPupils: function (printContainer) {
$(printContainer + ' tr').each(function () {
$(this).addClass('hidden')
})
$('.multiple-choice-mtc > input:checkbox').each(function () {
var pupilId = $(this).val()
const pupilId = $(this).val()
if ($(this).is(':checked')) {
$(printContainer + ' tr.pupil-' + pupilId).removeClass('hidden')
}
Expand Down
27 changes: 13 additions & 14 deletions admin/assets/javascripts/gds-table-sorting.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/**
* Table sorting.
*/
/* eslint-disable no-var */

if (!window.MTCAdmin) {
window.MTCAdmin = {}
Expand All @@ -24,16 +23,16 @@ if (!window.MTCAdmin) {
comparer: function (idx, asc, config) {
return function (a, b) {
return (function (v1, v2) {
return window.MTCAdmin.tableSort.isNumericValue(v1) && window.MTCAdmin.tableSort.isNumericValue(v2)
? window.MTCAdmin.tableSort.getNumberComparisonResult(v1, v2, asc)
: window.MTCAdmin.tableSort.getStringComparisonResult(v1, v2, asc, config)
return window.MTCAdmin.tableSort.isNumericValue(v1) && window.MTCAdmin.tableSort.isNumericValue(v2) ?
window.MTCAdmin.tableSort.getNumberComparisonResult(v1, v2, asc) :
window.MTCAdmin.tableSort.getStringComparisonResult(v1, v2, asc, config)
})(window.MTCAdmin.tableSort.getCellValue(a, idx), window.MTCAdmin.tableSort.getCellValue(b, idx))
}
},

isNumericValue: function (v) {
var numericOnlyPattern = /^\d+$/
var numericOnlyRegExp = new RegExp(numericOnlyPattern)
const numericOnlyPattern = /^\d+$/
const numericOnlyRegExp = new RegExp(numericOnlyPattern)
return ((typeof v === 'string' && numericOnlyRegExp.test(v)) || typeof v === 'number')
},

Expand Down Expand Up @@ -69,8 +68,8 @@ if (!window.MTCAdmin) {

applySortClass: function (headerEl) {
// Remove sort classes from headers
var nodeList = document.querySelectorAll('thead tr th span')
for (var i = 0; i < nodeList.length; i++) {
const nodeList = document.querySelectorAll('thead tr th span')
for (let i = 0; i < nodeList.length; i++) {
nodeList[i].className = 'sort-icon'
}

Expand Down Expand Up @@ -99,10 +98,10 @@ if (!window.MTCAdmin) {
*/
applySorting: function (document, tableId, config) {
// Listen for click events and perform sorting
var thNodeList = document.querySelectorAll('th')
const thNodeList = document.querySelectorAll('th')

for (var i = 0; i < thNodeList.length; i++) {
var th = thNodeList[i]
for (let i = 0; i < thNodeList.length; i++) {
const th = thNodeList[i]
window.MTCAdmin.tableSort.setUpClickHandler(th, i, tableId, config)
}
},
Expand All @@ -111,9 +110,9 @@ if (!window.MTCAdmin) {
// TODO: don't sort the whole table when clicking the `tickAllCheckboxes` checkbox
th.addEventListener('click', function () {
window.MTCAdmin.tableSort.applySortClass(this)
var tbody = document.querySelector('#' + tableId + ' tbody')
var trNodeList = tbody.querySelectorAll('tr')
var trList = [].slice.call(trNodeList)
const tbody = document.querySelector('#' + tableId + ' tbody')
const trNodeList = tbody.querySelectorAll('tr')
const trList = [].slice.call(trNodeList)

trList.sort(window.MTCAdmin.tableSort.comparer(
i,
Expand Down
32 changes: 16 additions & 16 deletions admin/assets/javascripts/global-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
* pupilGroups, assignForm, restarts, generatePins, pupilsNotTakingCheck
* are global, to be accessed by scripts in other files that use them.
*/
/* global $, inputStatus, stickyBanner */
/* eslint-disable no-var */
/* global inputStatus, stickyBanner */

/**
* Methods for 'pupils not taking the check'.
* @type {{isRadioChecked: isRadioChecked, isCheckboxChecked: isCheckboxChecked, validateForm: validateForm}}
*/
var pupilsNotTakingCheck = {
const pupilsNotTakingCheck = {
/**
* Is radio button checked?
* @returns {boolean}
*/
isRadioChecked: function () {
var el = $('input:radio[name="attendanceCode"]:checked')
const el = $('input:radio[name="attendanceCode"]:checked')
return el.length > 0
},
/**
* Is there at least one checkbox checked?
* @returns {boolean}
*/
isCheckboxChecked: function () {
var elCheckboxes = $('.multiple-choice-mtc > input:checkbox:checked').not('#tickAllCheckboxes')
var elTickAll = $('.multiple-choice-mtc > input#tickAllCheckboxes:checkbox:checked')
const elCheckboxes = $('.multiple-choice-mtc > input:checkbox:checked').not('#tickAllCheckboxes')
const elTickAll = $('.multiple-choice-mtc > input#tickAllCheckboxes:checkbox:checked')
return elTickAll.length > 0 || elCheckboxes.length > 0
},
/**
Expand All @@ -41,9 +41,9 @@ var pupilsNotTakingCheck = {
* Methods for 'Generate PINs'.
* @type {{isCheckboxChecked: isCheckboxChecked}}
*/
var generatePins = {
const generatePins = {
isCheckboxChecked: function () {
var el = $('.multiple-choice-mtc > input:checkbox:checked').not('#tickAllCheckboxes')
const el = $('.multiple-choice-mtc > input:checkbox:checked').not('#tickAllCheckboxes')
return el.length > 0
}
}
Expand All @@ -52,21 +52,21 @@ var generatePins = {
* Methods for 'Restarts'.
* @type {{isRadioChecked: isRadioChecked, isCheckboxChecked: isCheckboxChecked, validateForm: validateForm}}
*/
var restarts = {
const restarts = {
/**
* Is radio button checked?
* @returns {boolean}
*/
isRadioChecked: function () {
var el = $('input:radio[name="restartReason"]:checked')
const el = $('input:radio[name="restartReason"]:checked')
return el.length > 0
},
/**
* Is there at least one checkbox checked?
* @returns {boolean}
*/
isCheckboxChecked: function () {
var el = $('.multiple-choice-mtc > input:checkbox:checked')
const el = $('.multiple-choice-mtc > input:checkbox:checked')
return el.length > 0
},
validateForm: function () {
Expand All @@ -78,13 +78,13 @@ var restarts = {
* Methods for 'assign check form to check windows'.
* @type {{isCheckboxChecked: isCheckboxChecked}}
*/
var assignForm = {
const assignForm = {
/**
* Is there at least one checkbox checked?
* @returns {boolean}
*/
isCheckboxChecked: function () {
var el = $('.multiple-choice-mtc > input:checkbox:checked')
const el = $('.multiple-choice-mtc > input:checkbox:checked')
return el.length > 0
},
/**
Expand All @@ -100,21 +100,21 @@ var assignForm = {
* Methods for 'pupils groups'.
* @type {{isCheckboxChecked: isCheckboxChecked, isGroupNameComplete: *}}
*/
var pupilGroups = {
const pupilGroups = {
/**
* Is there at least one checkbox checked?
* @returns {boolean}
*/
isCheckboxChecked: function () {
var elCheckboxes = $('.multiple-choice-mtc > input:checkbox:checked')
const elCheckboxes = $('.multiple-choice-mtc > input:checkbox:checked')
return elCheckboxes.length > 0
},
/**
* Check if name field is not empty.
* @returns {boolean}
*/
isGroupNameComplete: function () {
var elName = $.trim($('input#name').val())
const elName = $.trim($('input#name').val())
return elName.length > 0
},
/**
Expand Down
8 changes: 2 additions & 6 deletions admin/assets/javascripts/google-analytics.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
/* global googleTrackingId dataLayer args */
document.addEventListener('DOMContentLoaded', function () {
// Disable tracking if the opt-out cookie exists.
// To disable analytics: window['ga-disable-UA-XXXXX-Y'] = true;
// More info on https://developers.google.com/analytics/devguides/collection/analyticsjs/user-opt-out
// eslint-disable-next-line no-undef
const disableStr = 'ga-disable-' + googleTrackingId
const consentCookie = window.GOVUK.getConsentCookie()
window[disableStr] = consentCookie && !consentCookie.usage

window.dataLayer = window.dataLayer || []
// eslint-disable-next-line no-undef
function gtag () { dataLayer.push(arguments) }

function gtag () { dataLayer.push(...args) }
gtag('js', new Date())
// eslint-disable-next-line no-undef
gtag('config', googleTrackingId, { anonymize_ip: true })
})
Loading

0 comments on commit ead6f1d

Please sign in to comment.