Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion superset-frontend/oxlint.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"plugins": ["import", "react", "jest", "jsx-a11y", "typescript", "unicorn"],
"plugins": [
"import",
"react",
"jest",
"jsx-a11y",
"typescript",
"unicorn",
"oxc"
],
"env": {
"browser": true,
"node": true,
Expand Down Expand Up @@ -73,6 +81,12 @@
"as-needed",
{ "requireReturnForObjectLiteral": false }
],
"no-useless-constructor": "error",
"no-else-return": "error",
"no-array-constructor": "error",
"no-new-wrappers": "error",
"no-regex-spaces": "error",
"no-object-constructor": "error",

// === Import plugin rules ===
"import/no-unresolved": "error",
Expand Down Expand Up @@ -256,6 +270,15 @@
"unicorn/no-new-array": "error",
"unicorn/no-invalid-remove-event-listener": "error",
"unicorn/no-useless-length-check": "error",
"unicorn/no-length-as-slice-end": "error",
"unicorn/no-useless-spread": "error",
"unicorn/no-thenable": "error",
"unicorn/escape-case": "error",
"unicorn/prefer-array-flat-map": "error",
"unicorn/prefer-array-some": "error",
"unicorn/throw-new-error": "error",
"unicorn/prefer-negative-index": "error",
"unicorn/prefer-math-trunc": "error",
"unicorn/filename-case": "off",
"unicorn/prevent-abbreviations": "off",
"unicorn/no-null": "off",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ export const datePickerInAdhocFilterMixin: Pick<
// 2) there was a time filter in adhoc filters
if (
state?.controls?.time_range?.value ||
ensureIsArray(control.value).findIndex(
ensureIsArray(control.value).some(
(flt: any) => flt?.operator === 'TEMPORAL_RANGE',
) > -1
)
) {
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,14 +443,12 @@ const order_by_cols: SharedControlConfig<'SelectControl'> = {
default: [],
shouldMapStateToProps: () => true,
mapStateToProps: ({ datasource }) => ({
choices: (datasource?.columns || [])
.map(col =>
[true, false].map(asc => [
JSON.stringify([col.column_name, asc]),
`${getColumnLabel(col.column_name)} [${asc ? 'asc' : 'desc'}]`,
]),
)
.flat(),
choices: (datasource?.columns || []).flatMap(col =>
[true, false].map(asc => [
JSON.stringify([col.column_name, asc]),
`${getColumnLabel(col.column_name)} [${asc ? 'asc' : 'desc'}]`,
]),
),
}),
resetOnHide: false,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const config = (contentType: ContentType) => {
};

default:
throw Error(`Invalid type provided: ${type}`);
throw new Error(`Invalid type provided: ${type}`);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ const MetadataBar = ({ items, tooltipPlacement = 'top' }: MetadataBarProps) => {
const sortedItems = uniqueItems.sort((a, b) => ORDER[a.type] - ORDER[b.type]);
const count = sortedItems.length;
if (count < MIN_NUMBER_ITEMS) {
throw Error('The minimum number of items for the metadata bar is 2.');
throw new Error('The minimum number of items for the metadata bar is 2.');
}
if (count > MAX_NUMBER_ITEMS) {
throw Error('The maximum number of items for the metadata bar is 6.');
throw new Error('The maximum number of items for the metadata bar is 6.');
}

const onResize = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class TTestTable extends Component<TTestTableProps, TTestTableState> {
const { control, liftValues, pValues } = this.state;

if (!Array.isArray(groups) || groups.length === 0) {
throw Error('Group by param is required');
throw new Error('Group by param is required');
}

// Render column header for each group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,31 +87,29 @@ function getQueryMode(controls: ControlStateMapping): QueryMode {
}

const processComparisonColumns = (columns: any[], suffix: string) =>
columns
.map(col => {
if (!col.label.includes(suffix)) {
return [
{
label: `${t('Main')} ${col.label}`,
value: `${t('Main')} ${col.value}`,
},
{
label: `# ${col.label}`,
value: `# ${col.value}`,
},
{
label: `△ ${col.label}`,
value: `△ ${col.value}`,
},
{
label: `% ${col.label}`,
value: `% ${col.value}`,
},
];
}
return [];
})
.flat();
columns.flatMap(col => {
if (!col.label.includes(suffix)) {
return [
{
label: `${t('Main')} ${col.label}`,
value: `${t('Main')} ${col.value}`,
},
{
label: `# ${col.label}`,
value: `# ${col.value}`,
},
{
label: `△ ${col.label}`,
value: `△ ${col.value}`,
},
{
label: `% ${col.label}`,
value: `% ${col.value}`,
},
];
}
return [];
});

/**
* Visibility check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,93 +216,91 @@ const processComparisonColumns = (
props: TableChartProps,
comparisonSuffix: string,
) =>
columns
.map(col => {
const {
datasource: { columnFormats, currencyFormats },
rawFormData: { column_config: columnConfig = {} },
} = props;
const savedFormat = columnFormats?.[col.key];
const savedCurrency = currencyFormats?.[col.key];
const originalLabel = col.label;
if (
(col.isMetric || col.isPercentMetric) &&
!col.key.includes(comparisonSuffix) &&
col.isNumeric
) {
return [
{
...col,
originalLabel,
metricName: col.key,
label: t('Main'),
key: `${t('Main')} ${col.key}`,
config: getComparisonColConfig(t('Main'), col.key, columnConfig),
formatter: getComparisonColFormatter(
t('Main'),
col,
columnConfig,
savedFormat,
savedCurrency,
),
},
{
...col,
originalLabel,
metricName: col.key,
label: `#`,
key: `# ${col.key}`,
config: getComparisonColConfig(`#`, col.key, columnConfig),
formatter: getComparisonColFormatter(
`#`,
col,
columnConfig,
savedFormat,
savedCurrency,
),
},
{
...col,
originalLabel,
metricName: col.key,
label: `△`,
key: `△ ${col.key}`,
config: getComparisonColConfig(`△`, col.key, columnConfig),
formatter: getComparisonColFormatter(
`△`,
col,
columnConfig,
savedFormat,
savedCurrency,
),
},
{
...col,
originalLabel,
metricName: col.key,
label: `%`,
key: `% ${col.key}`,
config: getComparisonColConfig(`%`, col.key, columnConfig),
formatter: getComparisonColFormatter(
`%`,
col,
columnConfig,
savedFormat,
savedCurrency,
),
},
];
}
if (
!col.isMetric &&
!col.isPercentMetric &&
!col.key.includes(comparisonSuffix)
) {
return [col];
}
return [];
})
.flat();
columns.flatMap(col => {
const {
datasource: { columnFormats, currencyFormats },
rawFormData: { column_config: columnConfig = {} },
} = props;
const savedFormat = columnFormats?.[col.key];
const savedCurrency = currencyFormats?.[col.key];
const originalLabel = col.label;
if (
(col.isMetric || col.isPercentMetric) &&
!col.key.includes(comparisonSuffix) &&
col.isNumeric
) {
return [
{
...col,
originalLabel,
metricName: col.key,
label: t('Main'),
key: `${t('Main')} ${col.key}`,
config: getComparisonColConfig(t('Main'), col.key, columnConfig),
formatter: getComparisonColFormatter(
t('Main'),
col,
columnConfig,
savedFormat,
savedCurrency,
),
},
{
...col,
originalLabel,
metricName: col.key,
label: `#`,
key: `# ${col.key}`,
config: getComparisonColConfig(`#`, col.key, columnConfig),
formatter: getComparisonColFormatter(
`#`,
col,
columnConfig,
savedFormat,
savedCurrency,
),
},
{
...col,
originalLabel,
metricName: col.key,
label: `△`,
key: `△ ${col.key}`,
config: getComparisonColConfig(`△`, col.key, columnConfig),
formatter: getComparisonColFormatter(
`△`,
col,
columnConfig,
savedFormat,
savedCurrency,
),
},
{
...col,
originalLabel,
metricName: col.key,
label: `%`,
key: `% ${col.key}`,
config: getComparisonColConfig(`%`, col.key, columnConfig),
formatter: getComparisonColFormatter(
`%`,
col,
columnConfig,
savedFormat,
savedCurrency,
),
},
];
}
if (
!col.isMetric &&
!col.isPercentMetric &&
!col.key.includes(comparisonSuffix)
) {
return [col];
}
return [];
});

const serverPageLengthMap = new Map();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Handlebars.registerHelper('dateFormat', function (context, block) {
Handlebars.registerHelper('stringify', (obj: any, obj2: any) => {
// calling without an argument
if (obj2 === undefined)
throw Error('Please call with an object. Example: `stringify myObj`');
throw new Error('Please call with an object. Example: `stringify myObj`');
return isPlainObject(obj) ? JSON.stringify(obj) : String(obj);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ export default typedMemo(function DataTable<D extends object>({
function hashString(s: string): string {
let h = 0;
for (let i = 0; i < s.length; i += 1) {
// oxlint-disable-next-line unicorn/prefer-math-trunc -- | 0 is intentional for 32-bit integer wrapping in hash
h = (h * 31 + s.charCodeAt(i)) | 0;
}
return String(h);
Expand Down
Loading
Loading