Skip to content

Commit

Permalink
Fix ts/eslint warnings (#32321)
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrejeambrun committed Jul 3, 2023
1 parent 5c72bef commit b6eeccd
Show file tree
Hide file tree
Showing 30 changed files with 100 additions and 37 deletions.
1 change: 1 addition & 0 deletions airflow/www/alias-rest-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ function generate(file) {

fs.writeFileSync(file, finalText, (err) => {
if (err) {
// eslint-disable-next-line no-console
console.error(err);
}
});
Expand Down
2 changes: 1 addition & 1 deletion airflow/www/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

module.exports = function (api) {
module.exports = (api) => {
api.cache(true);

const presets = [
Expand Down
2 changes: 2 additions & 0 deletions airflow/www/jest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ axios.defaults.adapter = require("axios/lib/adapters/http");
axios.interceptors.response.use((res) => res.data || res);

setLogger({
/* eslint-disable no-console */
log: console.log,
warn: console.warn,
/* eslint-enable no-console */
// ✅ no more errors on the console
error: () => {},
});
Expand Down
2 changes: 1 addition & 1 deletion airflow/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dev": "NODE_ENV=development webpack --watch --progress --devtool eval-cheap-source-map --mode development",
"prod": "NODE_ENV=production node --max_old_space_size=4096 ./node_modules/webpack/bin/webpack.js --mode production --progress",
"build": "NODE_ENV=production webpack --progress --mode production",
"lint": "eslint --ignore-path=.eslintignore --ext .js,.jsx,.ts,.tsx . && tsc",
"lint": "eslint --ignore-path=.eslintignore --max-warnings=0 --ext .js,.jsx,.ts,.tsx . && tsc",
"lint:fix": "eslint --fix --ignore-path=.eslintignore --ext .js,.jsx,.ts,.tsx . && tsc",
"format": "yarn prettier --write .",
"generate-api-types": "npx openapi-typescript \"../api_connexion/openapi/v1.yaml\" --output static/js/types/api-generated.ts && node alias-rest-types.js static/js/types/api-generated.ts"
Expand Down
2 changes: 1 addition & 1 deletion airflow/www/static/js/api/useDatasets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { getMetaValue } from "src/utils";
import type { DatasetListItem } from "src/types";
import type { unitOfTime } from "moment";

interface DatasetsData {
export interface DatasetsData {
datasets: DatasetListItem[];
totalEntries: number;
}
Expand Down
7 changes: 5 additions & 2 deletions airflow/www/static/js/api/useExtraLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,24 @@ export default function useExtraLinks({
async () => {
const data = await Promise.all(
extraLinks.map(async (link) => {
mapIndex ??= -1;
const definedMapIndex = mapIndex ?? -1;
const url = `${extraLinksUrl}?task_id=${encodeURIComponent(
taskId
)}&dag_id=${encodeURIComponent(
dagId
)}&execution_date=${encodeURIComponent(
executionDate
)}&link_name=${encodeURIComponent(link)}&map_index=${mapIndex}`;
)}&link_name=${encodeURIComponent(
link
)}&map_index=${definedMapIndex}`;
try {
const datum = await axios.get<AxiosResponse, LinkData>(url);
return {
name: link,
url: datum.url,
};
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
return {
name: link,
Expand Down
3 changes: 3 additions & 0 deletions airflow/www/static/js/callModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const showExternalLogRedirect =
const buttons = Array.from(
document.querySelectorAll('a[id^="btn_"][data-base-url]')
).reduce((obj, elm) => {
// eslint-disable-next-line no-param-reassign
obj[elm.id.replace("btn_", "")] = elm;
return obj;
}, {});
Expand All @@ -64,12 +65,14 @@ function updateButtonUrl(elm, params) {
let url = elm.dataset.baseUrl;
if (params.dag_id && elm.dataset.baseUrl.indexOf(dagId) !== -1) {
url = url.replace(dagId, params.dag_id);
// eslint-disable-next-line no-param-reassign
delete params.dag_id;
}
if (
Object.prototype.hasOwnProperty.call(params, "map_index") &&
params.map_index === undefined
) {
// eslint-disable-next-line no-param-reassign
delete params.map_index;
}
elm.setAttribute("href", `${url}?${$.param(params)}`);
Expand Down
12 changes: 7 additions & 5 deletions airflow/www/static/js/cluster-activity/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import * as useHealthModule from "src/api/useHealth";
import { render } from "@testing-library/react";

import { Wrapper } from "src/utils/testUtils";
import type { UseQueryResult } from "react-query";
import type { API, HistoricalMetricsData } from "src/types";
import ClusterActivity from ".";

const mockHistoricalMetricsData = {
Expand Down Expand Up @@ -100,39 +102,39 @@ describe("Test ToggleGroups", () => {
({
data: mockHistoricalMetricsData,
isSuccess: true,
} as any)
} as never as UseQueryResult<HistoricalMetricsData>)
);

jest.spyOn(useHealthModule, "default").mockImplementation(
() =>
({
data: mockHealthData,
isSuccess: true,
} as any)
} as never as UseQueryResult<API.HealthInfo>)
);

jest.spyOn(useDagsModule, "default").mockImplementation(
() =>
({
data: mockDagsData,
isSuccess: true,
} as any)
} as never as UseQueryResult<API.DAGCollection>)
);

jest.spyOn(useDagRunsModule, "default").mockImplementation(
() =>
({
data: mockDagRunsData,
isSuccess: true,
} as any)
} as never as UseQueryResult<API.DAGRunCollection>)
);

jest.spyOn(usePoolsModule, "default").mockImplementation(
() =>
({
data: mockPoolsData,
isSuccess: true,
} as any)
} as never as UseQueryResult<API.PoolCollection>)
);
});

Expand Down
2 changes: 2 additions & 0 deletions airflow/www/static/js/components/Table/Cells.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ import { SimpleStatus } from "src/dag/StatusBox";

interface CellProps {
cell: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value: any;
row: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
original: Record<string, any>;
};
};
Expand Down
2 changes: 1 addition & 1 deletion airflow/www/static/js/components/Table/Table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import type { SortingRule } from "react-table";
import { ChakraWrapper } from "src/utils/testUtils";
import { Table } from ".";

const data: Record<string, any>[] = [
const data: Record<string, string>[] = [
{ firstName: "Lamont", lastName: "Grimes", country: "United States" },
{ firstName: "Alysa", lastName: "Armstrong", country: "Spain" },
{ firstName: "Petra", lastName: "Blick", country: "France" },
Expand Down
6 changes: 4 additions & 2 deletions airflow/www/static/js/components/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ interface TableProps {
pageSize?: number;
isLoading?: boolean;
selectRows?: (selectedRows: number[]) => void;
onRowClicked?: (row: Row<object>, e: any) => void;
onRowClicked?: (row: Row<object>, e: unknown) => void;
}

export const Table = ({
Expand Down Expand Up @@ -244,7 +244,9 @@ export const Table = ({
}
}
onClick={
onRowClicked ? (e: any) => onRowClicked(row, e) : undefined
onRowClicked
? (e: unknown) => onRowClicked(row, e)
: undefined
}
>
{row.cells.map((cell) => (
Expand Down
3 changes: 2 additions & 1 deletion airflow/www/static/js/components/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const Tooltip = forwardRef<TooltipProps, "div">((props, ref) => {
* Ensure tooltip has only one child node
*/
const child = React.Children.only(children) as React.ReactElement & {
ref?: React.Ref<any>;
ref?: React.Ref<HTMLElement>;
};
const trigger: React.ReactElement = React.cloneElement(
child,
Expand Down Expand Up @@ -168,6 +168,7 @@ const Tooltip = forwardRef<TooltipProps, "div">((props, ref) => {
>
<StyledTooltip
variants={scale}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
{...(tooltipProps as any)}
initial="exit"
animate="enter"
Expand Down
4 changes: 4 additions & 0 deletions airflow/www/static/js/connection_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@ function getControlsContainer() {
function restoreFieldBehaviours() {
Array.from(document.querySelectorAll("label[data-orig-text]")).forEach(
(elem) => {
// eslint-disable-next-line no-param-reassign
elem.innerText = elem.dataset.origText;
// eslint-disable-next-line no-param-reassign
delete elem.dataset.origText;
}
);

Array.from(document.querySelectorAll(".form-control")).forEach((elem) => {
// eslint-disable-next-line no-param-reassign
elem.placeholder = "";
elem.parentElement.parentElement.classList.remove("hide");
});
Expand Down Expand Up @@ -259,6 +262,7 @@ $(document).ready(() => {
- All other custom form fields (i.e. fields that are named ``extra__...``) in
alphabetical order
*/
// eslint-disable-next-line func-names
$.each(inArray, function () {
if (this.name === "conn_id") {
outObj.connection_id = this.value;
Expand Down
2 changes: 1 addition & 1 deletion airflow/www/static/js/dag/details/graph/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export const nodeColor = ({

export const nodeStrokeColor = (
{ data: { isSelected } }: ReactFlowNode<CustomNodeProps>,
colors: any
colors: Record<string, string>
) => (isSelected ? colors.blue[500] : "");

interface BuildEdgesProps {
Expand Down
1 change: 1 addition & 0 deletions airflow/www/static/js/dag/grid/dagRuns/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const generateRuns = (length: number): DagRun[] =>
note: "someRandomValue",
}));

/* eslint-disable @typescript-eslint/no-explicit-any */
describe("Test DagRuns", () => {
test("Durations and manual run arrow render correctly, but without any date ticks", () => {
const dagRuns: DagRun[] = [
Expand Down
1 change: 1 addition & 0 deletions airflow/www/static/js/dag/grid/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ describe("Test ToggleGroups", () => {
const returnValue = {
data: mockGridData,
isSuccess: true,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any;

jest
Expand Down
2 changes: 2 additions & 0 deletions airflow/www/static/js/dag_dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function setUpZoomSupport() {
}

function setUpNodeHighlighting(focusItem = null) {
// eslint-disable-next-line func-names
d3.selectAll("g.node").on("mouseover", function (d) {
d3.select(this).selectAll("rect").style("stroke", highlightColor);
highlightNodes(g.predecessors(d), upstreamColor, highlightStrokeWidth);
Expand All @@ -114,6 +115,7 @@ function setUpNodeHighlighting(focusItem = null) {
});
});

// eslint-disable-next-line func-names
d3.selectAll("g.node").on("mouseout", function (d) {
d3.select(this).selectAll("rect,circle").style("stroke", null);
highlightNodes(g.predecessors(d), null, initialStrokeWidth);
Expand Down
1 change: 1 addition & 0 deletions airflow/www/static/js/dags.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ function getDagIds({ activeDagsOnly = false } = {}) {
dagIds = dagIds.filter(":checked");
}
dagIds = dagIds
// eslint-disable-next-line func-names
.map(function () {
return $(this).data("dag-id");
})
Expand Down
12 changes: 9 additions & 3 deletions airflow/www/static/js/datasets/List.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { render } from "@testing-library/react";
import * as useDatasetsModule from "src/api/useDatasets";
import { Wrapper } from "src/utils/testUtils";

import type { UseQueryResult } from "react-query";
import type { DatasetListItem } from "src/types";
import DatasetsList from "./List";

const datasets = [
Expand Down Expand Up @@ -57,22 +59,26 @@ const datasets = [
},
];

type UseDatasetsReturn = UseQueryResult<useDatasetsModule.DatasetsData> & {
data: useDatasetsModule.DatasetsData;
};

const returnValue = {
data: {
datasets,
totalEntries: datasets.length,
},
isSuccess: true,
} as any;
} as UseDatasetsReturn;

const emptyReturnValue = {
data: {
datasets: [],
datasets: [] as DatasetListItem[],
totalEntries: 0,
},
isSuccess: true,
isLoading: false,
} as any;
} as UseDatasetsReturn;

describe("Test Datasets List", () => {
test("Displays a list of datasets", () => {
Expand Down
2 changes: 2 additions & 0 deletions airflow/www/static/js/datasets/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ interface Props {

interface CellProps {
cell: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value: any;
row: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
original: Record<string, any>;
};
};
Expand Down
1 change: 1 addition & 0 deletions airflow/www/static/js/datetime_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export function updateAllDateTimes() {
// Since we have set the default timezone for moment, it will automatically
// convert it to the new target for us
$(".datetime input").each((_, el) => {
// eslint-disable-next-line no-param-reassign
el.value = moment(el.value).format();
});
}
Expand Down

0 comments on commit b6eeccd

Please sign in to comment.