Skip to content

Commit

Permalink
enforce function declaration for components
Browse files Browse the repository at this point in the history
  • Loading branch information
dhayab committed Mar 16, 2022
1 parent 46b43c5 commit 32a7892
Show file tree
Hide file tree
Showing 22 changed files with 54 additions and 47 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ module.exports = {
extends: ['algolia', 'algolia/react'],
rules: {
'eslint-comments/disable-enable-pair': 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
Expand Down
4 changes: 2 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getUrlFromState, getStateFromUrl, createURL } from './router';
export const AppContext = React.createContext(null);
export const SearchContext = React.createContext(null);

export const App = ({ config }) => {
export function App({ config }) {
const navigate = useNavigate();
const location = useLocation();
const searchClient = useSearchClient(config);
Expand Down Expand Up @@ -228,4 +228,4 @@ export const App = ({ config }) => {
)}
</AppContext.Provider>
);
};
}
4 changes: 2 additions & 2 deletions src/components/Banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { QueryRuleCustomData } from 'react-instantsearch-dom';

import './Banner.scss';

export const Banner = () => {
export function Banner() {
return (
<QueryRuleCustomData>
{({ items }) => {
Expand All @@ -23,4 +23,4 @@ export const Banner = () => {
}}
</QueryRuleCustomData>
);
};
}
4 changes: 2 additions & 2 deletions src/components/CloseIcon.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'preact/compat';

export const CloseIcon = (props) => {
export function CloseIcon(props) {
return (
<svg viewBox="0 0 31 32" width="31" height="32" {...props}>
<path
Expand All @@ -13,4 +13,4 @@ export const CloseIcon = (props) => {
/>
</svg>
);
};
}
4 changes: 2 additions & 2 deletions src/components/FilterIcon.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'preact/compat';

export const FilterIcon = (props) => {
export function FilterIcon(props) {
return (
<svg viewBox="0 0 16 14" {...props}>
<path
Expand All @@ -14,4 +14,4 @@ export const FilterIcon = (props) => {
></path>
</svg>
);
};
}
4 changes: 2 additions & 2 deletions src/components/FiltersButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useSearchContext } from '../hooks';

import { FilterIcon } from './FilterIcon';

export const FiltersButton = ({ onClick }) => {
export function FiltersButton({ onClick }) {
const { refinementCount } = useSearchContext();

return (
Expand All @@ -21,4 +21,4 @@ export const FiltersButton = ({ onClick }) => {
)}
</button>
);
};
}
4 changes: 2 additions & 2 deletions src/components/Icons/IconViewGrid.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'preact/compat';

export const IconViewGrid = (props) => {
export function IconViewGrid(props) {
return (
<svg width={16} height={16} viewBox="0 0 16 16" {...props}>
<path
Expand All @@ -10,4 +10,4 @@ export const IconViewGrid = (props) => {
/>
</svg>
);
};
}
4 changes: 2 additions & 2 deletions src/components/Icons/IconViewList.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'preact/compat';

export const IconViewList = (props) => {
export function IconViewList(props) {
return (
<svg width={16} height={16} viewBox="0 0 14 14" {...props}>
<path
Expand All @@ -10,4 +10,4 @@ export const IconViewList = (props) => {
/>
</svg>
);
};
}
4 changes: 2 additions & 2 deletions src/components/NoResultsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const HitsPreview = connectHits(function MoreHits(props) {
);
});

const QuerySuggestions = () => {
function QuerySuggestions() {
const { config, searchState, searchParameters } = useAppContext();

if (!config.suggestionsIndex) {
Expand All @@ -177,7 +177,7 @@ const QuerySuggestions = () => {
<QuerySuggestionsHits />
</Index>
);
};
}

const QuerySuggestionsHits = connectHits(function QuerySuggestionsHits(props) {
const { setQuery } = useSearchContext();
Expand Down
6 changes: 3 additions & 3 deletions src/components/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import React from 'preact/compat';

import './Panel.scss';

export const Panel = ({
export function Panel({
isOpened,
header,
footer,
onToggle,
children,
...rest
}) => {
}) {
return (
<div
className={[
Expand Down Expand Up @@ -53,4 +53,4 @@ export const Panel = ({
{footer && <div className="ais-Panel-footer">{footer}</div>}
</div>
);
};
}
6 changes: 3 additions & 3 deletions src/components/PartialHighlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React from 'preact/compat';

import { getAttributeValueByPath, parseAttribute } from '../utils';

export const PartialHighlight = ({
export function PartialHighlight({
hit,
attribute,
tagName = 'mark',
...rest
}) => {
}) {
let parts = [];

try {
Expand Down Expand Up @@ -43,7 +43,7 @@ export const PartialHighlight = ({
})}
</span>
);
};
}

function parsePartialHighlightedAttribute({
hit,
Expand Down
4 changes: 2 additions & 2 deletions src/components/ProductList.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { useAppContext } from '../hooks';
import { Hits } from './Hits';
import { InfiniteHits } from './InfiniteHits';

export const ProductList = (props) => {
export function ProductList(props) {
const { isMobile } = useAppContext();

if (isMobile) {
return <InfiniteHits {...props} />;
}

return <Hits {...props} />;
};
}
4 changes: 2 additions & 2 deletions src/components/QueryRulesHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ const getRulesContextFromSearchState = ({ refinementList = {}, menu = {} }) => {
}, {});
};

export const QueryRulesHandler = (props) => {
export function QueryRulesHandler(props) {
const ruleContexts = getRulesContextFromSearchState(props.searchState);

if (Object.keys(ruleContexts).length === 0) {
return null;
}

return <QueryRuleContext trackedFilters={ruleContexts} />;
};
}
4 changes: 2 additions & 2 deletions src/components/Refinements.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Panel } from './Panel';
import { SizeList } from './SizeList';
import { Slider } from './Slider';

const RefinementWidget = ({ type, ...props }) => {
function RefinementWidget({ type, ...props }) {
switch (type) {
case 'color':
return <ColorList {...props} />;
Expand Down Expand Up @@ -59,7 +59,7 @@ const RefinementWidget = ({ type, ...props }) => {
default:
return null;
}
};
}

function getPanelId(refinement) {
return refinement.options.attributes
Expand Down
6 changes: 3 additions & 3 deletions src/components/ReverseHighlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React from 'preact/compat';

import { getAttributeValueByPath, parseAttribute } from '../utils';

export const ReverseHighlight = ({
export function ReverseHighlight({
hit,
attribute,
tagName = 'mark',
...rest
}) => {
}) {
let parts = [];

try {
Expand Down Expand Up @@ -43,7 +43,7 @@ export const ReverseHighlight = ({
})}
</span>
);
};
}

function parseReverseHighlightedAttribute({
hit,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { SeeResultsButton } from './SeeResultsButton';
import { Stats } from './Stats';
import { Views } from './Views';

export const Search = (props) => {
export function Search(props) {
const { config, view, searchParameters, isMobile } = useAppContext();
const { isSearchStalled } = useSearchContext();

Expand Down Expand Up @@ -166,4 +166,4 @@ export const Search = (props) => {
</div>
</InstantSearch>
);
};
}
4 changes: 2 additions & 2 deletions src/components/SearchBox/FacetSearchBox.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'preact/compat';

export const FacetSearchBox = (props) => {
export function FacetSearchBox(props) {
return (
<div className="ais-SearchBox">
<form
Expand Down Expand Up @@ -59,4 +59,4 @@ export const FacetSearchBox = (props) => {
</form>
</div>
);
};
}
4 changes: 2 additions & 2 deletions src/components/SearchBox/PredictiveSearchBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ReverseHighlight } from '../ReverseHighlight';

import { SearchBox } from './SearchBox';

export const PredictiveSearchBox = (props) => {
export function PredictiveSearchBox(props) {
const [suggestion, setSuggestion] = React.useState(null);

return (
Expand Down Expand Up @@ -58,7 +58,7 @@ export const PredictiveSearchBox = (props) => {
</Index>
</>
);
};
}

const Suggestions = connectHits(function Suggestions({
query,
Expand Down
4 changes: 2 additions & 2 deletions src/components/SearchBox/SearchBox.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -138,4 +138,4 @@ export const SearchBox = (props) => {
</form>
</div>
);
};
}
4 changes: 2 additions & 2 deletions src/components/SearchButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const SearchButton = ({ onClick }) => {
);
};

const SearchIcon = (props) => {
function SearchIcon(props) {
return (
<svg
className="uni-SearchButton-Icon"
Expand All @@ -51,4 +51,4 @@ const SearchIcon = (props) => {
/>
</svg>
);
};
}
4 changes: 2 additions & 2 deletions src/components/Views.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'preact/compat';

import { IconViewGrid, IconViewList } from './Icons';

export const Views = (props) => {
export function Views(props) {
return (
<ul className="uni-BodyHeader-view">
<button
Expand Down Expand Up @@ -36,4 +36,4 @@ export const Views = (props) => {
</button>
</ul>
);
};
}
8 changes: 4 additions & 4 deletions src/config/Hit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Highlight, Snippet } from 'react-instantsearch-dom';

import './Hit.scss';

export const Hit = ({ hit, insights, view }) => {
export function Hit({ hit, insights, view }) {
return (
<article className="uni-Hit">
<a
Expand Down Expand Up @@ -60,9 +60,9 @@ export const Hit = ({ hit, insights, view }) => {
</a>
</article>
);
};
}

const CartIcon = (props) => {
function CartIcon(props) {
return (
<svg
viewBox="0 0 24 24"
Expand All @@ -77,4 +77,4 @@ const CartIcon = (props) => {
<path d="M5 1H1l0 0H5l2.7 13.4c0.2 1 1 1.6 2 1.6h9.7c1 0 1.8-0.7 2-1.6L23 6H6" />
</svg>
);
};
}

0 comments on commit 32a7892

Please sign in to comment.