Skip to content

Commit

Permalink
Enabling Strict boolean expressions check (deephaven#761)
Browse files Browse the repository at this point in the history
* Enable strict-boolean-expressions rule
  • Loading branch information
Zhou-Ziheng authored Oct 12, 2022
1 parent a9ff760 commit e0d6f07
Show file tree
Hide file tree
Showing 158 changed files with 956 additions and 635 deletions.
10 changes: 0 additions & 10 deletions .eslintrc

This file was deleted.

14 changes: 14 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
root: true,
extends: ['@deephaven/eslint-config'],
ignorePatterns: ['packages/golden-layout/*', 'jest.config.*'],
overrides: [
{
files: ['**/*.@(ts|tsx)'],
parserOptions: {
project: ['./tsconfig.eslint.json', './packages/*/tsconfig.json'],
tsconfigRootDir: __dirname,
},
},
],
};
20 changes: 11 additions & 9 deletions packages/chart/src/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,14 @@ export class Chart extends Component<ChartProps, ChartState> {

getCachedConfig = memoize(
(
downsamplingError,
isDownsampleFinished,
isDownsampleInProgress,
isDownsamplingDisabled
downsamplingError: unknown,
isDownsampleFinished: boolean,
isDownsampleInProgress: boolean,
isDownsamplingDisabled: boolean
) => {
const customButtons = [];
if (downsamplingError) {
const hasDownsampleError = Boolean(downsamplingError);
if (hasDownsampleError) {
customButtons.push({
name: `Downsampling failed: ${downsamplingError}`,
click: () => undefined,
Expand All @@ -221,7 +222,7 @@ export class Chart extends Component<ChartProps, ChartState> {
isDownsampleFinished ||
isDownsampleInProgress ||
isDownsamplingDisabled ||
downsamplingError
hasDownsampleError
) {
const name = Chart.downsampleButtonTitle(
isDownsampleInProgress,
Expand All @@ -247,7 +248,8 @@ export class Chart extends Component<ChartProps, ChartState> {
// Display the mode bar if there's an error or downsampling so user can see progress
// Yes, the value is a boolean or the string 'hover': https://github.com/plotly/plotly.js/blob/master/src/plot_api/plot_config.js#L249
displayModeBar:
isDownsampleInProgress || downsamplingError ? true : 'hover',
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
isDownsampleInProgress || hasDownsampleError ? true : 'hover',

// Each array gets grouped together in the mode bar
modeBarButtons: [
Expand Down Expand Up @@ -301,7 +303,7 @@ export class Chart extends Component<ChartProps, ChartState> {
}

handleAfterPlot(): void {
if (this.plot.current) {
if (this.plot.current != null) {
// TODO: Translate whatever Don was doing in plotting.js in the afterplot here so that area graphs show up properly
}
}
Expand Down Expand Up @@ -379,7 +381,7 @@ export class Chart extends Component<ChartProps, ChartState> {
}
case ChartModel.EVENT_DOWNSAMPLENEEDED:
case ChartModel.EVENT_DOWNSAMPLEFAILED: {
const downsamplingError = detail.message ? detail.message : detail;
const downsamplingError = detail.message ?? detail;
this.setState({
isDownsampleFinished: false,
isDownsampleInProgress: false,
Expand Down
42 changes: 28 additions & 14 deletions packages/chart/src/ChartUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ function isRangedPlotlyAxis(value: unknown): value is { range: Range[] } {
return (
value != null &&
(value as PlotlyAxis).range &&
!(value as PlotlyAxis).autorange
((value as PlotlyAxis).autorange === false ||
(value as PlotlyAxis).autorange === undefined)
);
}

Expand Down Expand Up @@ -435,8 +436,11 @@ class ChartUtils {
const isCommaSeparated =
placeholderDigits.indexOf(',') >= 0 || zeroDigits.indexOf(',') >= 0;
const comma = isCommaSeparated ? ',' : '';
const plotlyNumberType = numberType ? 'e' : 'f';
const type = percentSign || plotlyNumberType;
const plotlyNumberType =
numberType != null && numberType !== '' ? 'e' : 'f';

const type = percentSign !== '' ? percentSign : plotlyNumberType;

const decimalLength = decimalDigits.length + optionalDecimalDigits.length;
// IDS-4565 Plotly uses an older version of d3 which doesn't support the trim option or negative brackets
// If plotly updates it's d3 version, this should be re-enabled
Expand Down Expand Up @@ -557,7 +561,11 @@ class ChartUtils {
name: string,
settings?: Partial<ChartModelSettings>
): boolean | 'legendonly' {
if (settings?.hiddenSeries?.includes(name)) {
if (
settings != null &&
settings.hiddenSeries != null &&
settings.hiddenSeries.includes(name)
) {
return 'legendonly';
}
return true;
Expand Down Expand Up @@ -649,9 +657,8 @@ class ChartUtils {
);
set(seriesData, dataAttributeName, []);

const axisProperty = axis
? ChartUtils.getAxisPropertyName(axis.type)
: null;
const axisProperty =
axis != null ? ChartUtils.getAxisPropertyName(axis.type) : null;
if (axisProperty != null) {
const axes = axisTypeMap.get(axis.type);
if (axes) {
Expand Down Expand Up @@ -690,10 +697,13 @@ class ChartUtils {
// The default histfunc in plotly is 'count', but the data passed up from the API provides explicit x/y values and bins
// Since it's converted to bar, just set the widths of each bar
seriesData.width = [];
Object.assign(seriesData.marker.line, {
color: theme.paper_bgcolor,
width: 1,
});

if (seriesData.marker.line !== undefined) {
Object.assign(seriesData.marker.line, {
color: theme.paper_bgcolor,
width: 1,
});
}
} else if (plotStyle === dh.plot.SeriesPlotStyle.OHLC) {
(seriesData as Partial<OhclData>).increasing = {
line: { color: theme.ohlc_increasing },
Expand Down Expand Up @@ -793,7 +803,7 @@ class ChartUtils {
axisFormats.set(axisLayoutProperty, axisFormat);

const { businessCalendar } = axis;
if (businessCalendar) {
if (businessCalendar != null) {
const rangebreaks: Rangebreaks[] = [];
const {
businessPeriods,
Expand Down Expand Up @@ -1056,7 +1066,11 @@ class ChartUtils {
);

const { range, autorange } = layoutAxis;
if (getRangeParser && range && !autorange) {
if (
getRangeParser != null &&
range !== undefined &&
(autorange === undefined || autorange === false)
) {
const rangeParser = getRangeParser(axis);
const [rangeStart, rangeEnd] = rangeParser(range as Range);

Expand Down Expand Up @@ -1393,7 +1407,7 @@ class ChartUtils {
): Map<T[P], T[]> {
return array.reduce((result, item) => {
const key = item[property];
const group: T[] = result.get(key) || [];
const group: T[] = result.get(key) ?? [];
group.push(item);
result.set(key, group);
return result;
Expand Down
8 changes: 5 additions & 3 deletions packages/chart/src/FigureChartModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class FigureChartModel extends ChartModel {
this.layout.showlegend =
this.data.length > 1 || series.plotStyle === dh.plot.SeriesPlotStyle.PIE;

if (series.oneClick) {
if (series.oneClick != null) {
const { oneClick } = series;
const { columns } = oneClick;
for (let i = 0; i < columns.length; i += 1) {
Expand Down Expand Up @@ -581,8 +581,10 @@ class FigureChartModel extends ChartModel {
this.layout[axisLayoutProperty],
axisFormat
);
if (this.layout[axisLayoutProperty] != null) {
Object.assign(this.layout[axisLayoutProperty], axisFormat);

const props = this.layout[axisLayoutProperty];
if (props != null) {
Object.assign(props, axisFormat);
} else {
log.debug(`Ignoring null layout.${axisLayoutProperty}`);
}
Expand Down
4 changes: 1 addition & 3 deletions packages/code-studio/src/DownloadServiceWorkerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ class DownloadServiceWorkerUtils {
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
const swUrl = new URL(
`${
import.meta.env.BASE_URL ? `${import.meta.env.BASE_URL}` : ''
}download/serviceWorker.js`,
`${import.meta.env.BASE_URL ?? ''}download/serviceWorker.js`,
window.location.href
);

Expand Down
2 changes: 1 addition & 1 deletion packages/code-studio/src/log/LogInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function logInit(): void {
logHistory.enable();
}

if (window) {
if (window != null) {
// Expose the default logger so that log level can be changed dynamically
window.DHLog = Log;
window.DHLogProxy = logProxy;
Expand Down
4 changes: 2 additions & 2 deletions packages/code-studio/src/main/AppControlsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ const DragSourceMenuItem = (props: DragSourceMenuItemProps) => {
const handleMouseMove = useCallback(
(event: MouseEvent) => {
if (
startX.current &&
startY.current &&
startX.current != null &&
startY.current != null &&
startObject.current &&
(Math.abs(startX.current - event.clientX) >= MINIMUM_DRAG_DISTANCE ||
Math.abs(startY.current - event.clientY) >= MINIMUM_DRAG_DISTANCE)
Expand Down
8 changes: 4 additions & 4 deletions packages/code-studio/src/main/AppInit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ const AppInit = (props: AppInitProps) => {
]);

const initFonts = useCallback(() => {
if (document.fonts) {
if (document.fonts != null) {
document.fonts.ready.then(() => {
setIsFontLoading(false);
});
Expand All @@ -288,9 +288,9 @@ const AppInit = (props: AppInitProps) => {
[initClient, initFonts]
);

const isLoading = (!workspace && !error) || isFontLoading;
const isLoaded = !isLoading && !error;
const errorMessage = error ? `${error}` : null;
const isLoading = (workspace == null && error == null) || isFontLoading;
const isLoaded = !isLoading && error == null;
const errorMessage = error != null ? `${error}` : null;

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion packages/code-studio/src/main/AppMainContainer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jest.mock('@deephaven/dashboard', () => ({
__esModule: true,
Dashboard: jest.fn(({ hydrate }) => {
const result = hydrate(mockProp, mockId);
if (result.fetch) {
if (result.fetch != null) {
result.fetch();
}
return <p>{JSON.stringify(result)}</p>;
Expand Down
26 changes: 15 additions & 11 deletions packages/code-studio/src/main/AppMainContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export class AppMainContainer extends Component<

initWidgets(): void {
const { connection } = this.props;
if (!connection.subscribeToFieldUpdates) {
if (connection.subscribeToFieldUpdates == null) {
log.warn(
'subscribeToFieldUpdates not supported, not initializing widgets'
);
Expand All @@ -291,7 +291,7 @@ export class AppMainContainer extends Component<
// Now add all the modified and updated widgets back in
const widgetsToAdd = [...updated, ...created];
widgetsToAdd.forEach(toAdd => {
if (toAdd.name) {
if (toAdd.name != null && toAdd.name !== '') {
newWidgets.push(toAdd);
}
});
Expand All @@ -311,7 +311,7 @@ export class AppMainContainer extends Component<

if (notebookPath) {
const { session, sessionConfig } = this.props;
if (!session || !sessionConfig) {
if (session == null || sessionConfig == null) {
log.error('No session available to open notebook URL', notebookPath);
return;
}
Expand Down Expand Up @@ -619,7 +619,7 @@ export class AppMainContainer extends Component<
const pluginModule = plugins.get(pluginName);
if (
pluginModule != null &&
(pluginModule as { TablePlugin: ReactElement }).TablePlugin
(pluginModule as { TablePlugin: ReactElement }).TablePlugin != null
) {
return (pluginModule as {
TablePlugin: ForwardRefExoticComponent<React.RefAttributes<unknown>>;
Expand All @@ -637,14 +637,18 @@ export class AppMainContainer extends Component<
): DashboardPanelProps & { fetch?: () => Promise<unknown> } {
const { connection } = this.props;
const { metadata } = props;
if (metadata?.type && (metadata?.id || metadata?.name)) {
if (
metadata?.type != null &&
(metadata?.id != null || metadata?.name != null)
) {
// Looks like a widget, hydrate it as such
const widget: VariableDefinition = metadata.id
? {
type: metadata.type,
id: metadata.id,
}
: { type: metadata.type, name: metadata.name, title: metadata.name };
const widget: VariableDefinition =
metadata.id != null
? {
type: metadata.type,
id: metadata.id,
}
: { type: metadata.type, name: metadata.name, title: metadata.name };
return {
fetch: () => connection.getObject(widget),
localDashboardId: id,
Expand Down
2 changes: 1 addition & 1 deletion packages/code-studio/src/main/WidgetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const WidgetList = (props: WidgetListProps): JSX.Element => {
*/
const sendSelect = useCallback(
(widget: VariableDefinition, event?: WindowMouseEvent) => {
if (widget) onSelect(widget, event);
if (widget != null) onSelect(widget, event);
},
[onSelect]
);
Expand Down
14 changes: 7 additions & 7 deletions packages/code-studio/src/main/WidgetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,33 @@ export const createChartModel = async (
if (isChartPanelTableMetadata(metadata)) {
settings = metadata.settings;
tableName = metadata.table;
figureName = '';
figureName = undefined;
tableSettings = metadata.tableSettings;
} else {
settings = {};
tableName = '';
figureName = metadata.figure;
tableSettings = {};
}
if (panelState) {
if (panelState.tableSettings) {
if (panelState !== undefined) {
if (panelState.tableSettings != null) {
tableSettings = panelState.tableSettings;
}
if (panelState.table) {
if (panelState.table != null) {
tableName = panelState.table;
}
if (panelState.figure) {
if (panelState.figure != null) {
figureName = panelState.figure;
}
if (panelState.settings) {
if (panelState.settings != null) {
settings = {
...settings,
...panelState.settings,
};
}
}

if (figureName) {
if (figureName !== undefined) {
const definition = {
title: figureName,
name: figureName,
Expand Down
Loading

0 comments on commit e0d6f07

Please sign in to comment.