diff --git a/.eslintrc.js b/.eslintrc.js index a152caf0..b5f0f28c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2,16 +2,17 @@ module.exports = { extends: ['algolia', 'algolia/react'], rules: { 'eslint-comments/disable-enable-pair': 0, - // Do not enforce a specific import order - 'import/order': 0, - // Allow function components - 'react/function-component-definition': 0, + // Enforce function declaration for components + 'react/function-component-definition': [ + 'error', + { + 'named-components': 'function-declaration', + }, + ], // Allow boolean props without explicit values 'react/jsx-boolean-value': 0, // Allow JSX content in .js files 'react/jsx-filename-extension': 0, - // Do not enforce event listeners naming conventions - 'react/jsx-handler-names': 0, // Allow passing function references to event listeners 'react/jsx-no-bind': 0, // Avoid errors about `UNSAFE` lifecycles (e.g. `UNSAFE_componentWillMount`) diff --git a/src/App.js b/src/App.js index 18d3be29..291574ea 100644 --- a/src/App.js +++ b/src/App.js @@ -2,9 +2,9 @@ import React, { createPortal } from 'preact/compat'; import { connectHitInsights } from 'react-instantsearch-dom'; import { useNavigate, useLocation } from 'react-router-dom'; -import { getUrlFromState, getStateFromUrl, createURL } from './router'; -import { useSearchClient, useInsights, useMatchMedia } from './hooks'; import { SearchButton, Search } from './components'; +import { useSearchClient, useInsights, useMatchMedia } from './hooks'; +import { getUrlFromState, getStateFromUrl, createURL } from './router'; export const AppContext = React.createContext(null); export const SearchContext = React.createContext(null); diff --git a/src/components/Banner.js b/src/components/Banner.js index 88464de9..dee8bdc0 100644 --- a/src/components/Banner.js +++ b/src/components/Banner.js @@ -3,7 +3,7 @@ import { QueryRuleCustomData } from 'react-instantsearch-dom'; import './Banner.scss'; -export const Banner = () => { +export function Banner() { return ( {({ items }) => { @@ -23,4 +23,4 @@ export const Banner = () => { }} ); -}; +} diff --git a/src/components/ColorList.js b/src/components/ColorList.js index d57a532b..c4ca862f 100644 --- a/src/components/ColorList.js +++ b/src/components/ColorList.js @@ -2,8 +2,8 @@ import React from 'preact/compat'; import { connectRefinementList } from 'react-instantsearch-dom'; import './ColorList.scss'; -import { FacetSearchBox } from './SearchBox/FacetSearchBox'; import { PartialHighlight } from './PartialHighlight'; +import { FacetSearchBox } from './SearchBox/FacetSearchBox'; export const ColorList = connectRefinementList(function ColorList(props) { const [query, setQuery] = React.useState(''); diff --git a/src/components/FiltersButton.js b/src/components/FiltersButton.js index a37c3004..cd61c52f 100644 --- a/src/components/FiltersButton.js +++ b/src/components/FiltersButton.js @@ -1,8 +1,9 @@ import React from 'preact/compat'; -import { FilterIcon } from './FilterIcon'; import { useSearchContext } from '../hooks'; +import { FilterIcon } from './FilterIcon'; + export function FiltersButton({ onClick }) { const { refinementCount } = useSearchContext(); diff --git a/src/components/Hits.js b/src/components/Hits.js index 29c34370..1e5505a6 100644 --- a/src/components/Hits.js +++ b/src/components/Hits.js @@ -2,6 +2,7 @@ import React from 'preact/compat'; import { connectHits } from 'react-instantsearch-dom'; import { useAppContext } from '../hooks'; + import { Pagination } from './Pagination'; export const Hits = connectHits((props) => { diff --git a/src/components/InfiniteHits.js b/src/components/InfiniteHits.js index 49cb02c6..1af5bebc 100644 --- a/src/components/InfiniteHits.js +++ b/src/components/InfiniteHits.js @@ -16,7 +16,7 @@ export const InfiniteHits = connectInfiniteHits((props) => { diff --git a/src/components/NoResultsHandler.js b/src/components/NoResultsHandler.js index f9802394..370ea108 100644 --- a/src/components/NoResultsHandler.js +++ b/src/components/NoResultsHandler.js @@ -7,11 +7,11 @@ import { connectHits, } from 'react-instantsearch-dom'; -import { useAppContext, useSearchContext } from '../hooks'; import { NO_RESULTS_INDEX_NAME, QUERY_SUGGESTIONS_INDEX_NAME, } from '../constants'; +import { useAppContext, useSearchContext } from '../hooks'; export const NoResultsHandler = connectStateResults(function ResultsWrapper( props diff --git a/src/components/ProductList.js b/src/components/ProductList.js index a7f3e324..5ab5b922 100644 --- a/src/components/ProductList.js +++ b/src/components/ProductList.js @@ -1,11 +1,11 @@ import React from 'preact/compat'; +import { useAppContext } from '../hooks'; + import { Hits } from './Hits'; import { InfiniteHits } from './InfiniteHits'; -import { useAppContext } from '../hooks'; - -export const ProductList = (props) => { +export function ProductList(props) { const { isMobile } = useAppContext(); if (isMobile) { @@ -13,4 +13,4 @@ export const ProductList = (props) => { } return ; -}; +} diff --git a/src/components/QueryRulesHandler.js b/src/components/QueryRulesHandler.js index 4a8c07eb..e2422c20 100644 --- a/src/components/QueryRulesHandler.js +++ b/src/components/QueryRulesHandler.js @@ -21,7 +21,7 @@ const getRulesContextFromSearchState = ({ refinementList = {}, menu = {} }) => { }, {}); }; -export const QueryRulesHandler = (props) => { +export function QueryRulesHandler(props) { const ruleContexts = getRulesContextFromSearchState(props.searchState); if (Object.keys(ruleContexts).length === 0) { @@ -29,4 +29,4 @@ export const QueryRulesHandler = (props) => { } return ; -}; +} diff --git a/src/components/Refinements.js b/src/components/Refinements.js index 51a577f4..5cdcd9ae 100644 --- a/src/components/Refinements.js +++ b/src/components/Refinements.js @@ -6,10 +6,11 @@ import { } from 'react-instantsearch-dom'; import { useAppContext } from '../hooks'; -import { Panel } from './Panel'; + import { ColorList } from './ColorList'; -import { Slider } from './Slider'; +import { Panel } from './Panel'; import { SizeList } from './SizeList'; +import { Slider } from './Slider'; function RefinementWidget({ type, ...props }) { switch (type) { diff --git a/src/components/Search.js b/src/components/Search.js index 323dfa4f..ac562204 100644 --- a/src/components/Search.js +++ b/src/components/Search.js @@ -2,19 +2,20 @@ import React from 'preact/compat'; import { InstantSearch, Configure, SortBy } from 'react-instantsearch-dom'; import { useAppContext, useSearchContext } from '../hooks'; + import { Banner } from './Banner'; +import { CloseIcon } from './CloseIcon'; import { CurrentRefinements } from './CurrentRefinements'; +import { FiltersButton } from './FiltersButton'; +import { NoResultsHandler } from './NoResultsHandler'; +import { ProductList } from './ProductList'; import { QueryRulesHandler } from './QueryRulesHandler'; import { Refinements } from './Refinements'; +import { ResetButton } from './ResetButton'; import { HeaderSearchBox } from './SearchBox'; +import { SeeResultsButton } from './SeeResultsButton'; import { Stats } from './Stats'; -import { CloseIcon } from './CloseIcon'; -import { NoResultsHandler } from './NoResultsHandler'; -import { ProductList } from './ProductList'; import { Views } from './Views'; -import { FiltersButton } from './FiltersButton'; -import { SeeResultsButton } from './SeeResultsButton'; -import { ResetButton } from './ResetButton'; export function Search(props) { const { config, view, searchParameters, isMobile } = useAppContext(); diff --git a/src/components/SearchBox/ConnectedSearchBox.js b/src/components/SearchBox/ConnectedSearchBox.js index c0790e9c..90a91963 100644 --- a/src/components/SearchBox/ConnectedSearchBox.js +++ b/src/components/SearchBox/ConnectedSearchBox.js @@ -2,6 +2,7 @@ import React from 'preact/compat'; import { connectSearchBox } from 'react-instantsearch-dom'; import { useAppContext } from '../../hooks'; + import { PredictiveSearchBox } from './PredictiveSearchBox'; import { SearchBox as SearchBoxComponent } from './SearchBox'; diff --git a/src/components/SearchBox/FacetSearchBox.js b/src/components/SearchBox/FacetSearchBox.js index cbcba972..cc0b31db 100644 --- a/src/components/SearchBox/FacetSearchBox.js +++ b/src/components/SearchBox/FacetSearchBox.js @@ -1,6 +1,6 @@ import React from 'preact/compat'; -export const FacetSearchBox = (props) => { +export function FacetSearchBox(props) { return (
{
); -}; +} diff --git a/src/components/SearchBox/PredictiveSearchBox.js b/src/components/SearchBox/PredictiveSearchBox.js index 1783d84d..56389560 100644 --- a/src/components/SearchBox/PredictiveSearchBox.js +++ b/src/components/SearchBox/PredictiveSearchBox.js @@ -3,9 +3,10 @@ import { Index, connectHits, Configure } from 'react-instantsearch-dom'; import { QUERY_SUGGESTIONS_INDEX_NAME } from '../../constants'; import { ReverseHighlight } from '../ReverseHighlight'; + import { SearchBox } from './SearchBox'; -export const PredictiveSearchBox = (props) => { +export function PredictiveSearchBox(props) { const [suggestion, setSuggestion] = React.useState(null); return ( @@ -57,7 +58,7 @@ export const PredictiveSearchBox = (props) => { ); -}; +} const Suggestions = connectHits(function Suggestions({ query, diff --git a/src/components/SearchBox/SearchBox.js b/src/components/SearchBox/SearchBox.js index 52b94880..dd27ab9f 100644 --- a/src/components/SearchBox/SearchBox.js +++ b/src/components/SearchBox/SearchBox.js @@ -1,6 +1,6 @@ import React from 'preact/compat'; -export const SearchBox = (props) => { +export function SearchBox(props) { const inputRef = React.useRef(null); function onSubmit(event) { @@ -138,4 +138,4 @@ export const SearchBox = (props) => { ); -}; +} diff --git a/src/components/SizeList.js b/src/components/SizeList.js index f264af09..6069f23d 100644 --- a/src/components/SizeList.js +++ b/src/components/SizeList.js @@ -1,8 +1,8 @@ import React from 'preact/compat'; import { connectRefinementList } from 'react-instantsearch-dom'; -import { FacetSearchBox } from './SearchBox/FacetSearchBox'; import { PartialHighlight } from './PartialHighlight'; +import { FacetSearchBox } from './SearchBox/FacetSearchBox'; export const SizeList = connectRefinementList(function SizeList(props) { const [query, setQuery] = React.useState(''); diff --git a/src/config/settings.js b/src/config/settings.js index 808d2391..00793b42 100644 --- a/src/config/settings.js +++ b/src/config/settings.js @@ -14,6 +14,7 @@ */ import React from 'preact/compat'; + import { Hit } from './Hit'; /* diff --git a/src/hooks/useSearchClient.js b/src/hooks/useSearchClient.js index 1c17b472..3b99610f 100644 --- a/src/hooks/useSearchClient.js +++ b/src/hooks/useSearchClient.js @@ -1,11 +1,11 @@ -import React from 'preact/compat'; import algoliasearch from 'algoliasearch/lite'; +import React from 'preact/compat'; -import { version } from '../version'; import { NO_RESULTS_INDEX_NAME, QUERY_SUGGESTIONS_INDEX_NAME, } from '../constants'; +import { version } from '../version'; export function useSearchClient(config) { const appId = config.appId; diff --git a/src/index.js b/src/index.js index 37493a42..7993468d 100644 --- a/src/index.js +++ b/src/index.js @@ -5,9 +5,9 @@ import './reset.scss'; import './theme.scss'; import './App.scss'; +import { App } from './App'; import config from './config'; import rules from './config/rules'; -import { App } from './App'; import { getDomElement, validateConfig } from './utils'; validateConfig(config, rules);