Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/65543 upgrade eslint to v9 #2975

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1f38cad
add all attempts as text files, with my scratch build as the active one
GuyHarwood Nov 13, 2024
bbb36d1
basic eslint config. 5k~ issues
GuyHarwood Nov 14, 2024
4250014
remove output file
GuyHarwood Nov 14, 2024
04ef8cb
separate rulesets and concerns
GuyHarwood Nov 14, 2024
91cea24
remove header imports for jest
GuyHarwood Nov 14, 2024
732e65d
update globals and exclude minified sources
GuyHarwood Nov 14, 2024
e4cfca3
remove standard. progress with eslint 9 fixes
GuyHarwood Nov 15, 2024
715cad8
fix more errors
GuyHarwood Nov 15, 2024
8c1749b
Merge branch 'master' into feature/65543-upgrade-eslint-v9
GuyHarwood Nov 15, 2024
b1bdbab
add notes
GuyHarwood Nov 15, 2024
28d0ef5
final lint errors fixed
GuyHarwood Nov 18, 2024
9355bec
add stylistic. fix issues
GuyHarwood Nov 18, 2024
16b1d0e
finish off stylistic fixes on codebase
GuyHarwood Nov 18, 2024
8561406
Merge branch 'master' into feature/65543-upgrade-eslint-v9
GuyHarwood Nov 19, 2024
da26a0e
narrow global usage
GuyHarwood Nov 19, 2024
eac8e5c
narrow scope on globals. tighten up browser js rules
GuyHarwood Nov 19, 2024
b2c732e
remove superfluous rules
GuyHarwood Nov 19, 2024
7759a26
introduce jest plugin. build out existing ts rules from old config file
GuyHarwood Nov 20, 2024
5bef97e
code updates based on eslint/ts rules
GuyHarwood Nov 21, 2024
9bfaf9b
fix merge conflicts
GuyHarwood Nov 29, 2024
e8fb7dc
target proper integration test call
GuyHarwood Dec 3, 2024
766f50d
remove all tsignore where no longer relevant
GuyHarwood Dec 3, 2024
a4448fd
remove test block that has been disabled for 3+ years
GuyHarwood Dec 3, 2024
237794d
tslib: upgradeESLint to v9 and convert existing config, with fixes
GuyHarwood Dec 5, 2024
3630517
narrow restrictions on lint rules
GuyHarwood Dec 10, 2024
4c57572
revert to strict
GuyHarwood Dec 11, 2024
54db685
update build-agent to 3.248.0
GuyHarwood Dec 12, 2024
594e337
fix merge conflicts and lint issues in admin (TS targeting browser js)
GuyHarwood Dec 23, 2024
c1cf7fa
Merge branch 'master' into feature/65543-upgrade-eslint-v9
GuyHarwood Dec 31, 2024
7dab516
Pr comment fixes
GuyHarwood Jan 8, 2025
4364d7b
Merge branch 'feature/65543-upgrade-eslint-v9' of github.com:DFEAGILE…
GuyHarwood Jan 9, 2025
735c9c2
disable import rule for app insights
GuyHarwood Jan 9, 2025
0b30c45
remove redis param docs
GuyHarwood Jan 9, 2025
bc38ec4
put back unused next var as removal causes rendering failure of error…
GuyHarwood Jan 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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'
]
}
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
4 changes: 1 addition & 3 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,7 +385,7 @@ app.use(function (req, res, next) {
})

// error handler
app.use(function (err, req, res, next) {
app.use(function (err, req, res) {
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 })
})
15 changes: 7 additions & 8 deletions admin/assets/javascripts/jquery-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
* Based on guidelines found here:
* https://paper.dropbox.com/doc/Modal-dialog-boxes-jbsTPoITg37IIc6ybjetM
*/
/* global $ */
/* eslint-disable no-var */

$(function () {
var modalForm = document.querySelector('#js-modal-form')
var hasModalForm = modalForm && modalForm.length > 0
function startModal (e) {
const modalForm = document.querySelector('#js-modal-form')
const hasModalForm = modalForm && modalForm.length > 0
function startModal () {
$('.modal-link').on('click', function (e) {
if (hasModalForm) {
toggleShowHideModal(e)
Expand All @@ -27,7 +26,7 @@ $(function () {
$('#js-modal-confirmation-button').attr('href', '')
}
})
$('#js-modal-confirmation-button').on('click', function (e) {
$('#js-modal-confirmation-button').on('click', function () {
if (hasModalForm) {
modalForm.submit()
}
Expand All @@ -36,7 +35,7 @@ $(function () {
toggleShowHideModal(e)
})
$('#modal-wrapper').on('keydown', function (e) {
var modalBox = $('#js-modal-box')
const modalBox = $('#js-modal-box')
// escape keystroke should hide the modal when it is visible
if (e.keyCode === 27 && modalBox.hasClass('show')) {
toggleShowHideModal(e)
Expand Down Expand Up @@ -71,7 +70,7 @@ $(function () {
e.preventDefault()
}
$('#js-modal-overlay').toggleClass('show')
var modalBox = $('#js-modal-box')
const modalBox = $('#js-modal-box')
if (modalBox.hasClass('show')) {
modalBox.removeClass('show')
$('#js-modal-link').focus()
Expand Down
1 change: 0 additions & 1 deletion admin/assets/javascripts/layout.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
document.addEventListener('DOMContentLoaded', function () {
window.GOVUKFrontend.initAll()
const cookieElement = document.querySelectorAll('div[data-module=cookie-banner]')
// eslint-disable-next-line no-undef
const module = new GOVUK.Modules.CookieBanner()
module.start(cookieElement)
})
5 changes: 2 additions & 3 deletions admin/assets/javascripts/mtc-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
/**
* Autocomplete component
*/
/* eslint-disable no-var */

if (!window.MTCAdmin) {
window.MTCAdmin = {}
}

/* global $ */
(function () {
window.MTCAdmin.autoComplete = {
/**
Expand Down Expand Up @@ -95,7 +94,7 @@ if (!window.MTCAdmin) {
setupLinkedConfirm: function (autoCompleteContainer, linkedContainer, findValueFunc) {
return function (event, value) {
if (typeof value === 'undefined') return
var ul = $(linkedContainer).find('ul')
const ul = $(linkedContainer).find('ul')
/*
* The autocomplete library triggers the dropdown when setting the value on the linkedContainer
* we need to hide the menu using the style attribute, wait for the dropdown to appear,
Expand Down
Loading
Loading