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

Update to ESlint 9 and flat config #4358

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
  •  
  •  
  •  
12 changes: 0 additions & 12 deletions .eslintignore

This file was deleted.

74 changes: 0 additions & 74 deletions .eslintrc.cjs

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") &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because of the no-prototype-builtins rule.

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: 1 addition & 1 deletion adminShared/search.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { drop, escapeRegExp, sortBy } from "@ourworldindata/utils"
import React from "react"
import * as React from "react"

export interface SearchWord {
regex: RegExp
Expand Down
2 changes: 0 additions & 2 deletions adminSiteClient/.eslintrc.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions adminSiteClient/Admin.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from "react"
import ReactDOM from "react-dom"
import * as lodash from "lodash"
import { observable, computed, action } from "mobx"
Expand Down Expand Up @@ -163,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/AdminApp.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import * as React from "react"
import { Admin } from "./Admin.js"
import { ChartEditorPage } from "./ChartEditorPage.js"
import { action } from "mobx"
Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/AdminAppContext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import * as React from "react"
import { Admin } from "./Admin.js"

export interface AdminAppContextType {
Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/AdminLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import * as React from "react"
import { observable, action, computed } from "mobx"
import { observer } from "mobx-react"

Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/AdminSidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Link } from "./Link.js"
import React from "react"
import * as React from "react"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome/index.js"
import {
faChartBar,
Expand Down
6 changes: 3 additions & 3 deletions adminSiteClient/BulkDownloadPage.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react"
import { Component } from "react"
import { observer } from "mobx-react"
import { AdminLayout } from "./AdminLayout.js"
import { AdminAppContext, AdminAppContextType } from "./AdminAppContext.js"

@observer
export class BulkDownloadPage extends React.Component {
export class BulkDownloadPage extends Component {
static contextType = AdminAppContext
context!: AdminAppContextType

Expand All @@ -20,7 +20,7 @@ export class BulkDownloadPage extends React.Component {
}
}

export class DownloadChartsSection extends React.Component {
export class DownloadChartsSection extends Component {
render() {
return (
<section>
Expand Down
4 changes: 2 additions & 2 deletions adminSiteClient/BulkGrapherConfigEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import { Component } from "react"
import {
chartBulkUpdateAllowedColumnNamesAndTypes,
WHITELISTED_SQL_COLUMN_NAMES,
Expand Down Expand Up @@ -130,7 +130,7 @@ const config: GrapherConfigGridEditorConfig = {
finalVariableLayerModificationFn: () => ({}),
}

export class BulkGrapherConfigEditorPage extends React.Component {
export class BulkGrapherConfigEditorPage extends Component {
render() {
return (
<AdminLayout title="Bulk chart editor">
Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/ChartEditorView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import * as React from "react"
import { observer } from "mobx-react"
import {
observable,
Expand Down
4 changes: 2 additions & 2 deletions adminSiteClient/ChartIndexPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import { Component } from "react"
import { observer } from "mobx-react"
import { observable, computed, action, runInAction } from "mobx"

Expand All @@ -15,7 +15,7 @@ import {
import { sortNumeric, SortOrder } from "@ourworldindata/utils"

@observer
export class ChartIndexPage extends React.Component {
export class ChartIndexPage extends Component {
static contextType = AdminAppContext
context!: AdminAppContextType

Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/ChartList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import * as React from "react"
import { observer } from "mobx-react"
import { runInAction, observable } from "mobx"
import { bind } from "decko"
Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/ChartRow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import * as React from "react"
import { observer } from "mobx-react"
import { action, runInAction } from "mobx"
import * as lodash from "lodash"
Expand Down
3 changes: 2 additions & 1 deletion adminSiteClient/ChartViewIndexPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useContext, useEffect, useMemo, useState } from "react"
import { useContext, useEffect, useMemo, useState } from "react"
import * as React from "react"
import { Button, Flex, Input, Space, Table } from "antd"

import { AdminLayout } from "./AdminLayout.js"
Expand Down
4 changes: 2 additions & 2 deletions adminSiteClient/ColorSchemeDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import { Component } from "react"
import { computed, action } from "mobx"
import Select from "react-select"
import { GrapherChartOrMapType } from "@ourworldindata/types"
Expand Down Expand Up @@ -27,7 +27,7 @@ interface ColorSchemeDropdownProps {
}

@observer
export class ColorSchemeDropdown extends React.Component<ColorSchemeDropdownProps> {
export class ColorSchemeDropdown extends Component<ColorSchemeDropdownProps> {
static defaultProps = {
additionalOptions: [],
gradientColorCount: 6,
Expand Down
8 changes: 4 additions & 4 deletions adminSiteClient/Colorpicker.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import { Component, Fragment } from "react"
import { action } from "mobx"
import { observer } from "mobx-react"
import { SketchPicker } from "react-color"
Expand All @@ -16,7 +16,7 @@ interface ColorpickerProps {
}

@observer
export class Colorpicker extends React.Component<ColorpickerProps> {
export class Colorpicker extends Component<ColorpickerProps> {
@action.bound onColor(color: string) {
if (color === "") {
this.props.onColor(undefined)
Expand All @@ -39,7 +39,7 @@ export class Colorpicker extends React.Component<ColorpickerProps> {
}

return (
<React.Fragment>
<Fragment>
<SketchPicker
disableAlpha
presetColors={availableColors.map((color) => ({
Expand All @@ -49,7 +49,7 @@ export class Colorpicker extends React.Component<ColorpickerProps> {
color={this.props.color}
onChange={(color) => this.onColor(color.hex)}
/>
</React.Fragment>
</Fragment>
)
}
}
8 changes: 4 additions & 4 deletions adminSiteClient/DatasetEditPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import { Component } from "react"
import { observer } from "mobx-react"
import { observable, computed, runInAction, action } from "mobx"
import * as lodash from "lodash"
Expand Down Expand Up @@ -81,7 +81,7 @@ class DatasetEditable {
}

@observer
class DatasetTagEditor extends React.Component<{
class DatasetTagEditor extends Component<{
newDataset: DatasetEditable
availableTags: { id: number; name: string; parentName: string }[]
}> {
Expand All @@ -106,7 +106,7 @@ class DatasetTagEditor extends React.Component<{
}

@observer
class DatasetEditor extends React.Component<{ dataset: DatasetPageData }> {
class DatasetEditor extends Component<{ dataset: DatasetPageData }> {
static contextType = AdminAppContext
context!: AdminAppContextType
@observable newDataset!: DatasetEditable
Expand Down Expand Up @@ -449,7 +449,7 @@ class DatasetEditor extends React.Component<{ dataset: DatasetPageData }> {
}

@observer
export class DatasetEditPage extends React.Component<{ datasetId: number }> {
export class DatasetEditPage extends Component<{ datasetId: number }> {
static contextType = AdminAppContext
context!: AdminAppContextType
@observable dataset?: DatasetPageData
Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/DatasetList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import * as React from "react"
import { observable, action } from "mobx"
import { observer } from "mobx-react"
import * as lodash from "lodash"
Expand Down
4 changes: 2 additions & 2 deletions adminSiteClient/DatasetsIndexPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import { Component } from "react"
import { observer } from "mobx-react"
import { observable, computed, action, runInAction } from "mobx"
import * as lodash from "lodash"
Expand All @@ -15,7 +15,7 @@ import {
} from "../adminShared/search.js"

@observer
export class DatasetsIndexPage extends React.Component {
export class DatasetsIndexPage extends Component {
static contextType = AdminAppContext
context!: AdminAppContextType

Expand Down
Loading
Loading