From 519c3481b689d3cf890614e37fd68325593be363 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Wed, 8 Jan 2025 20:45:58 -0700 Subject: [PATCH 1/4] disabling wildcard imports with eslint --- superset-frontend/.eslintrc.js | 6 ++++++ .../cypress/e2e/dashboard/editmode.test.ts | 4 ++-- .../legacy-preset-chart-deckgl/src/layers/common.tsx | 11 +++++++---- .../legacy-preset-chart-deckgl/src/utils/sandbox.ts | 1 + .../SqlLab/components/ScheduleQueryButton/index.tsx | 4 ++-- .../controls/ZoomConfigControl/ZoomConfigsChart.tsx | 4 ++-- .../components/controls/ZoomConfigControl/zoomUtil.ts | 6 +++--- 7 files changed, 23 insertions(+), 13 deletions(-) diff --git a/superset-frontend/.eslintrc.js b/superset-frontend/.eslintrc.js index 977765142754..d2ed09e69e75 100644 --- a/superset-frontend/.eslintrc.js +++ b/superset-frontend/.eslintrc.js @@ -193,6 +193,12 @@ module.exports = { message: 'Default React import is not required due to automatic JSX runtime in React 16.4', }, + { + // this disallows wildcard imports from modules (but allows them for local files with `./` or `src/`) + selector: + 'ImportNamespaceSpecifier[parent.source.value!=/^(\\.|src)/]', + message: 'Wildcard imports are not allowed', + }, ], }, settings: { diff --git a/superset-frontend/cypress-base/cypress/e2e/dashboard/editmode.test.ts b/superset-frontend/cypress-base/cypress/e2e/dashboard/editmode.test.ts index 5059a7f7cc9e..5d7dc5f9b93e 100644 --- a/superset-frontend/cypress-base/cypress/e2e/dashboard/editmode.test.ts +++ b/superset-frontend/cypress-base/cypress/e2e/dashboard/editmode.test.ts @@ -18,7 +18,7 @@ */ import { SAMPLE_DASHBOARD_1, TABBED_DASHBOARD } from 'cypress/utils/urls'; import { drag, resize, waitForChartLoad } from 'cypress/utils'; -import * as ace from 'brace'; +import { edit } from 'brace'; import { interceptExploreUpdate, interceptGet, @@ -60,7 +60,7 @@ function assertMetadata(text: string) { // cypress can read this locally, but not in ci // so we have to use the ace module directly to fetch the value - expect(ace.edit(metadata).getValue()).to.match(regex); + expect(edit(metadata).getValue()).to.match(regex); }); } diff --git a/superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/common.tsx b/superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/common.tsx index 80f0371e5cfb..4ff84f90e493 100644 --- a/superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/common.tsx +++ b/superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/common.tsx @@ -17,7 +17,10 @@ * under the License. */ import { ReactNode } from 'react'; -import * as d3array from 'd3-array'; +import d3array, { + ascending as d3ascending, + quantile as d3quantile, +} from 'd3-array'; import { JsonObject, JsonValue, QueryFormData } from '@superset-ui/core'; import sandboxedEval from '../utils/sandbox'; import { TooltipProps } from '../components/Tooltip'; @@ -93,13 +96,13 @@ export function getAggFunc( let sortedArr; if (accessor) { sortedArr = arr.sort((o1: JsonObject, o2: JsonObject) => - d3array.ascending(accessor(o1), accessor(o2)), + d3ascending(accessor(o1), accessor(o2)), ); } else { - sortedArr = arr.sort(d3array.ascending); + sortedArr = arr.sort(d3ascending); } - return d3array.quantile(sortedArr, percentiles[type], acc); + return d3quantile(sortedArr, percentiles[type], acc); }; } else { d3func = d3array[type]; diff --git a/superset-frontend/plugins/legacy-preset-chart-deckgl/src/utils/sandbox.ts b/superset-frontend/plugins/legacy-preset-chart-deckgl/src/utils/sandbox.ts index bf41f1f200d0..eee84679199a 100644 --- a/superset-frontend/plugins/legacy-preset-chart-deckgl/src/utils/sandbox.ts +++ b/superset-frontend/plugins/legacy-preset-chart-deckgl/src/utils/sandbox.ts @@ -19,6 +19,7 @@ // A safe alternative to JS's eval import vm, { Context, RunningScriptOptions } from 'vm'; import _ from 'underscore'; +/* eslint-ignore-next-line no-restricted-syntax*/ import * as d3array from 'd3-array'; import * as colors from './colors'; diff --git a/superset-frontend/src/SqlLab/components/ScheduleQueryButton/index.tsx b/superset-frontend/src/SqlLab/components/ScheduleQueryButton/index.tsx index 83f49feef597..c87d8c693881 100644 --- a/superset-frontend/src/SqlLab/components/ScheduleQueryButton/index.tsx +++ b/superset-frontend/src/SqlLab/components/ScheduleQueryButton/index.tsx @@ -24,7 +24,7 @@ import validator from '@rjsf/validator-ajv8'; import { Row, Col } from 'src/components'; import { Input, TextArea } from 'src/components/Input'; import { t, styled } from '@superset-ui/core'; -import * as chrono from 'chrono-node'; +import { parseDate } from 'chrono-node'; import ModalTrigger, { ModalTriggerRef } from 'src/components/ModalTrigger'; import { Form, FormItem } from 'src/components/Form'; import Button from 'src/components/Button'; @@ -50,7 +50,7 @@ const getJSONSchema = () => { jsonSchema.properties[key] = { ...value, default: value.default - ? chrono.parseDate(value.default)?.toISOString() + ? parseDate(value.default)?.toISOString() : null, }; } diff --git a/superset-frontend/src/explore/components/controls/ZoomConfigControl/ZoomConfigsChart.tsx b/superset-frontend/src/explore/components/controls/ZoomConfigControl/ZoomConfigsChart.tsx index 0d4b44b53202..d3f755bd03c5 100644 --- a/superset-frontend/src/explore/components/controls/ZoomConfigControl/ZoomConfigsChart.tsx +++ b/superset-frontend/src/explore/components/controls/ZoomConfigControl/ZoomConfigsChart.tsx @@ -17,7 +17,7 @@ * under the License. */ import { t } from '@superset-ui/core'; -import * as echarts from 'echarts'; +import { init as echartsInit } from 'echarts'; import { createRef, FC, useEffect } from 'react'; import { ZoomConfigsChartProps } from './types'; import { @@ -48,7 +48,7 @@ export const ZoomConfigsChart: FC = ({ const barWidth = 15; const data = zoomConfigsToData(value.values); - const chart = echarts.init(ref.current); + const chart = echartsInit(ref.current); const option = { xAxis: { diff --git a/superset-frontend/src/explore/components/controls/ZoomConfigControl/zoomUtil.ts b/superset-frontend/src/explore/components/controls/ZoomConfigControl/zoomUtil.ts index 281c7aba5a2e..6dce39c21e1f 100644 --- a/superset-frontend/src/explore/components/controls/ZoomConfigControl/zoomUtil.ts +++ b/superset-frontend/src/explore/components/controls/ZoomConfigControl/zoomUtil.ts @@ -17,7 +17,7 @@ * under the License. */ -import * as echarts from 'echarts'; +import { util } from 'echarts'; import { isZoomConfigsFixed, isZoomConfigsLinear } from './typeguards'; import { CreateDragGraphicOption, @@ -105,10 +105,10 @@ export const createDragGraphicOption = ({ // Give a big z value, which makes the circle cover the symbol // in bar series. z: 100, - // Util method `echarts.util.curry` is used here to generate a + // Util method `util.curry` (from echarts) is used here to generate a // new function the same as `onDrag`, except that the // first parameter is fixed to be the `dataIndex` here. - ondrag: echarts.util.curry(onDrag, dataIndex), + ondrag: util.curry(onDrag, dataIndex), }; }; From 8ebd22c1d2b74d9c27b7648155e89315952aa9f4 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Wed, 8 Jan 2025 21:14:29 -0700 Subject: [PATCH 2/4] need to ignore this too --- .../plugins/legacy-preset-chart-deckgl/src/utils/sandbox.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/superset-frontend/plugins/legacy-preset-chart-deckgl/src/utils/sandbox.ts b/superset-frontend/plugins/legacy-preset-chart-deckgl/src/utils/sandbox.ts index eee84679199a..088697b45af6 100644 --- a/superset-frontend/plugins/legacy-preset-chart-deckgl/src/utils/sandbox.ts +++ b/superset-frontend/plugins/legacy-preset-chart-deckgl/src/utils/sandbox.ts @@ -19,8 +19,9 @@ // A safe alternative to JS's eval import vm, { Context, RunningScriptOptions } from 'vm'; import _ from 'underscore'; -/* eslint-ignore-next-line no-restricted-syntax*/ +/* eslint-ignore-next-line no-restricted-syntax */ import * as d3array from 'd3-array'; +/* eslint-ignore-next-line no-restricted-syntax */ import * as colors from './colors'; // Objects exposed here should be treated like a public API From 0cbe00fb3612c5d98f46936c103fc2361e053c76 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Wed, 8 Jan 2025 21:19:20 -0700 Subject: [PATCH 3/4] fixing bot feedback --- .../src/SqlLab/components/ScheduleQueryButton/index.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/superset-frontend/src/SqlLab/components/ScheduleQueryButton/index.tsx b/superset-frontend/src/SqlLab/components/ScheduleQueryButton/index.tsx index c87d8c693881..7053f5df7be6 100644 --- a/superset-frontend/src/SqlLab/components/ScheduleQueryButton/index.tsx +++ b/superset-frontend/src/SqlLab/components/ScheduleQueryButton/index.tsx @@ -47,11 +47,10 @@ const getJSONSchema = () => { Object.entries(jsonSchema.properties).forEach( ([key, value]: [string, any]) => { if (value.default && value.format === 'date-time') { + const parsedDate = parseDate(value.default); jsonSchema.properties[key] = { ...value, - default: value.default - ? parseDate(value.default)?.toISOString() - : null, + default: parsedDate ? parsedDate.toISOString() : null, }; } }, From 7e5ae22225b045f581fefb65da6b11ccf2b96448 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Thu, 9 Jan 2025 09:03:46 -0700 Subject: [PATCH 4/4] fixing disabled lines --- .../plugins/legacy-preset-chart-deckgl/src/utils/sandbox.ts | 4 ++-- tests/unit_tests/models/core_test.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/superset-frontend/plugins/legacy-preset-chart-deckgl/src/utils/sandbox.ts b/superset-frontend/plugins/legacy-preset-chart-deckgl/src/utils/sandbox.ts index 088697b45af6..f9accf445dec 100644 --- a/superset-frontend/plugins/legacy-preset-chart-deckgl/src/utils/sandbox.ts +++ b/superset-frontend/plugins/legacy-preset-chart-deckgl/src/utils/sandbox.ts @@ -19,9 +19,9 @@ // A safe alternative to JS's eval import vm, { Context, RunningScriptOptions } from 'vm'; import _ from 'underscore'; -/* eslint-ignore-next-line no-restricted-syntax */ +/* eslint-disable-next-line no-restricted-syntax */ import * as d3array from 'd3-array'; -/* eslint-ignore-next-line no-restricted-syntax */ +/* eslint-disable-next-line no-restricted-syntax */ import * as colors from './colors'; // Objects exposed here should be treated like a public API diff --git a/tests/unit_tests/models/core_test.py b/tests/unit_tests/models/core_test.py index 7722578a1d7d..f399fc85240d 100644 --- a/tests/unit_tests/models/core_test.py +++ b/tests/unit_tests/models/core_test.py @@ -17,6 +17,7 @@ # pylint: disable=import-outside-toplevel + from datetime import datetime import pytest