Skip to content

Commit

Permalink
build(eslint): disabling wildcard imports with eslint (apache#31761)
Browse files Browse the repository at this point in the history
  • Loading branch information
rusackas authored Jan 14, 2025
1 parent 44ff462 commit 8550113
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 15 deletions.
6 changes: 6 additions & 0 deletions superset-frontend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
// A safe alternative to JS's eval
import vm, { Context, RunningScriptOptions } from 'vm';
import _ from 'underscore';
/* eslint-disable-next-line no-restricted-syntax */
import * as d3array from 'd3-array';
/* eslint-disable-next-line no-restricted-syntax */
import * as colors from './colors';

// Objects exposed here should be treated like a public API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
? chrono.parseDate(value.default)?.toISOString()
: null,
default: parsedDate ? parsedDate.toISOString() : null,
};
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -48,7 +48,7 @@ export const ZoomConfigsChart: FC<ZoomConfigsChartProps> = ({
const barWidth = 15;
const data = zoomConfigsToData(value.values);

const chart = echarts.init(ref.current);
const chart = echartsInit(ref.current);

const option = {
xAxis: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import * as echarts from 'echarts';
import { util } from 'echarts';
import { isZoomConfigsFixed, isZoomConfigsLinear } from './typeguards';
import {
CreateDragGraphicOption,
Expand Down Expand Up @@ -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),
};
};

Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/models/core_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

# pylint: disable=import-outside-toplevel


from datetime import datetime

import pytest
Expand Down

0 comments on commit 8550113

Please sign in to comment.