Skip to content

Commit

Permalink
Update to ESlint 9 and flat config
Browse files Browse the repository at this point in the history
  • Loading branch information
rakyi committed Dec 26, 2024
1 parent 05dee10 commit cccf8c7
Show file tree
Hide file tree
Showing 112 changed files with 1,440 additions and 602 deletions.
12 changes: 0 additions & 12 deletions .eslintignore

This file was deleted.

5 changes: 4 additions & 1 deletion adminShared/patchHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ export function setValueRecursive(
let newObject: any = {}
if (json !== undefined && checkIsPlainObjectWithGuard(json))
newObject = { ...json }
const currentValue = newObject.hasOwnProperty(currentPart)
const currentValue = Object.prototype.hasOwnProperty.call(
newObject,
currentPart
)
? newObject[currentPart]
: undefined
const updatedValue = setValueRecursive(
Expand Down
18 changes: 9 additions & 9 deletions adminShared/schemaProcessing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ function extractSchemaRecursive(
// then do not emit anything directly and recurse over the
// described properties
if (
schema.hasOwnProperty("type") &&
Object.prototype.hasOwnProperty.call(schema, "type") &&
schema.type === "object" &&
schema.hasOwnProperty("properties") &&
Object.prototype.hasOwnProperty.call(schema, "properties") &&
checkIsPlainObjectWithGuard(schema.properties)
) {
// Color scales are complex objects that are treated as opaque objects with a special
Expand Down Expand Up @@ -166,15 +166,15 @@ function extractSchemaRecursive(
// paternProperties is ".*" and the type of those
// is string (interpreted as a color)
// We yield something like this as a single entry
schema.hasOwnProperty("type") &&
Object.prototype.hasOwnProperty.call(schema, "type") &&
schema.type === "object" &&
schema.hasOwnProperty("patternProperties") &&
Object.prototype.hasOwnProperty.call(schema, "patternProperties") &&
Object.values(
schema.patternProperties as Record<string, any>
).every(
(item: any) =>
checkIsPlainObjectWithGuard(item) &&
item.hasOwnProperty("type") &&
Object.prototype.hasOwnProperty.call(item, "type") &&
isPlainTypeString((item as any).type)
)
) {
Expand Down Expand Up @@ -234,7 +234,7 @@ function extractSchemaRecursive(
// a primitive type. If so we collect all the types
// and yield a single FieldDefinition with the merged
// type
schema.hasOwnProperty("oneOf") &&
Object.prototype.hasOwnProperty.call(schema, "oneOf") &&
isArray(schema.oneOf) &&
schema.oneOf.map((item) => item.type).every(isPlainTypeStringOrNull)
) {
Expand Down Expand Up @@ -264,13 +264,13 @@ function recursiveDereference(
schema !== undefined &&
checkIsPlainObjectWithGuard(schema)
) {
if (schema.hasOwnProperty("$ref")) {
if (Object.prototype.hasOwnProperty.call(schema, "$ref")) {
const ref = schema["$ref"] as string
const localPrefix = "#/$defs/"
if (!ref.startsWith(localPrefix))
throw "Only local refs are supported at the moment!"
const refName = ref.substring(localPrefix.length)
if (!defs.hasOwnProperty(refName)) {
if (!Object.prototype.hasOwnProperty.call(defs, refName)) {
console.error("Reference not found", refName)
return schema
} else return defs[refName] // Note: we are not using recursive dereferencing, i.e. if there are refs in the $defs section we don't resolve them here
Expand All @@ -281,7 +281,7 @@ function recursiveDereference(
}

function dereference(schema: Record<string, unknown>): any {
if (!schema.hasOwnProperty("$defs")) return
if (!Object.prototype.hasOwnProperty.call(schema, "$defs")) return
const defs = schema["$defs"] as Record<string, unknown>

const dereferenced = recursiveDereference(schema, defs)
Expand Down
2 changes: 0 additions & 2 deletions adminSiteClient/.eslintrc.yaml

This file was deleted.

1 change: 0 additions & 1 deletion adminSiteClient/Admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ export class Admin {
}

@action.bound private removeRequest(request: Promise<Response>): void {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.currentRequests = this.currentRequests.filter(
(req) => req !== request
)
Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/GrapherConfigGridEditorTypesAndUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export function fetchVariablesParametersFromQueryString(
sExpressionContext: OperationContext
): FetchVariablesParameters {
let filterQuery: Operation | undefined = undefined
if (params.hasOwnProperty("filter")) {
if (Object.prototype.hasOwnProperty.call(params, "filter")) {
filterQuery = parseToOperation(params.filter!, sExpressionContext)
}
return {
Expand Down
4 changes: 2 additions & 2 deletions adminSiteClient/SiteRedirectsIndexPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { AdminAppContext } from "./AdminAppContext.js"
import { AdminLayout } from "./AdminLayout.js"
import { Link } from "./Link.js"

const SOURCE_PATTERN = /^\/$|^\/.*[^\/]+$/
const SOURCE_PATTERN = /^\/$|^\/.*[^/]+$/
const INVALID_SOURCE_MESSAGE =
"URL must start with a slash and cannot end with a slash, unless it's the root."
const TARGET_PATTERN = /^\/$|^(https?:\/\/|\/).*[^\/]+$/
const TARGET_PATTERN = /^\/$|^(https?:\/\/|\/).*[^/]+$/
const INVALID_TARGET_MESSAGE =
"URL must start with a slash or http(s):// and cannot end with a slash, unless it's the root."

Expand Down
4 changes: 2 additions & 2 deletions adminSiteClient/VariablesIndexPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
reaction,
IReactionDisposer,
} from "mobx"
import * as lodash from "lodash"
import lodash from "lodash"

import { AdminLayout } from "./AdminLayout.js"
import { SearchField, FieldsRow } from "./Forms.js"
Expand Down Expand Up @@ -42,7 +42,7 @@ export class VariablesIndexPage extends Component {
const html = text.replace(
new RegExp(
this.highlightSearch.replace(
/[-\/\\^$*+?.()|[\]{}]/g,
/[-/\\^$*+?.()|[\]{}]/g,
"\\$&"
),
"i"
Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/gdocsValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function validatePublishedAt(gdoc: OwidGdoc, errors: OwidGdocErrorMessage[]) {
}

function validateSlug(gdoc: OwidGdoc, errors: OwidGdocErrorMessage[]) {
if (!gdoc.slug.match(/^[a-z0-9-\/]+$/)) {
if (!gdoc.slug.match(/^[a-z0-9-/]+$/)) {
errors.push({
property: "slug",
type: OwidGdocErrorMessageType.Error,
Expand Down
2 changes: 0 additions & 2 deletions adminSiteServer/.eslintrc.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion adminSiteServer/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jest.mock("googleapis", () => {
import { OwidAdminApp } from "./appClass.js"

import { logInAsUser } from "./authentication.js"
import knex, { Knex } from "knex"
import { Knex, knex } from "knex"
import { dbTestConfig } from "../db/tests/dbTestConfig.js"
import {
TransactionCloseMode,
Expand Down
2 changes: 0 additions & 2 deletions baker/.eslintrc.yaml

This file was deleted.

11 changes: 4 additions & 7 deletions baker/batchTagWithGpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,10 @@ if (require.main === module) {
})
},
async (argv) => {
try {
await db.knexReadonlyTransaction(
(trx) => batchTagChartsWithGpt(trx, argv),
db.TransactionCloseMode.Close
)
} finally {
}
await db.knexReadonlyTransaction(
(trx) => batchTagChartsWithGpt(trx, argv),
db.TransactionCloseMode.Close
)
}
)
.help()
Expand Down
6 changes: 2 additions & 4 deletions baker/pageOverrides.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ export const getPostBySlugLogToSlackNoThrow = async (
knex: KnexReadonlyTransaction,
slug: string
) => {
let post
try {
post = await getFullPostBySlugFromSnapshot(knex, slug)
return await getFullPostBySlugFromSnapshot(knex, slug)
} catch (err) {
void logErrorAndMaybeSendToBugsnag(err)
} finally {
return post
return undefined
}
}

Expand Down
4 changes: 2 additions & 2 deletions baker/siteRenderers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ThankYouPage } from "../site/ThankYouPage.js"
import TombstonePage from "../site/TombstonePage.js"
import OwidGdocPage from "../site/gdocs/OwidGdocPage.js"
import ReactDOMServer from "react-dom/server.js"
import * as lodash from "lodash"
import lodash from "lodash"
import { formatCountryProfile, isCanonicalInternalUrl } from "./formatting.js"
import {
bakeGrapherUrls,
Expand Down Expand Up @@ -621,9 +621,9 @@ export const renderProminentLinks = async (
)
)
$block.remove()
return
}
}
if (!title) return

const image =
$block.find("figure").html() ||
Expand Down
4 changes: 0 additions & 4 deletions db/.eslintrc.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion db/model/Gdoc/htmlToEnriched.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ interface ParseContext {
to some html tags like <br />
*/
const wpTagRegex =
/wp:(?<tag>([\w\/-]+))\s*(?<attributes>{.*})?\s*(?<isVoidElement>\/)?$/
/wp:(?<tag>([\w/-]+))\s*(?<attributes>{.*})?\s*(?<isVoidElement>\/)?$/

/** Unwraps a CheerioElement in the sense that it applies
cheerioElementsToArchieML on the children, returning the result. In effect
Expand Down
1 change: 0 additions & 1 deletion db/refreshPageviewsFromDatasette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ const main = async (): Promise<void> => {
)
} catch (e) {
console.error(e)
} finally {
}
}

Expand Down
10 changes: 8 additions & 2 deletions devTools/cloudflareImagesSync/cloudflareImagesSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
CLOUDFLARE_IMAGES_API_KEY,
IMAGE_HOSTING_R2_CDN_URL,
} from "../../settings/serverSettings.js"
import { excludeNullish, keyBy } from "@ourworldindata/utils"
import { keyBy } from "@ourworldindata/utils"

type CloudflareImageDirectory = Record<string, { id: string; filename: string }>

Expand Down Expand Up @@ -89,6 +89,7 @@ async function validateDirectory(
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function purgeRecords(trx: db.KnexReadWriteTransaction) {
await new Promise<void>((resolve) => {
const readlineInterface = readline.createInterface({
Expand Down Expand Up @@ -449,4 +450,9 @@ You need to set "CLOUDFLARE_IMAGES_ACCOUNT_ID" and "CLOUDFLARE_IMAGES_API_KEY" i
})
}

main().then(() => process.exit(0))
main()
.then(() => process.exit(0))
.catch((e) => {
console.error(e)
process.exit(1)
})
2 changes: 1 addition & 1 deletion devTools/explorerTools/extractGrapherIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ async function main(): Promise<void> {
console.log(csvRows.join("\n"))
}

main()
void main()
2 changes: 1 addition & 1 deletion devTools/explorerTools/rewriteAllExplorers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ const rewriteAllExplorers = async () => {
console.log("Finished rewriting", allExplorers.length, "explorers")
}

rewriteAllExplorers()
void rewriteAllExplorers()
2 changes: 1 addition & 1 deletion devTools/flagUpdater/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ const main = async () => {
}
}

main()
void main()
8 changes: 2 additions & 6 deletions devTools/gdocs/fetch-by-id.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#! /usr/bin/env node

import { TransactionCloseMode, knexReadonlyTransaction } from "../../db/db.js"

import fs from "fs-extra"

import parseArgs from "minimist"

import { OwidGoogleAuth } from "../../db/OwidGoogleAuth.js"
Expand All @@ -19,7 +15,7 @@ async function main(parsedArgs: parseArgs.ParsedArgs) {
suggestionsViewMode: "PREVIEW_WITHOUT_SUGGESTIONS",
})
// Remove the Authorization header from the response before printing it
delete response.config.headers.Authorization
delete response.config?.headers?.Authorization
process.stdout.write(JSON.stringify(response, null, 2))
} catch (error) {
console.error("Encountered an error: ", error)
Expand All @@ -40,5 +36,5 @@ Usage:
`)
process.exit(0)
} else {
main(parsedArgs)
void main(parsedArgs)
}
6 changes: 3 additions & 3 deletions devTools/graphersToGit/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const dumpGraphers = async () => {
JSON.stringify(mapToObjectLiteral(graphersById), null, 2),
"utf8"
)
closeTypeOrmAndKnexConnections()
void closeTypeOrmAndKnexConnections()
}

// If an author changes the map variable then removes that variable, we don't remove it from map config.
Expand Down Expand Up @@ -205,7 +205,7 @@ const dumpComplexSelections = async () => {
}),
"utf8"
)
closeTypeOrmAndKnexConnections()
void closeTypeOrmAndKnexConnections()
}

const getArgsOrErrorMessage = () => {
Expand Down Expand Up @@ -240,4 +240,4 @@ const tasks = [
dumpColorScales,
]

main()
void main()
13 changes: 3 additions & 10 deletions devTools/markdownTest/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import {
TransactionCloseMode,
knexReadWriteTransaction,
knexReadonlyTransaction,
} from "../../db/db.js"
import { TransactionCloseMode, knexReadonlyTransaction } from "../../db/db.js"
import { getPostRawBySlug } from "../../db/model/Post.js"
import { enrichedBlocksToMarkdown } from "../../db/model/Gdoc/enrichedToMarkdown.js"

import fs from "fs-extra"

import parseArgs from "minimist"
import { OwidEnrichedGdocBlock } from "@ourworldindata/utils"
import { parsePostArchieml } from "@ourworldindata/utils"
import { OwidEnrichedGdocBlock, parsePostArchieml } from "@ourworldindata/utils"
import { getAndLoadGdocBySlug } from "../../db/model/Gdoc/GdocFactory.js"

async function main(parsedArgs: parseArgs.ParsedArgs) {
Expand Down Expand Up @@ -58,4 +51,4 @@ async function main(parsedArgs: parseArgs.ParsedArgs) {
}

const parsedArgs = parseArgs(process.argv.slice(2))
main(parsedArgs)
void main(parsedArgs)
4 changes: 2 additions & 2 deletions devTools/navigationTest/navigationTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const testSiteNavigation = async () => {
return categorySlugs
})

let promises = slugs.map((slug) => {
const promises = slugs.map((slug) => {
return fetch(`https://ourworldindata.org/${slug}`, {
method: "HEAD",
})
Expand All @@ -36,4 +36,4 @@ const testSiteNavigation = async () => {
console.log("✅ All fetches completed")
}

testSiteNavigation()
void testSiteNavigation()
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import parseArgs from "minimist"
import { knexRaw, knexReadWriteTransaction } from "../../db/db.js"
import {
DbInsertPostGdocComponent,
DbRawPostGdoc,
parsePostGdocContent,
} from "@ourworldindata/types"
import { DbRawPostGdoc, parsePostGdocContent } from "@ourworldindata/types"
import { getGdocComponentsWithoutChildren } from "../../db/model/Gdoc/extractGdocComponentInfo.js"

async function main(parsedArgs: parseArgs.ParsedArgs) {
async function main() {
await knexReadWriteTransaction(async (trx) => {
await knexRaw(trx, `DELETE FROM posts_gdocs_components`)
console.log("Deleted all rows from posts_gdocs_components")
Expand Down Expand Up @@ -47,5 +43,5 @@ if (parsedArgs["h"]) {
`reconstructPostsGdocsComponents - Reconstruct posts_gdocs_components table from posts_gdocs table`
)
} else {
main(parsedArgs)
void main()
}
Loading

0 comments on commit cccf8c7

Please sign in to comment.