chore: Enable eslint to enforce curly (#3060)

This commit is contained in:
Tom Moor
2022-02-05 10:15:40 -08:00
committed by GitHub
parent c7df74fcc4
commit c5a11fe17b
103 changed files with 1175 additions and 397 deletions

View File

@@ -55,9 +55,13 @@ class AuthenticatedLayout extends React.Component<Props> {
goToNewDocument = () => {
const { activeCollectionId } = this.props.ui;
if (!activeCollectionId) return;
if (!activeCollectionId) {
return;
}
const can = this.props.policies.abilities(activeCollectionId);
if (!can.update) return;
if (!can.update) {
return;
}
history.push(newDocumentPath(activeCollectionId));
};
@@ -65,7 +69,9 @@ class AuthenticatedLayout extends React.Component<Props> {
const { auth } = this.props;
const { user, team } = auth;
const showSidebar = auth.authenticated && user && team;
if (auth.isSuspended) return <ErrorSuspended />;
if (auth.isSuspended) {
return <ErrorSuspended />;
}
const sidebar = showSidebar ? (
<Switch>

View File

@@ -72,13 +72,18 @@ export function filterTemplateItems(items: TMenuItem[]): TMenuItem[] {
// this block literally just trims unnecessary separators
filtered = filtered.reduce((acc, item, index) => {
// trim separators from start / end
if (item.type === "separator" && index === 0) return acc;
if (item.type === "separator" && index === filtered.length - 1) return acc;
if (item.type === "separator" && index === 0) {
return acc;
}
if (item.type === "separator" && index === filtered.length - 1) {
return acc;
}
// trim double separators looking ahead / behind
const prev = filtered[index - 1];
if (prev && prev.type === "separator" && item.type === "separator")
if (prev && prev.type === "separator" && item.type === "separator") {
return acc;
}
// otherwise, continue
return [...acc, item];

View File

@@ -28,7 +28,9 @@ function HoverPreviewInternal({ node, onClose }: Props) {
const startCloseTimer = () => {
stopOpenTimer();
timerClose.current = setTimeout(() => {
if (isVisible) setVisible(false);
if (isVisible) {
setVisible(false);
}
onClose();
}, DELAY_CLOSE);
};

View File

@@ -21,7 +21,9 @@ function HoverPreviewDocument({ url, children }: Props) {
}
const document = slug ? documents.getByUrl(slug) : undefined;
if (!document) return null;
if (!document) {
return null;
}
return (
<>

View File

@@ -84,7 +84,9 @@ const InputSelect = (props: Props) => {
);
React.useEffect(() => {
if (previousValue.current === select.selectedValue) return;
if (previousValue.current === select.selectedValue) {
return;
}
previousValue.current = select.selectedValue;
async function load() {

View File

@@ -70,7 +70,9 @@ class PaginatedList extends React.Component<Props> {
};
fetchResults = async () => {
if (!this.props.fetch) return;
if (!this.props.fetch) {
return;
}
this.isFetching = true;
const limit = DEFAULT_PAGINATION_LIMIT;
const results = await this.props.fetch({
@@ -94,7 +96,9 @@ class PaginatedList extends React.Component<Props> {
@action
loadMoreResults = async () => {
// Don't paginate if there aren't more results or were currently fetching
if (!this.allowLoadMore || this.isFetching) return;
if (!this.allowLoadMore || this.isFetching) {
return;
}
// If there are already cached results that we haven't yet rendered because
// of lazy rendering then show another page.
const leftToRender = this.props.items.length - this.renderCount;

View File

@@ -22,7 +22,9 @@ class PathToDocument extends React.Component<Props> {
handleClick = async (ev: React.SyntheticEvent) => {
ev.preventDefault();
const { document, result, onSuccess } = this.props;
if (!document) return;
if (!document) {
return;
}
if (result.type === "document") {
await document.move(result.collectionId, result.id);
@@ -30,13 +32,17 @@ class PathToDocument extends React.Component<Props> {
await document.move(result.collectionId);
}
if (onSuccess) onSuccess();
if (onSuccess) {
onSuccess();
}
};
render() {
const { result, collection, document, ref, style } = this.props;
const Component = document ? ResultWrapperLink : ResultWrapper;
if (!result) return <div />;
if (!result) {
return <div />;
}
return (
// @ts-expect-error ts-migrate(2604) FIXME: JSX element type 'Component' does not have any con... Remove this comment to see the full error message

View File

@@ -12,13 +12,16 @@ export default function ScrollToTop({ children }: Props) {
const previousLocationPathname = usePrevious(location.pathname);
React.useEffect(() => {
if (location.pathname === previousLocationPathname) return;
if (location.pathname === previousLocationPathname) {
return;
}
// exception for when entering or exiting document edit, scroll position should not reset
if (
location.pathname.match(/\/edit\/?$/) ||
previousLocationPathname?.match(/\/edit\/?$/)
)
) {
return;
}
window.scrollTo(0, 0);
}, [location.pathname, previousLocationPathname]);

View File

@@ -21,7 +21,9 @@ function Scrollable(
const { height } = useWindowSize();
const updateShadows = React.useCallback(() => {
const c = (ref || fallbackRef).current;
if (!c) return;
if (!c) {
return;
}
const scrollTop = c.scrollTop;
const tsv = !!((shadow || topShadow) && scrollTop > 0);

View File

@@ -79,8 +79,12 @@ function CollectionLink({
accept: "document",
drop: (item: DragObject, monitor) => {
const { id, collectionId } = item;
if (monitor.didDrop()) return;
if (!collection) return;
if (monitor.didDrop()) {
return;
}
if (!collection) {
return;
}
const document = documents.get(id);
if (collection.id === collectionId && !document?.parentDocumentId) {
@@ -115,7 +119,9 @@ function CollectionLink({
const [{ isOverReorder }, dropToReorder] = useDrop({
accept: "document",
drop: async (item: DragObject) => {
if (!collection) return;
if (!collection) {
return;
}
documents.move(item.id, collection.id, undefined, 0);
},
collect: (monitor) => ({

View File

@@ -112,7 +112,9 @@ function DocumentLink(
const handleTitleChange = React.useCallback(
async (title: string) => {
if (!document) return;
if (!document) {
return;
}
await documents.update(
{
id: document.id,
@@ -167,8 +169,12 @@ function DocumentLink(
const [{ isOverReparent, canDropToReparent }, dropToReparent] = useDrop({
accept: "document",
drop: (item: DragObject, monitor) => {
if (monitor.didDrop()) return;
if (!collection) return;
if (monitor.didDrop()) {
return;
}
if (!collection) {
return;
}
documents.move(item.id, collection.id, node.id);
},
canDrop: (_item, monitor) =>
@@ -212,8 +218,12 @@ function DocumentLink(
const [{ isOverReorder, isDraggingAnyDocument }, dropToReorder] = useDrop({
accept: "document",
drop: (item: DragObject) => {
if (!collection) return;
if (item.id === node.id) return;
if (!collection) {
return;
}
if (item.id === node.id) {
return;
}
if (expanded) {
documents.move(item.id, collection.id, node.id, 0);

View File

@@ -67,7 +67,9 @@ function StarredLink({
const handleTitleChange = React.useCallback(
async (title: string) => {
if (!document) return;
if (!document) {
return;
}
await documents.update(
{
id: document.id,

View File

@@ -79,7 +79,9 @@ class SocketProvider extends React.Component<Props> {
views,
fileOperations,
} = this.props;
if (!auth.token) return;
if (!auth.token) {
return;
}
this.socket.on("connect", () => {
// immediately send current users token to the websocket backend where it
@@ -329,8 +331,9 @@ class SocketProvider extends React.Component<Props> {
this.socket.on("fileOperations.update", async (event: any) => {
const user = auth.user;
let collection = null;
if (event.collectionId)
if (event.collectionId) {
collection = await collections.fetch(event.collectionId);
}
if (user) {
fileOperations.add({ ...event, user, collection });

View File

@@ -63,7 +63,9 @@ const Tabs = ({ children }: { children: React.ReactNode }) => {
const updateShadows = React.useCallback(() => {
const c = ref.current;
if (!c) return;
if (!c) {
return;
}
const scrollLeft = c.scrollLeft;
const wrapperWidth = c.scrollWidth - c.clientWidth;
const fade = !!(wrapperWidth - scrollLeft !== 0);