Skip to content

Commit

Permalink
Fix all remaining lint issues (#1249)
Browse files Browse the repository at this point in the history
As part of ongoing automation for our code practices and preferences we introduced eslint instead of the DEFRA standard linter standard.js.

Our eslint setup uses standard.js as the base linter but we have our own rules on top.

We have previously introduced a gradual adoption of eslint by using the git diff when running eslint. This appears to have some limitation with some rules not getting picked up.

At this point it makes sense to fix the remaining lint issues and remove the git diff and lint the whole codebase. When we first moved over to eslint there were 1000+ issues now we only have 137 issues (with the majority being able to be fixed with --fix).

This change fixes all outstanding linting issues and remove the previous lint with git diff lint to the basic eslint run.
  • Loading branch information
jonathangoulding authored Aug 9, 2024
1 parent e1464c4 commit 504788b
Show file tree
Hide file tree
Showing 65 changed files with 145 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app/lib/legacy-db-snake-case-mappers.lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @module LegacyDbSnakeCaseMappersLib
*/

const { camelCase, knexIdentifierMappers, snakeCase } = require('objection/lib/utils/identifierMapping')
const { camelCase, knexIdentifierMappers, snakeCase } = require('objection/lib/utils/identifierMapping.js')

/**
* Return an object containing Knex postProcessResponse() and wrapIdentifier() hooks used in Db query and result parsing
Expand Down
1 change: 1 addition & 0 deletions app/presenters/paginator.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ function _items (selectedPageNumber, numberOfPages, path) {
const paginatorType = _paginatorType(selectedPageNumber, numberOfPages)

let items

switch (paginatorType) {
case COMPLEX_START_PAGINATOR:
items = _complexPaginatorStart(selectedPageNumber, numberOfPages, path)
Expand Down
1 change: 1 addition & 0 deletions app/requests/charging-module/token.request.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function _parseResult (result) {

if (result.succeeded) {
const data = JSON.parse(result.response.body)

authentication.accessToken = data.access_token
authentication.expiresIn = data.expires_in
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ async function go (billRun, billingPeriod, billingAccounts) {
// supplementary it is extremely unlikely an annual bill run would generate no bills. But we play it safe and don't
// make that assumption.
const results = await Promise.all(processes)

if (!billRunIsPopulated) {
billRunIsPopulated = results.some((result) => {
return result
Expand Down Expand Up @@ -142,6 +143,7 @@ function _extractBillableLicences (allBillLicences) {

allBillLicences.forEach((billLicence) => {
const { id, billId, licenceId, licenceRef, billable } = billLicence

if (billable) {
billableBillLicences.push({ id, billId, licenceId, licenceRef })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function _billingPeriods (billRunType, financialYear) {
// It means we'll never pick a PRESROC for our billing periods. But also we are future proofed should we still be
// here in 2029!
const earliestSrocFinYearEnd = Math.max(SROC_FIRST_FIN_YEAR_END, (years.endYear - NO_OF_YEARS_TO_LOOK_BACK))

while (earliestSrocFinYearEnd <= years.endYear) {
_addBillingPeriod(billingPeriods, years.startYear, years.endYear)

Expand Down
1 change: 1 addition & 0 deletions app/services/bill-runs/generate-transactions.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function go (billLicenceId, chargeReference, billingPeriod, chargePeriod, newLic

if (!waterUndertaker) {
const compensationTransaction = _compensationTransaction(standardTransaction)

transactions.push(compensationTransaction)
}

Expand Down
1 change: 1 addition & 0 deletions app/services/bill-runs/submit-cancel-bill-run.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async function go (billRunId) {
const billRun = await _fetchBillRun(billRunId)

const cannotBeDeleted = _cannotBeDeleted(billRun.status)

if (cannotBeDeleted) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ function _buildBillingDataWithTransactions (chargeVersions, preGeneratedData, bi
// We fetch the previous transactions for `superseded` (REPLACED) charge versions later in the process
if (chargeVersion.status === 'current') {
const calculatedTransactions = _generateCalculatedTransactions(billLicenceId, billingPeriod, chargeVersion)

acc[billLicenceId].calculatedTransactions.push(...calculatedTransactions)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ async function go (id, filterIssues, filterLicenceHolderNumber, filterLicenceSta
return { billRun, licences }
}

function _applyFilters (reviewLicenceQuery, filterIssues, filterLicenceHolderNumber, filterLicenceStatus, filterProgress) {
function _applyFilters (
reviewLicenceQuery, filterIssues, filterLicenceHolderNumber, filterLicenceStatus, filterProgress
) {
if (filterIssues) {
_filterIssues(filterIssues, reviewLicenceQuery)
}
Expand Down Expand Up @@ -84,7 +86,9 @@ async function _fetchBillRun (id) {
})
}

async function _fetchBillRunLicences (id, filterIssues, filterLicenceHolderNumber, filterLicenceStatus, filterProgress, page = 1) {
async function _fetchBillRunLicences (
id, filterIssues, filterLicenceHolderNumber, filterLicenceStatus, filterProgress, page = 1
) {
const reviewLicenceQuery = ReviewLicenceModel.query()
.select('licenceId', 'licenceRef', 'licenceHolder', 'issues', 'progress', 'status')
.where('billRunId', id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ async function go (billRunId, licence) {

async function _persistChargeElement (chargeElement, reviewReturnIds, reviewChargeReferenceId) {
const reviewChargeElementId = await _persistReviewChargeElement(chargeElement, reviewChargeReferenceId)

for (const returnLog of chargeElement.returnLogs) {
// When we persist the review result we need the Id's for both the charge element and return log's review result
// records. Though it looks like we're iterating return logs here, these are copies assigned during matching and
Expand Down Expand Up @@ -130,6 +131,7 @@ async function _persistReturnLogs (returnLogs, reviewLicenceId) {

for (const returnLog of returnLogs) {
const reviewReturnId = await _persistReviewReturn(returnLog, reviewLicenceId)

reviewReturnIds.push({ returnId: returnLog.id, reviewReturnId })
}

Expand Down
1 change: 1 addition & 0 deletions app/services/billing-accounts/change-address.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ async function _patchExistingBillingAccountAddressEndDate (trx, billingAccountId
// `endDate` to be today - 1 (yesterday). The following works it all out even if we're over a month or year boundary
// and no moment() in sight! Thanks to https://stackoverflow.com/a/1296374 for how to do this
const endDate = new Date()

endDate.setDate(timestamp.getDate() - 1)

await BillingAccountAddressModel.query(trx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async function go (payload) {
}

const parsedLicenceRef = licenceRef.trim().toUpperCase()

await DeDuplicateService.go(parsedLicenceRef)

return {
Expand Down
1 change: 1 addition & 0 deletions app/services/health/fetch-import-jobs.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ async function go () {
*/
function _subtractDaysFromCurrentDate (days) {
const date = new Date()

date.setDate(date.getDate() - days)

return date
Expand Down
2 changes: 2 additions & 0 deletions app/services/idm/fetch-user-roles-and-groups.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ async function go (userId) {
*/
function _extractRolesAndGroupsFromUser (user) {
const { roles, groups } = user

delete user.roles
delete user.groups

Expand All @@ -71,6 +72,7 @@ function _extractRolesAndGroupsFromUser (user) {
function _extractRolesFromGroups (groups) {
return groups.flatMap((group) => {
const { roles } = group

delete group.roles

return roles
Expand Down
2 changes: 2 additions & 0 deletions app/services/jobs/export/write-table-to-file.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ async function go (headers, rows, schemaFolderPath, tableName) {
const transformDataStream = _transformDataStream()

const convertedHeaders = ConvertToCSVService.go(headers)

writeToFileStream.write(convertedHeaders)

await promisifiedPipeline(inputStream, transformDataStream, writeToFileStream)
Expand All @@ -44,6 +45,7 @@ function _transformDataStream () {
objectMode: true,
transform: function (row, _encoding, callback) {
const datRow = ConvertToCSVService.go(Object.values(row))

callback(null, datRow)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ async function go () {

function _twoMonthsAgo () {
const today = new Date()

today.setMonth(today.getMonth() - 2)

return today
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ async function go () {

function _offSetCurrentDateByDays (days) {
const date = new Date()

date.setDate(date.getDate() + days)

return date
Expand Down
2 changes: 2 additions & 0 deletions app/services/plugins/payload-cleaning.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function _cleanObject (obj) {

for (const [key, value] of Object.entries(obj)) {
let result

if (typeof value === 'object') {
if (Array.isArray(value)) {
result = _cleanArray(value)
Expand Down Expand Up @@ -202,6 +203,7 @@ function _keepValue (value) {
function _cleanValue (value) {
if (typeof value === 'string') {
let cleanedValue = Sanitizer.sanitize(value)

cleanedValue = cleanedValue.trim()
cleanedValue = Sanitizer.unescapeEntities(cleanedValue)

Expand Down
1 change: 1 addition & 0 deletions app/services/return-requirements/add.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ async function _save (session) {

return session.$update()
}

module.exports = {
go
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function _licenceEnded (licence) {
}

const today = new Date()

today.setHours(0, 0, 0, 0)

return ends.date <= today
Expand Down
1 change: 1 addition & 0 deletions app/services/return-requirements/fetch-points.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function _abstractPointsData (result) {
result.purposes.forEach((purpose) => {
purpose.purposePoints.forEach((point) => {
const pointDetail = point.point_detail

pointsData.push(pointDetail)
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ async function go (sessionId, payload, yar) {

if (!validationResult) {
const notification = _notification(session, payload)

await _save(session, payload)

if (notification) {
Expand Down
1 change: 1 addition & 0 deletions app/services/return-requirements/submit-note.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async function go (sessionId, payload, user, yar) {

if (!validationResult) {
const notification = _notification(session, payload.note)

await _save(session, payload, user)

if (notification) {
Expand Down
2 changes: 1 addition & 1 deletion db/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const environment = process.env.NODE_ENV || 'development'

const dbConfig = require('../knexfile.application')[environment]
const dbConfig = require('../knexfile.application.js')[environment]

// Where the 'pg' package has concern that parsing a DB value into its JavaScript equivalent will lead to a loss of
// data it will return the value as a string. For example, a PostgreSQL BigInt has the range -9223372036854775808 to
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict'

const { start } = require('./app/server')
const { start } = require('./app/server.js')

start()
2 changes: 1 addition & 1 deletion knexfile.application.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const { legacyDbSnakeCaseMappers } = require('./app/lib/legacy-db-snake-case-map
* to migrations.
*/

const knexfile = require('./knexfile')
const knexfile = require('./knexfile.js')

for (const environment in knexfile) {
Object.assign(knexfile[environment], legacyDbSnakeCaseMappers({ underscoreBeforeDigits: true }))
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"rollback:all": "knex migrate:rollback --all",
"rollback:all:test": "NODE_ENV=test knex migrate:rollback --all",
"seed": "knex seed:run --knexfile knexfile.application.js",
"lint": "eslint $(git diff --name-only --diff-filter=ACMRTUXB | grep -E \"\\.(js)$\")",
"lint:all": "eslint .",
"lint": "eslint .",
"pretest": "NODE_ENV=test node db/clean.js",
"test": "lab --silent-skips --shuffle",
"postinstall": "npm run build",
Expand Down
Loading

0 comments on commit 504788b

Please sign in to comment.