From 7d535a85d88c2041d713b598056a4ad4089ca4c2 Mon Sep 17 00:00:00 2001 From: Gildas Garcia Date: Sun, 9 Jun 2019 12:42:59 +0200 Subject: [PATCH] Fix remaining warnings --- examples/data-generator/src/commands.js | 2 +- examples/data-generator/src/finalize.js | 4 ++-- examples/data-generator/src/invoices.js | 6 +----- .../src/actions/dataActions/crudUpdateMany.ts | 2 +- .../ra-core/src/controller/CreateController.tsx | 2 +- packages/ra-core/src/controller/EditController.tsx | 4 ++-- .../field/ReferenceFieldController.spec.tsx | 2 +- .../field/ReferenceManyFieldController.spec.tsx | 1 - .../ra-core/src/controller/field/useReference.ts | 2 +- .../src/controller/field/useReferenceArray.ts | 8 ++++---- packages/ra-core/src/controller/useListParams.ts | 14 +++++++------- .../ra-core/src/controller/useRecordSelection.ts | 6 +++--- packages/ra-core/src/controller/useSortState.ts | 2 +- packages/ra-core/src/fetch/useDataProvider.ts | 3 +-- packages/ra-core/src/fetch/useMutation.ts | 3 ++- packages/ra-core/src/fetch/useQuery.ts | 3 ++- .../src/reducer/admin/references/oneToMany.ts | 4 ++-- packages/ra-core/src/reducer/admin/ui.ts | 1 - packages/ra-data-graphcool/src/buildVariables.js | 6 +++--- .../ra-data-graphql-simple/src/buildVariables.js | 10 +++------- packages/ra-data-graphql/src/introspection.js | 3 ++- packages/ra-input-rich-text/src/index.js | 6 ++++-- packages/ra-input-rich-text/src/index.spec.js | 8 +------- packages/ra-ui-materialui/src/auth/Logout.tsx | 1 + .../src/input/AutocompleteArrayInput.js | 9 ++------- .../src/input/AutocompleteInput.js | 9 ++------- 26 files changed, 50 insertions(+), 71 deletions(-) diff --git a/examples/data-generator/src/commands.js b/examples/data-generator/src/commands.js index 55ce415bdb7..4c774ecccd2 100644 --- a/examples/data-generator/src/commands.js +++ b/examples/data-generator/src/commands.js @@ -58,7 +58,7 @@ export default (db, { serializeDate }) => { (total_ex_taxes + delivery_fees + taxes).toFixed(2) ), status: status, - returned: status == 'delivered' ? weightedBoolean(10) : false, + returned: status === 'delivered' ? weightedBoolean(10) : false, }; }); }; diff --git a/examples/data-generator/src/finalize.js b/examples/data-generator/src/finalize.js index 85a6bae154a..a541ca14e9c 100644 --- a/examples/data-generator/src/finalize.js +++ b/examples/data-generator/src/finalize.js @@ -22,7 +22,7 @@ export default function(db) { customers[command.customer_id].nbProducts += command.basket.length; return customers; }, {}); - Object.keys(customersBySpending).map(customer_id => { + Object.keys(customersBySpending).forEach(customer_id => { if (customersBySpending[customer_id].nbProducts > 10) { db.customers[customer_id].groups.push('collector'); } @@ -30,7 +30,7 @@ export default function(db) { // add 'ordered_once' group db.customers - .filter(customer => customer.nb_commands == 1) + .filter(customer => customer.nb_commands === 1) .forEach(customer => customer.groups.push('ordered_once')); // add 'compulsive' group diff --git a/examples/data-generator/src/invoices.js b/examples/data-generator/src/invoices.js index 04d1f7efe91..99c5a5e1a41 100644 --- a/examples/data-generator/src/invoices.js +++ b/examples/data-generator/src/invoices.js @@ -1,8 +1,4 @@ -import { random, lorem } from 'faker/locale/en'; -import subDays from 'date-fns/sub_days'; -import { randomDate } from './utils'; - -export default (db, { serializeDate }) => { +export default db => { let id = 0; return db.commands diff --git a/packages/ra-core/src/actions/dataActions/crudUpdateMany.ts b/packages/ra-core/src/actions/dataActions/crudUpdateMany.ts index fd474990895..9e63c220415 100644 --- a/packages/ra-core/src/actions/dataActions/crudUpdateMany.ts +++ b/packages/ra-core/src/actions/dataActions/crudUpdateMany.ts @@ -1,4 +1,4 @@ -import { Identifier, Record } from '../../types'; +import { Identifier } from '../../types'; import { UPDATE_MANY } from '../../dataFetchActions'; import { FETCH_END, FETCH_ERROR } from '../fetchActions'; import { NotificationSideEffect, RefreshSideEffect } from '../../sideEffect'; diff --git a/packages/ra-core/src/controller/CreateController.tsx b/packages/ra-core/src/controller/CreateController.tsx index ccfd864a7c7..51cc59d58d6 100644 --- a/packages/ra-core/src/controller/CreateController.tsx +++ b/packages/ra-core/src/controller/CreateController.tsx @@ -104,7 +104,7 @@ const CreateController = (props: Props) => { (data: Partial, redirect: RedirectionSideEffect) => { dispatch(crudCreate(resource, data, basePath, redirect)); }, - [resource, basePath] + [resource, basePath] // eslint-disable-line react-hooks/exhaustive-deps ); if (!children) { diff --git a/packages/ra-core/src/controller/EditController.tsx b/packages/ra-core/src/controller/EditController.tsx index d5d666a1c56..b91e2c5c3c9 100644 --- a/packages/ra-core/src/controller/EditController.tsx +++ b/packages/ra-core/src/controller/EditController.tsx @@ -101,7 +101,7 @@ const EditController = (props: Props) => { useEffect(() => { dispatch(resetForm(REDUX_FORM_NAME)); - }, [resource, id, version]); + }, [resource, id, version]); // eslint-disable-line react-hooks/exhaustive-deps const resourceName = translate(`resources.${resource}.name`, { smart_count: 1, @@ -130,7 +130,7 @@ const EditController = (props: Props) => { dispatch(updateAction); } }, - [resource, id, record, basePath, undoable] + [resource, id, record, basePath, undoable] // eslint-disable-line react-hooks/exhaustive-deps ); if (!children) { diff --git a/packages/ra-core/src/controller/field/ReferenceFieldController.spec.tsx b/packages/ra-core/src/controller/field/ReferenceFieldController.spec.tsx index 7a3acc8caad..86e354688ec 100644 --- a/packages/ra-core/src/controller/field/ReferenceFieldController.spec.tsx +++ b/packages/ra-core/src/controller/field/ReferenceFieldController.spec.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { render, cleanup } from 'react-testing-library'; +import { cleanup } from 'react-testing-library'; import ReferenceFieldController from './ReferenceFieldController'; import renderWithRedux from '../../util/renderWithRedux'; diff --git a/packages/ra-core/src/controller/field/ReferenceManyFieldController.spec.tsx b/packages/ra-core/src/controller/field/ReferenceManyFieldController.spec.tsx index cc401f4839a..1f22d0fa9dc 100644 --- a/packages/ra-core/src/controller/field/ReferenceManyFieldController.spec.tsx +++ b/packages/ra-core/src/controller/field/ReferenceManyFieldController.spec.tsx @@ -1,6 +1,5 @@ import React from 'react'; import assert from 'assert'; -import { render } from 'react-testing-library'; import ReferenceManyFieldController from './ReferenceManyFieldController'; import renderWithRedux from '../../util/renderWithRedux'; diff --git a/packages/ra-core/src/controller/field/useReference.ts b/packages/ra-core/src/controller/field/useReference.ts index baa3b3329f5..974714de7c3 100644 --- a/packages/ra-core/src/controller/field/useReference.ts +++ b/packages/ra-core/src/controller/field/useReference.ts @@ -76,7 +76,7 @@ export const useReference = ({ if (sourceId !== null && typeof sourceId !== 'undefined') { dispatch(crudGetManyAccumulate(reference, [sourceId])); } - }, [sourceId, reference]); + }, [sourceId, reference]); // eslint-disable-line react-hooks/exhaustive-deps const rootPath = basePath.replace(resource, reference); const resourceLinkPath = !linkType ? false diff --git a/packages/ra-core/src/controller/field/useReferenceArray.ts b/packages/ra-core/src/controller/field/useReferenceArray.ts index 4065939b78e..8f803b5972d 100644 --- a/packages/ra-core/src/controller/field/useReferenceArray.ts +++ b/packages/ra-core/src/controller/field/useReferenceArray.ts @@ -1,11 +1,11 @@ -import { FunctionComponent, ReactNode, useEffect, ReactElement } from 'react'; +import { useEffect } from 'react'; // @ts-ignore import { useDispatch, useSelector } from 'react-redux'; import get from 'lodash/get'; import { crudGetManyAccumulate } from '../../actions'; import { getReferencesByIds } from '../../reducer/admin/references/oneToMany'; -import { ReduxState, Record, RecordMap, Sort, Identifier } from '../../types'; +import { ReduxState, Record, RecordMap, Identifier } from '../../types'; interface ReferenceArrayProps { loadedOnce: boolean; @@ -70,12 +70,12 @@ const useReferenceArray = ({ ); useEffect(() => { dispatch(crudGetManyAccumulate(reference, ids)); - }, [reference, ids, record.id]); + }, [reference, ids, record.id]); // eslint-disable-line react-hooks/exhaustive-deps const referenceBasePath = basePath.replace(resource, reference); // FIXME obviously very weak return { - // tslint:disable-next-line:triple-equals + // eslint-disable-next-line eqeqeq loadedOnce: data != undefined, ids, data, diff --git a/packages/ra-core/src/controller/useListParams.ts b/packages/ra-core/src/controller/useListParams.ts index 205e7d6f8bc..b7b3ec9c5af 100644 --- a/packages/ra-core/src/controller/useListParams.ts +++ b/packages/ra-core/src/controller/useListParams.ts @@ -137,7 +137,7 @@ const useListParams = ({ sort, perPage, }), - requestSignature + requestSignature // eslint-disable-line react-hooks/exhaustive-deps ); const changeParams = useCallback(action => { @@ -151,21 +151,21 @@ const useListParams = ({ }) ); dispatch(changeListParams(resource, newParams)); - }, requestSignature); + }, requestSignature); // eslint-disable-line react-hooks/exhaustive-deps const setSort = useCallback( newSort => changeParams({ type: SET_SORT, payload: { sort: newSort } }), - requestSignature + requestSignature // eslint-disable-line react-hooks/exhaustive-deps ); const setPage = useCallback( newPage => changeParams({ type: SET_PAGE, payload: newPage }), - requestSignature + requestSignature // eslint-disable-line react-hooks/exhaustive-deps ); const setPerPage = useCallback( newPerPage => changeParams({ type: SET_PER_PAGE, payload: newPerPage }), - requestSignature + requestSignature // eslint-disable-line react-hooks/exhaustive-deps ); const filterValues = query.filter || emptyObject; @@ -190,7 +190,7 @@ const useListParams = ({ setDisplayedFilters({ [filterName]: false }); const newFilters = removeKey(filterValues, filterName); setFilters(newFilters); - }, requestSignature); + }, requestSignature); // eslint-disable-line react-hooks/exhaustive-deps const showFilter = useCallback((filterName: string, defaultValue: any) => { setDisplayedFilters({ [filterName]: true }); @@ -200,7 +200,7 @@ const useListParams = ({ [filterName]: defaultValue, }); } - }, requestSignature); + }, requestSignature); // eslint-disable-line react-hooks/exhaustive-deps return [ { diff --git a/packages/ra-core/src/controller/useRecordSelection.ts b/packages/ra-core/src/controller/useRecordSelection.ts index 5e4504633e2..7036b268e16 100644 --- a/packages/ra-core/src/controller/useRecordSelection.ts +++ b/packages/ra-core/src/controller/useRecordSelection.ts @@ -23,17 +23,17 @@ const useSelectItems = (resource: string) => { (newIds: Identifier[]) => { dispatch(setListSelectedIds(resource, newIds)); }, - [resource] + [resource] // eslint-disable-line react-hooks/exhaustive-deps ), toggle: useCallback( (id: Identifier) => { dispatch(toggleListItem(resource, id)); }, - [resource] + [resource] // eslint-disable-line react-hooks/exhaustive-deps ), clearSelection: useCallback(() => { dispatch(setListSelectedIds(resource, [])); - }, [resource]), + }, [resource]), // eslint-disable-line react-hooks/exhaustive-deps }; return [selectedIds, selectionModifiers]; }; diff --git a/packages/ra-core/src/controller/useSortState.ts b/packages/ra-core/src/controller/useSortState.ts index 54a90e14549..c1b59363521 100644 --- a/packages/ra-core/src/controller/useSortState.ts +++ b/packages/ra-core/src/controller/useSortState.ts @@ -61,7 +61,7 @@ export default ( return; } dispatch(initialSort); - }, [initialSort.field, initialSort.order]); + }, [initialSort.field, initialSort.order]); // eslint-disable-line react-hooks/exhaustive-deps return { setSort: (field: string) => dispatch(field), diff --git a/packages/ra-core/src/fetch/useDataProvider.ts b/packages/ra-core/src/fetch/useDataProvider.ts index b7552d2c3cc..821f9280fbd 100644 --- a/packages/ra-core/src/fetch/useDataProvider.ts +++ b/packages/ra-core/src/fetch/useDataProvider.ts @@ -105,8 +105,7 @@ const useDataProvider = () => { : dispatch(queryAction); }); }, - - [] + [] // eslint-disable-line react-hooks/exhaustive-deps ); }; diff --git a/packages/ra-core/src/fetch/useMutation.ts b/packages/ra-core/src/fetch/useMutation.ts index 905e727db82..2d3e199bafa 100644 --- a/packages/ra-core/src/fetch/useMutation.ts +++ b/packages/ra-core/src/fetch/useMutation.ts @@ -90,7 +90,8 @@ const useMutation = ( loaded: false, }); }); - }, [JSON.stringify({ query, options })]); // deep equality, see https://github.com/facebook/react/issues/14476#issuecomment-471199055 + // deep equality, see https://github.com/facebook/react/issues/14476#issuecomment-471199055 + }, [JSON.stringify({ query, options })]); // eslint-disable-line react-hooks/exhaustive-deps return [mutate, state]; }; diff --git a/packages/ra-core/src/fetch/useQuery.ts b/packages/ra-core/src/fetch/useQuery.ts index fd0114e2cbe..5357a2b1858 100644 --- a/packages/ra-core/src/fetch/useQuery.ts +++ b/packages/ra-core/src/fetch/useQuery.ts @@ -111,7 +111,8 @@ const useQuery = ( loaded: false, }); }); - }, [JSON.stringify({ query, options })]); // deep equality, see https://github.com/facebook/react/issues/14476#issuecomment-471199055 + // deep equality, see https://github.com/facebook/react/issues/14476#issuecomment-471199055 + }, [JSON.stringify({ query, options })]); // eslint-disable-line react-hooks/exhaustive-deps return state; }; diff --git a/packages/ra-core/src/reducer/admin/references/oneToMany.ts b/packages/ra-core/src/reducer/admin/references/oneToMany.ts index 16044f8b95f..2998135ff14 100644 --- a/packages/ra-core/src/reducer/admin/references/oneToMany.ts +++ b/packages/ra-core/src/reducer/admin/references/oneToMany.ts @@ -87,7 +87,7 @@ export const getReferences = (state: ReduxState, reference, relatedTo) => { const resource = state.admin.resources[reference]; if (!resource) { - return; + return undefined; } return resource.data[id]; @@ -124,7 +124,7 @@ export const getReferencesByIds = ( const resource = state.admin.resources[reference]; if (!resource) { - return; + return undefined; } return resource.data[id]; diff --git a/packages/ra-core/src/reducer/admin/ui.ts b/packages/ra-core/src/reducer/admin/ui.ts index 9dd75386584..fef2b996233 100644 --- a/packages/ra-core/src/reducer/admin/ui.ts +++ b/packages/ra-core/src/reducer/admin/ui.ts @@ -11,7 +11,6 @@ import { STOP_OPTIMISTIC_MODE, StopOptimisticModeAction, } from '../../actions'; -import { number } from '../../form'; type ActionTypes = | ToggleSidebarAction diff --git a/packages/ra-data-graphcool/src/buildVariables.js b/packages/ra-data-graphcool/src/buildVariables.js index f33f90c96a8..634fb2f9f18 100644 --- a/packages/ra-data-graphcool/src/buildVariables.js +++ b/packages/ra-data-graphcool/src/buildVariables.js @@ -41,7 +41,7 @@ const buildGetListVariables = introspectionResults => ( const parts = key.split('.'); if (parts.length > 1) { - if (parts[1] == 'id') { + if (parts[1] === 'id') { const type = introspectionResults.types.find( t => t.name === `${resource.type.name}Filter` ); @@ -157,7 +157,6 @@ export default introspectionResults => ( queryType ); } - case CREATE: { return buildCreateUpdateVariables(introspectionResults)( resource, @@ -166,10 +165,11 @@ export default introspectionResults => ( queryType ); } - case DELETE: return { id: params.id, }; + default: + console.log('Unknown fetch verb'); } }; diff --git a/packages/ra-data-graphql-simple/src/buildVariables.js b/packages/ra-data-graphql-simple/src/buildVariables.js index d91f76f7592..e04a3034ffd 100644 --- a/packages/ra-data-graphql-simple/src/buildVariables.js +++ b/packages/ra-data-graphql-simple/src/buildVariables.js @@ -127,7 +127,7 @@ const buildGetListVariables = introspectionResults => ( const parts = key.split('.'); if (parts.length > 1) { - if (parts[1] == 'id') { + if (parts[1] === 'id') { const type = introspectionResults.types.find( t => t.name === `${resource.type.name}Filter` ); @@ -240,24 +240,20 @@ export default introspectionResults => ( queryType ); } - case GET_MANY: return { filter: { ids: preparedParams.ids }, }; - case GET_MANY_REFERENCE: { const parts = preparedParams.target.split('.'); return { filter: { [`${parts[0]}Id`]: preparedParams.id }, }; } - case GET_ONE: return { id: preparedParams.id, }; - case UPDATE: { return buildCreateUpdateVariables(introspectionResults)( resource, @@ -266,7 +262,6 @@ export default introspectionResults => ( queryType ); } - case CREATE: { return buildCreateUpdateVariables(introspectionResults)( resource, @@ -275,10 +270,11 @@ export default introspectionResults => ( queryType ); } - case DELETE: return { id: preparedParams.id, }; + default: + console.log('Unknown fetch verb'); } }; diff --git a/packages/ra-data-graphql/src/introspection.js b/packages/ra-data-graphql/src/introspection.js index 5e2a79136dd..1f1acd1d03f 100644 --- a/packages/ra-data-graphql/src/introspection.js +++ b/packages/ra-data-graphql/src/introspection.js @@ -71,7 +71,8 @@ export default async (client, options) => { [aorFetchType]: queries.find( query => options.operationNames[aorFetchType] && - query.name == options.operationNames[aorFetchType](type) + query.name === + options.operationNames[aorFetchType](type) ), }), { type } diff --git a/packages/ra-input-rich-text/src/index.js b/packages/ra-input-rich-text/src/index.js index ddc92f3eb72..6974aeab931 100644 --- a/packages/ra-input-rich-text/src/index.js +++ b/packages/ra-input-rich-text/src/index.js @@ -81,7 +81,9 @@ export class RichTextInput extends Component { onTextChange = () => { const value = - this.editor.innerHTML == '


' ? '' : this.editor.innerHTML; + this.editor.innerHTML === '


' + ? '' + : this.editor.innerHTML; this.lastValueChange = value; this.props.input.onChange(value); }; @@ -94,7 +96,7 @@ export class RichTextInput extends Component { const { error, helperText = false } = this.props.meta; return ( diff --git a/packages/ra-input-rich-text/src/index.spec.js b/packages/ra-input-rich-text/src/index.spec.js index a5f61ee46cf..d3f0971d5e7 100644 --- a/packages/ra-input-rich-text/src/index.spec.js +++ b/packages/ra-input-rich-text/src/index.spec.js @@ -1,12 +1,6 @@ import React from 'react'; import debounce from 'lodash/debounce'; -import { - render, - fireEvent, - waitForElement, - cleanup, - getByTestId, -} from 'react-testing-library'; +import { render, fireEvent, waitForElement } from 'react-testing-library'; import { RichTextInput } from './index'; diff --git a/packages/ra-ui-materialui/src/auth/Logout.tsx b/packages/ra-ui-materialui/src/auth/Logout.tsx index 3ebc9842075..89b94ec1214 100644 --- a/packages/ra-ui-materialui/src/auth/Logout.tsx +++ b/packages/ra-ui-materialui/src/auth/Logout.tsx @@ -38,6 +38,7 @@ const LogoutWithRef: FunctionComponent< const classes = useStyles(); const translate = useTranslate(); const dispatch = useDispatch(); + // eslint-disable-next-line react-hooks/exhaustive-deps const logout = useCallback(() => dispatch(userLogout(redirectTo)), [ redirectTo, ]); diff --git a/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.js b/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.js index ad5fd552de6..06eab57ebfc 100644 --- a/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.js +++ b/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.js @@ -214,13 +214,8 @@ export class AutocompleteArrayInput extends React.Component { this.updateFilter(inputValue); }; handleChange = (event, { newValue, method }) => { - switch (method) { - case 'type': - case 'escape': - this.handleMatchSuggestionOrFilter(newValue); - break; - default: - break; + if (['type', 'escape'].includes(method)) { + this.handleMatchSuggestionOrFilter(newValue); } }; diff --git a/packages/ra-ui-materialui/src/input/AutocompleteInput.js b/packages/ra-ui-materialui/src/input/AutocompleteInput.js index a3312e84b2f..bcf1b85031d 100644 --- a/packages/ra-ui-materialui/src/input/AutocompleteInput.js +++ b/packages/ra-ui-materialui/src/input/AutocompleteInput.js @@ -226,13 +226,8 @@ export class AutocompleteInput extends React.Component { }; handleChange = (event, { newValue, method }) => { - switch (method) { - case 'type': - case 'escape': - this.handleMatchSuggestionOrFilter(newValue); - break; - default: - break; + if (['type', 'escape'].includes(method)) { + this.handleMatchSuggestionOrFilter(newValue); } };