Skip to content

Commit cc25ab9

Browse files
Fix code style checks (#541)
1 parent cc308ec commit cc25ab9

File tree

15 files changed

+66
-103
lines changed

15 files changed

+66
-103
lines changed

.eslintrc.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@
44
module.exports = {
55
extends: ['prettier'],
66
ignorePatterns: [
7-
'**/app/**',
7+
'**/lib/**',
88
'**/public/**',
99

1010
// Enable dotfile linting
1111
'!.*',
1212
'node_modules',
13-
'node_modules/.*',
14-
15-
// Prevent CHANGELOG history changes
16-
'CHANGELOG.md'
13+
'node_modules/.*'
1714
],
1815
overrides: [
1916
{
@@ -32,13 +29,7 @@ module.exports = {
3229
parserOptions: {
3330
ecmaVersion: 'latest'
3431
},
35-
plugins: [
36-
'@typescript-eslint',
37-
'import',
38-
'jsdoc',
39-
'n',
40-
'promise'
41-
],
32+
plugins: ['@typescript-eslint', 'import', 'jsdoc', 'n', 'promise'],
4233
rules: {
4334
// Always import Node.js packages from `node:*`
4435
'import/enforce-node-protocol-usage': ['error', 'always'],

.github/workflows/code-style.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Code style checks
2+
3+
on: pull_request
4+
5+
jobs:
6+
lint:
7+
name: Code style checks
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v5
11+
- uses: actions/setup-node@v6
12+
with:
13+
node-version-file: .nvmrc
14+
# Ensure npm 11.5.1 or later is installed
15+
- name: Update npm
16+
run: npm install -g npm@latest
17+
- name: Install dependencies
18+
run: npm ci
19+
- name: Run code style checks
20+
run: npm run lint

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22

app/data/session-data-defaults.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const organisations = require('./organisations')
21
const allOrganisations = require('./all-organisations')
3-
const regions = require('./regions')
42
const featureFlags = require('./feature-flags')
3+
const organisations = require('./organisations')
4+
const regions = require('./regions')
55
const users = require('./users')
66
const vaccines = require('./vaccines')
77

app/filters.js

Lines changed: 17 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,34 @@
11
const prototypeFilters = require('@x-govuk/govuk-prototype-filters');
22

3-
/**
4-
* @param {Environment} env
5-
*/
6-
module.exports = function (env) {
7-
const filters = prototypeFilters;
8-
9-
/* ------------------------------------------------------------------
10-
add your methods to the filters obj below this comment block:
11-
@example:
12-
13-
filters.sayHi = function(name) {
14-
return 'Hi ' + name + '!'
15-
}
16-
17-
Which in your templates would be used as:
18-
19-
{{ 'Paul' | sayHi }} => 'Hi Paul'
20-
21-
Notice the first argument of your filters method is whatever
22-
gets 'piped' via '|' to the filter.
23-
24-
Filters can take additional arguments, for example:
25-
26-
filters.sayHi = function(name,tone) {
27-
return (tone == 'formal' ? 'Greetings' : 'Hi') + ' ' + name + '!'
28-
}
29-
30-
Which would be used like this:
31-
32-
{{ 'Joel' | sayHi('formal') }} => 'Greetings Joel!'
33-
{{ 'Gemma' | sayHi }} => 'Hi Gemma!'
343

35-
For more on filters and how to write them see the Nunjucks
36-
documentation.
37-
38-
------------------------------------------------------------------ */
4+
module.exports = function () {
5+
const filters = prototypeFilters;
396

407
/**
418
* Find an object by ID in an array
9+
*
4210
* @param {Array} array - Array to search
4311
* @param {string} id - ID to find
44-
* @returns {Object} Found object or undefined
45-
*/
12+
* @returns {object} Found object or undefined
13+
*/
4614
const findById = (array, id) => {
4715
if (!array || !Array.isArray(array)) return undefined
4816
return array.find(item => item.id === id)
4917
}
50-
51-
filters.findById = findById
5218

19+
filters.findById = findById
5320

5421
filters.dayName = function(isoDate) {
5522
const date = new Date(Date.parse(isoDate))
5623
const dateFormatter = new Intl.DateTimeFormat('en-GB', {weekday: 'short'});
57-
24+
5825
return dateFormatter.format(date)
5926
}
60-
27+
6128
filters.pluck = function(array, attribute) {
6229
return array.map((item) => item[attribute])
6330
}
64-
31+
6532
filters.capitaliseFirstLetter = function(string) {
6633
if (string) {
6734
return string.charAt(0) .toUpperCase() + string.slice(1)
@@ -78,23 +45,23 @@ module.exports = function (env) {
7845
* January, rather than 0 (which is the default for
7946
* JavaScript date objects).
8047
*
81-
* @param {Integer, string} monthNumber - number of the month
82-
* @returns {String} Full name of the month in English
83-
*/
48+
* @param {number|string} monthNumber - number of the month
49+
* @returns {string} Full name of the month in English
50+
*/
8451
filters.monthName = function(monthNumber) {
85-
52+
8653
try {
8754
monthNumber = parseInt(monthNumber)
88-
55+
8956
if (!monthNumber || (monthNumber < 1) || (monthNumber > 12)) {
9057
throw new Error('Invalid monthNumber - must be between 1 and 12')
9158
}
92-
59+
9360
const date = new Date(Date.UTC(2000, (monthNumber - 1), 1, 0, 0, 0));
9461
const dateFormatter = new Intl.DateTimeFormat('en-GB', {month: 'long'});
95-
62+
9663
return dateFormatter.format(date)
97-
64+
9865
} catch (error) {
9966
return error.message.split(':')[0]
10067
}

app/routes/helpers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = router => {
1616
const vaccines = data.vaccines
1717
const siteId = "RW3NM"
1818

19-
for (vaccine of vaccines) {
19+
for (let vaccine of vaccines) {
2020

2121
const organisationVaccine = organisationVaccines.find((organisationVaccine) => organisationVaccine.name === vaccine.name)
2222

@@ -29,7 +29,7 @@ module.exports = router => {
2929
})
3030
}
3131

32-
for (vaccineProduct of vaccine.products) {
32+
for (let vaccineProduct of vaccine.products) {
3333

3434
const numberOfBatchesToAdd = 1 + Math.floor(Math.random() * 10)
3535

app/routes/home.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ module.exports = router => {
9999
})
100100
}
101101

102-
for (vaccine of uniqueVaccinesRecorded) {
102+
for (let vaccine of uniqueVaccinesRecorded) {
103103
totalsByVaccine.push({
104104
vaccine: vaccine,
105105
today: countVaccinations(vaccinationsRecorded, {
@@ -123,7 +123,7 @@ module.exports = router => {
123123

124124
const siteIds = [...new Set(vaccinationsRecorded.map((vaccination) => vaccination.siteId))]
125125

126-
for (siteId of siteIds) {
126+
for (let siteId of siteIds) {
127127
totalsBySite.push({
128128
siteId: siteId,
129129
today: countVaccinations(vaccinationsRecorded, {

app/routes/lists.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const { randomItem } = require('../lib/utils/random-item.js')
21
const { dateFromYearMonthDay } = require('../lib/utils/date-from-year-month-day.js')
2+
const { randomItem } = require('../lib/utils/random-item.js')
33

44

55
module.exports = router => {
@@ -227,7 +227,7 @@ module.exports = router => {
227227

228228
const nhsNumbers = data.nhsNumbers.split(/\n/)
229229

230-
for (nhsNumber of nhsNumbers) {
230+
for (let nhsNumber of nhsNumbers) {
231231
patientList.patients.push({
232232
nhsNumber: nhsNumber,
233233
firstName: randomItem(listOfFirstNames),

app/routes/record-vaccinations.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ module.exports = router => {
151151
let vaccinesAvailable = JSON.parse(JSON.stringify(data.vaccines)).filter((vaccine) => vaccinesAdded.includes(vaccine.name))
152152

153153
// Filter all vaccine products to only show ones with batches added
154-
for (vaccineAvailable of vaccinesAvailable) {
154+
for (let vaccineAvailable of vaccinesAvailable) {
155155
vaccineAvailable.products = vaccineAvailable.products.filter((vaccineProduct) => vaccineProductsAdded.includes(vaccineProduct.name))
156156
}
157157

@@ -206,7 +206,6 @@ module.exports = router => {
206206
router.get('/record-vaccinations/patient', (req, res) => {
207207

208208
const data = req.session.data
209-
const showError = data.showError
210209
const nhsNumberKnown = data.nhsNumberKnown
211210
const nhsNumber = String(data.nhsNumber).replaceAll(' ', '')
212211

@@ -392,11 +391,11 @@ module.exports = router => {
392391

393392
router.post('/record-vaccinations/create-a-record', (req, res) => {
394393
const data = req.session.data
395-
const firstName = req.session.data.firstName;
396-
const lastName = req.session.data.lastName;
397-
const dateOfBirth = req.session.data.dateOfBirth;
398-
const postcode = req.session.data.postcode;
399-
const gender = req.session.data.gender;
394+
const firstName = data.firstName;
395+
const lastName = data.lastName;
396+
const dateOfBirth = data.dateOfBirth;
397+
const postcode = data.postcode;
398+
const gender = data.gender;
400399

401400
if (firstName != '' && lastName != '' && dateOfBirth.day != '' && dateOfBirth.month != '' && dateOfBirth.year != '' && postcode != '' && gender != '') {
402401

@@ -774,7 +773,6 @@ module.exports = router => {
774773
router.get('/record-vaccinations/batch', (req, res) => {
775774
let error
776775
const data = req.session.data
777-
const currentOrganisation = res.locals.currentOrganisation
778776

779777
const vaccine = data.vaccineStock.find(function(batch) {
780778
return (batch.vaccineProduct === data.vaccineProduct) &&
@@ -846,7 +844,6 @@ module.exports = router => {
846844

847845
const data = req.session.data
848846
const vaccineBatch = data.vaccineBatch
849-
const vaccine = data.vaccine
850847

851848
const vaccineOptions = data.vaccineStock.find(function(batch) {
852849
return (batch.vaccineProduct === data.vaccineProduct) &&
@@ -1159,8 +1156,6 @@ module.exports = router => {
11591156
router.post('/record-vaccinations/answer-dose-amount', (req, res) => {
11601157
const data = req.session.data
11611158
const doseAmount = data.doseAmount
1162-
let redirectPath
1163-
11641159

11651160
if (doseAmount && doseAmount != "") {
11661161
res.redirect("/record-vaccinations/check")

app/routes/records.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ module.exports = router => {
154154
const firstName = data.firstName;
155155
const lastName = data.lastName;
156156
const dateOfBirth = data.dateOfBirth;
157-
const postcode = data.postcode;
158157

159158
if (firstName && lastName && dateOfBirth) {
160159

0 commit comments

Comments
 (0)