Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade eslint-plugin-react-hooks from 2.3.0 to 4.0.4 #68295

Merged
merged 4 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@
"eslint-plugin-prefer-object-spread": "^1.2.1",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-react": "^7.17.0",
"eslint-plugin-react-hooks": "^2.3.0",
"eslint-plugin-react-hooks": "^4.0.4",
"eslint-plugin-react-perf": "^3.2.3",
"exit-hook": "^2.2.0",
"faker": "1.1.0",
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/charts/public/services/theme/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ export class ThemeService {

/** A React hook for consuming the charts theme */
public useChartsTheme = () => {
/* eslint-disable-next-line react-hooks/rules-of-hooks */
const [value, update] = useState(this.chartsDefaultTheme);

/* eslint-disable-next-line react-hooks/rules-of-hooks */
useEffect(() => {
const s = this.chartsTheme$.subscribe(update);
return () => s.unsubscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const Editor = memo(({ loading }: Props) => {
INITIAL_PANEL_WIDTH,
]);

/* eslint-disable-next-line react-hooks/exhaustive-deps */
const onPanelWidthChange = useCallback(
debounce((widths: number[]) => {
storage.set(StorageKeys.WIDTH, widths);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const useSaveCurrentTextObject = () => {

const { currentTextObject } = useEditorReadContext();

/* eslint-disable-next-line react-hooks/exhaustive-deps */
return useCallback(
throttle(
(text: string) => {
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/ui/search_bar/create_search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,14 @@ export function createSearchBar({ core, storage, data }: StatefulSearchBarDeps)
queryRef.current = props.query;
setQuery(props.query || defaultQuery);
}
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [defaultQuery, props.query]);

useEffect(() => {
if (props.onQuerySubmit !== onQuerySubmitRef.current) {
onQuerySubmitRef.current = props.onQuerySubmit;
}
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [props.onQuerySubmit]);

// handle service state updates.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function HasExtendedBoundsParamEditor(props: AggParamEditorProps<boolean>) {

setValue(value && agg.params.min_doc_count);
}
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [agg.params.min_doc_count, setValue, value]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const CUSTOM_METRIC = {
};

function useCompatibleAggCallback(aggFilter: AggFilter) {
/* eslint-disable-next-line react-hooks/exhaustive-deps */
return useCallback(isCompatibleAggregation(aggFilter), [aggFilter]);
}

Expand Down
2 changes: 2 additions & 0 deletions src/plugins/vis_type_timelion/public/components/panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ function Panel({ interval, seriesList, renderComplete }: PanelProps) {
[chartElem]
);

/* eslint-disable-next-line react-hooks/exhaustive-deps */
const highlightSeries = useCallback(
debounce(({ currentTarget }: JQuery.TriggeredEvent) => {
const id = Number(currentTarget.getAttribute(SERIES_ID_ATTR));
Expand Down Expand Up @@ -295,6 +296,7 @@ function Panel({ interval, seriesList, renderComplete }: PanelProps) {
[plot, legendValueNumbers, unhighlightSeries, legendCaption]
);

/* eslint-disable-next-line react-hooks/exhaustive-deps */
const debouncedSetLegendNumbers = useCallback(
debounce(setLegendNumbers, DEBOUNCE_DELAY, {
maxWait: DEBOUNCE_DELAY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export function AgentConfigurationCreateEdit({
..._newConfig,
settings: existingConfig?.settings || {},
}));
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [existingConfig]);

// update newConfig when existingConfig has loaded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ export const TransactionDistribution: FunctionComponent<Props> = (
bucketIndex,
} = props;

/* eslint-disable-next-line react-hooks/exhaustive-deps */
const formatYShort = useCallback(getFormatYShort(transactionType), [
transactionType,
]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the violation here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
My guess is that its trying to analyze the source code of the first param, but since its not a function expression, it can't.
The following is valid:

  const formatYShort = useCallback(() => getFormatYShort(transactionType), [
    transactionType,
  ]);


/* eslint-disable-next-line react-hooks/exhaustive-deps */
const formatYLong = useCallback(getFormatYLong(transactionType), [
transactionType,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const TransactionActionMenu: FunctionComponent<Props> = ({
{ key: 'transaction.name', value: transaction?.transaction.name },
{ key: 'transaction.type', value: transaction?.transaction.type },
].filter((filter): filter is Filter => typeof filter.value === 'string'),
/* eslint-disable-next-line react-hooks/exhaustive-deps */
[transaction]
);

Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/apm/public/hooks/useFetcher.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ describe('useFetcher', () => {
jest.useFakeTimers();

const hook = renderHook(
/* eslint-disable-next-line react-hooks/exhaustive-deps */
({ callback, args }) => useFetcher(callback, args),
{
initialProps: {
Expand Down Expand Up @@ -165,6 +166,7 @@ describe('useFetcher', () => {

it('should return the same object reference when data is unchanged between rerenders', async () => {
const hook = renderHook(
/* eslint-disable-next-line react-hooks/exhaustive-deps */
({ callback, args }) => useFetcher(callback, args),
{
initialProps: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const MetricsAlertDropdown = () => {
<FormattedMessage id="xpack.infra.alerting.manageAlerts" defaultMessage="Manage alerts" />
</EuiContextMenuItem>,
];
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [kibana.services]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const Expressions: React.FC<Props> = (props) => {
aggregation: 'avg',
};
}
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [alertsContext.metadata]);

const updateParams = useCallback(
Expand All @@ -109,6 +110,7 @@ export const Expressions: React.FC<Props> = (props) => {
timeUnit: timeUnit ?? defaultExpression.timeUnit,
});
setAlertParams('criteria', exp);
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [setAlertParams, alertParams.criteria, timeSize, timeUnit]);

const removeExpression = useCallback(
Expand All @@ -119,6 +121,7 @@ export const Expressions: React.FC<Props> = (props) => {
setAlertParams('criteria', exp);
}
},
/* eslint-disable-next-line react-hooks/exhaustive-deps */
[setAlertParams, alertParams.criteria]
);

Expand All @@ -133,6 +136,7 @@ export const Expressions: React.FC<Props> = (props) => {
[setAlertParams, derivedIndexPattern]
);

/* eslint-disable-next-line react-hooks/exhaustive-deps */
const debouncedOnFilterChange = useCallback(debounce(onFilterChange, FILTER_TYPING_DEBOUNCE_MS), [
onFilterChange,
]);
Expand Down Expand Up @@ -162,6 +166,7 @@ export const Expressions: React.FC<Props> = (props) => {
setTimeSize(ts || undefined);
setAlertParams('criteria', criteria);
},
/* eslint-disable-next-line react-hooks/exhaustive-deps */
[alertParams.criteria, setAlertParams]
);

Expand All @@ -175,6 +180,7 @@ export const Expressions: React.FC<Props> = (props) => {
setTimeUnit(tu as TimeUnit);
setAlertParams('criteria', criteria);
},
/* eslint-disable-next-line react-hooks/exhaustive-deps */
[alertParams.criteria, setAlertParams]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const ExpressionChart: React.FC<Props> = ({
: (value: number) => `${value}`;
}, [data]);

/* eslint-disable-next-line react-hooks/exhaustive-deps */
const yAxisFormater = useCallback(createFormatterForMetric(metric), [expression]);

if (loading || !data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const InventoryAlertDropdown = () => {
<FormattedMessage id="xpack.infra.alerting.manageAlerts" defaultMessage="Manage alerts" />
</EuiContextMenuItem>,
];
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [kibana.services]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export const Expressions: React.FC<Props> = (props) => {
timeUnit: timeUnit ?? defaultExpression.timeUnit,
});
setAlertParams('criteria', exp);
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [setAlertParams, alertParams.criteria, timeSize, timeUnit]);

const removeExpression = useCallback(
Expand All @@ -141,6 +142,7 @@ export const Expressions: React.FC<Props> = (props) => {
[derivedIndexPattern, setAlertParams]
);

/* eslint-disable-next-line react-hooks/exhaustive-deps */
const debouncedOnFilterChange = useCallback(debounce(onFilterChange, FILTER_TYPING_DEBOUNCE_MS), [
onFilterChange,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export const Editor: React.FC<Props> = (props) => {
} else {
return [];
}
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [sourceStatus]);

const updateCount = useCallback(
Expand Down Expand Up @@ -176,6 +177,7 @@ export const Editor: React.FC<Props> = (props) => {
? [...alertParams.criteria, DEFAULT_CRITERIA]
: [DEFAULT_CRITERIA];
setAlertParams('criteria', nextCriteria);
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [alertParams, setAlertParams]);

const removeCriterion = useCallback(
Expand All @@ -185,6 +187,7 @@ export const Editor: React.FC<Props> = (props) => {
});
setAlertParams('criteria', nextCriteria);
},
/* eslint-disable-next-line react-hooks/exhaustive-deps */
[alertParams, setAlertParams]
);

Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/infra/public/components/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ export const Header = ({ breadcrumbs = [], readOnlyBadge = false }: HeaderProps)

const setBreadcrumbs = useCallback(() => {
return chrome?.setBreadcrumbs(breadcrumbs || []);
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [breadcrumbs, chrome]);

const setBadge = useCallback(() => {
return chrome?.setBadge(badge);
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [badge, chrome]);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ const useFetchEntriesEffect = (
}
};

/* eslint-disable-next-line react-hooks/exhaustive-deps */
const fetchNewerEntries = useCallback(
throttle(() => runFetchMoreEntriesRequest(ShouldFetchMoreEntries.After), 500),
[props, state.bottomCursor]
Expand Down Expand Up @@ -330,10 +331,12 @@ const useFetchEntriesEffect = (
props.timestampsLastUpdate,
];

/* eslint-disable react-hooks/exhaustive-deps */
useEffect(fetchNewEntriesEffect, fetchNewEntriesEffectDependencies);
useEffect(fetchMoreEntriesEffect, fetchMoreEntriesEffectDependencies);
useEffect(streamEntriesEffect, streamEntriesEffectDependencies);
useEffect(expandRangeEffect, expandRangeEffectDependencies);
/* eslint-enable react-hooks/exhaustive-deps */

return { fetchNewerEntries, checkForNewEntries: runFetchNewEntriesRequest };
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const useLogFilterState: (props: {
}

return true;
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [filterQueryDraft]);

const serializedFilterQuery = useMemo(() => (filterQuery ? filterQuery.serializedQuery : null), [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const useLogSource = ({
[sourceId, fetch]
);

/* eslint-disable-next-line react-hooks/exhaustive-deps */
const logIndicesExist = useMemo(() => (sourceStatus?.logIndexNames?.length ?? 0) > 0, [
sourceStatus,
]);
Expand All @@ -87,6 +88,7 @@ export const useLogSource = ({
fields: sourceStatus?.logIndexFields ?? [],
title: sourceConfiguration?.configuration.name ?? 'unknown',
}),
/* eslint-disable-next-line react-hooks/exhaustive-deps */
[sourceConfiguration, sourceStatus]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const useSourceViaHttp = ({
title: pickIndexPattern(response?.source, indexType),
};
},
/* eslint-disable-next-line react-hooks/exhaustive-deps */
[response, type]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const useBulkGetSavedObject = (type: string) => {
};
fetchData();
},
/* eslint-disable-next-line react-hooks/exhaustive-deps */
[type, kibana.services.savedObjects]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const useCreateSavedObject = (type: string) => {
};
save();
},
/* eslint-disable-next-line react-hooks/exhaustive-deps */
[type, kibana.services.savedObjects]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const useDeleteSavedObject = (type: string) => {
};
dobj();
},
/* eslint-disable-next-line react-hooks/exhaustive-deps */
[type, kibana.services.savedObjects]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const useFindSavedObject = <SavedObjectType extends SavedObjectAttributes
};
fetchData();
},
/* eslint-disable-next-line react-hooks/exhaustive-deps */
[type, kibana.services.savedObjects]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const LogEntryCategoriesResultsContent: React.FunctionComponent = () => {
title: loadDataErrorTitle,
});
},
/* eslint-disable-next-line react-hooks/exhaustive-deps */
[services.notifications]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export const LogEntryRateResultsContent: React.FunctionComponent = () => {
[setAutoRefresh]
);

/* eslint-disable-next-line react-hooks/exhaustive-deps */
const hasResults = useMemo(() => (logEntryRate?.histogramBuckets?.length ?? 0) > 0, [
logEntryRate,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const AnomaliesTableExpandedRow: React.FunctionComponent<{
const logEntryRateSeries = useMemo(
() =>
results?.histogramBuckets ? getLogEntryRateSeriesForPartition(results, partitionId) : [],
/* eslint-disable-next-line react-hooks/exhaustive-deps */
[results, partitionId]
);
const anomalyAnnotations = useMemo(
Expand All @@ -41,13 +42,15 @@ export const AnomaliesTableExpandedRow: React.FunctionComponent<{
major: [],
critical: [],
},
/* eslint-disable-next-line react-hooks/exhaustive-deps */
[results, partitionId]
);
const totalNumberOfLogEntries = useMemo(
() =>
results?.histogramBuckets
? getTotalNumberOfLogEntriesForPartition(results, partitionId)
: undefined,
/* eslint-disable-next-line react-hooks/exhaustive-deps */
[results, partitionId]
);
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const LogsSettingsPage = () => {

const availableFields = useMemo(
() => sourceStatus?.logIndexFields.map((field) => field.name) ?? [],
/* eslint-disable-next-line react-hooks/exhaustive-deps */
[sourceStatus]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const MODAL_MARGIN = 25;
export const PageViewLogInContext: React.FC = () => {
const { sourceConfiguration } = useLogSourceContext();
const { textScale, textWrap } = useContext(LogViewConfiguration.Context);
/* eslint-disable-next-line react-hooks/exhaustive-deps */
const columnConfigurations = useMemo(() => sourceConfiguration?.configuration.logColumns ?? [], [
sourceConfiguration,
]);
Expand Down
Loading