Skip to content

Commit

Permalink
PI-2713 Switch to HMPPS eslint config (#236)
Browse files Browse the repository at this point in the history
* Bump eslint from 8.57.0 to 9.17.0

Bumps [eslint](https://github.com/eslint/eslint) from 8.57.0 to 9.17.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](eslint/eslint@v8.57.0...v9.17.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* PI-2713 Switch to HMPPS eslint config

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Marcus Aspin <[email protected]>
  • Loading branch information
dependabot[bot] and marcus-bcl authored Dec 31, 2024
1 parent bcb1a16 commit d1ee5c9
Show file tree
Hide file tree
Showing 23 changed files with 506 additions and 131 deletions.
8 changes: 0 additions & 8 deletions .eslintignore

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion .zap/traverse.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function listChildren(node, level) {
var j
let j
for (j = 0; j < node.getChildCount(); j++) {
print(Array(level + 1).join(' ') + node.getChildAt(j).getNodeName())
listChildren(node.getChildAt(j), level + 1)
Expand Down
2 changes: 2 additions & 0 deletions assets/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ const lastAppointment = () => {
const resetConditionals = () => {
const handleReset = () => {
document.querySelectorAll('.govuk-radios__conditional input').forEach(radioBtn => {
// eslint-disable-next-line no-param-reassign
radioBtn.checked = false
})
}
const elm = document.querySelector('[data-reset-conditional-radios]')
if (elm) {
// eslint-disable-next-line no-shadow
document.querySelectorAll('[data-reset-conditional-radios]').forEach(elm => {
elm.addEventListener('click', handleReset)
})
Expand Down
47 changes: 24 additions & 23 deletions assets/js/backendSortableTable.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable func-names,no-plusplus */
MOJFrontend.BackendSortableTable = function (params) {
this.table = $(params.table)

Expand All @@ -16,11 +17,11 @@ MOJFrontend.BackendSortableTable = function (params) {
}

MOJFrontend.BackendSortableTable.prototype.check = function () {
//Empty function
// Empty function
}

MOJFrontend.BackendSortableTable.prototype.setupOptions = function (params) {
params = params || {}
MOJFrontend.BackendSortableTable.prototype.setupOptions = function (nullableParams) {
const params = nullableParams || {}
this.statusMessage = params.statusMessage || 'Sort by %heading% (%direction%)'
this.ascendingText = params.ascendingText || 'ascending'
this.descendingText = params.descendingText || 'descending'
Expand All @@ -30,7 +31,7 @@ MOJFrontend.BackendSortableTable.prototype.createHeadingButtons = function () {
const headings = this.table.find('thead th')
let heading
let i = 0
for (let head of headings) {
for (const head of headings) {
heading = $(head)
if (heading.attr('aria-sort')) {
this.createHeadingButton(heading, i)
Expand All @@ -44,19 +45,21 @@ MOJFrontend.BackendSortableTable.prototype.setNaturalOrder = function () {
let heading
this.naturalSortColumn = 0
this.naturalSortDirection = 'ascending'
for (let head of headings) {
let i = 0
for (const head of headings) {
heading = $(head)
if (heading.attr('aria-sort-natural')) {
this.naturalSortColumn = i
this.naturalSortDirection = heading.attr('aria-sort-natural')
break
}
i++
}
}

MOJFrontend.BackendSortableTable.prototype.createHeadingButton = function (heading, i) {
const text = heading.text()
const button = $('<button type="button" data-index="' + i + '">' + text + '</button>')
const button = $(`<button type="button" data-index="${i}">${text}</button>`)
heading.text('')
heading.append(button)
}
Expand All @@ -77,7 +80,7 @@ MOJFrontend.BackendSortableTable.prototype.onSortButtonClick = function (e) {
}

const columnName = $(e.currentTarget).parent().attr('col-name')
const sortBy = columnName + '.' + backendSortDirection
const sortBy = `${columnName}.${backendSortDirection}`

window.location = `/${action}?sortBy=${sortBy}`
}
Expand All @@ -97,15 +100,14 @@ MOJFrontend.BackendSortableTable.prototype.sort = function (rows, columnNumber,
return 1
}
return this.sortNatural(rowA, rowB)
} else {
if (valueB < valueA) {
return -1
}
if (valueB > valueA) {
return 1
}
return this.sortNatural(rowA, rowB)
}
if (valueB < valueA) {
return -1
}
if (valueB > valueA) {
return 1
}
return this.sortNatural(rowA, rowB)
}, this),
)
}
Expand All @@ -123,15 +125,14 @@ MOJFrontend.BackendSortableTable.prototype.sortNatural = function (rowA, rowB) {
return 1
}
return 0
} else {
if (valueB < valueA) {
return -1
}
if (valueB > valueA) {
return 1
}
return 0
}
if (valueB < valueA) {
return -1
}
if (valueB > valueA) {
return 1
}
return 0
}

MOJFrontend.BackendSortableTable.prototype.getCellValue = function (cell) {
Expand Down
3 changes: 2 additions & 1 deletion assets/js/govukFrontendInit.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { initAll } from '/assets/govuk/govuk-frontend.min.js'
// eslint-disable-next-line import/no-unresolved,import/extensions
import { initAll } from './govuk/govuk-frontend.min.js'

initAll()
2 changes: 1 addition & 1 deletion assets/js/mojFrontendInit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
window.MOJFrontend.initAll()
const $backendSortableTables = document.querySelectorAll('[data-module="moj-backend-sortable-table"]')
MOJFrontend.nodeListForEach($backendSortableTables, function ($table) {
MOJFrontend.nodeListForEach($backendSortableTables, function f($table) {
const best = new MOJFrontend.BackendSortableTable({
table: $table,
})
Expand Down
1 change: 0 additions & 1 deletion assets/js/predictors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable */
const openText = 'Open'
const closeText = 'Close'

Expand Down
29 changes: 29 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import hmppsConfig from '@ministryofjustice/eslint-config-hmpps'
import typescriptEslint from '@typescript-eslint/eslint-plugin'
import tsParser from '@typescript-eslint/parser'

export default [
...hmppsConfig({
extraIgnorePaths: ['playwright-report/**', '.zap/**'],
extraPathsAllowingDevDependencies: ['e2e_tests/**', 'playwright.config.ts'],
extraFrontendGlobals: { $: 'readonly', MOJFrontend: 'readonly' },
}),

{
name: 'overrides',
files: ['**/*.ts'],
ignores: ['**/*.js'],
plugins: {
'@typescript-eslint': typescriptEslint,
},
languageOptions: {
parser: tsParser,
},
rules: {
// TODO remove these overrides and fix the issues:
'@typescript-eslint/no-unused-vars': 0,
'@typescript-eslint/no-explicit-any': 0,
'import/prefer-default-export': 0,
},
},
]
Loading

0 comments on commit d1ee5c9

Please sign in to comment.