From ca99952fa8846f546fb50a5d3b2e4398cc282182 Mon Sep 17 00:00:00 2001 From: SleeplessOne1917 Date: Fri, 28 Jul 2023 20:07:16 +0000 Subject: [PATCH] ES-Lint tweak (#2001) --- .eslintrc.json | 5 +- src/server/handlers/catch-all-handler.tsx | 2 +- src/shared/components/app/navbar.tsx | 6 +- src/shared/components/app/theme.tsx | 6 +- .../components/comment/comment-node.tsx | 18 ++--- .../components/comment/comment-report.tsx | 2 +- .../components/common/markdown-textarea.tsx | 2 +- src/shared/components/common/paginator.tsx | 2 +- .../components/common/password-input.tsx | 2 +- src/shared/components/common/pictrs-image.tsx | 2 +- .../common/registration-application.tsx | 2 +- src/shared/components/common/vote-buttons.tsx | 4 +- .../components/community/communities.tsx | 6 +- .../components/community/community-link.tsx | 2 +- src/shared/components/community/community.tsx | 54 +++++++------- src/shared/components/community/sidebar.tsx | 4 +- src/shared/components/home/admin-settings.tsx | 2 +- src/shared/components/home/emojis-form.tsx | 2 +- src/shared/components/home/home.tsx | 38 +++++----- src/shared/components/home/login-reset.tsx | 2 +- src/shared/components/home/login.tsx | 4 +- src/shared/components/home/setup.tsx | 4 +- src/shared/components/home/signup.tsx | 10 +-- src/shared/components/home/site-form.tsx | 2 +- src/shared/components/home/tagline-form.tsx | 6 +- src/shared/components/modlog.tsx | 4 +- src/shared/components/person/inbox.tsx | 68 +++++++++--------- .../components/person/password-change.tsx | 2 +- src/shared/components/person/profile.tsx | 28 ++++---- .../person/registration-applications.tsx | 4 +- src/shared/components/person/reports.tsx | 14 ++-- src/shared/components/person/settings.tsx | 8 +-- src/shared/components/person/verify-email.tsx | 4 +- src/shared/components/post/post-form.tsx | 2 +- src/shared/components/post/post-listing.tsx | 10 +-- src/shared/components/post/post-listings.tsx | 4 +- src/shared/components/post/post-report.tsx | 2 +- src/shared/components/post/post.tsx | 70 +++++++++---------- .../create-private-message.tsx | 4 +- .../private_message/private-message-form.tsx | 2 +- .../private-message-report.tsx | 2 +- .../private_message/private-message.tsx | 4 +- src/shared/components/search.tsx | 4 +- src/shared/markdown.ts | 6 +- src/shared/utils/app/new-vote.ts | 6 +- src/shared/utils/app/selectable-languages.ts | 4 +- src/shared/utils/app/set-theme.ts | 2 +- src/shared/utils/env/get-external-host.ts | 2 +- .../utils/helpers/get-random-from-list.ts | 2 +- .../utils/roles/am-community-creator.ts | 2 +- src/shared/utils/roles/am-site-creator.ts | 2 +- src/shared/utils/roles/am-top-mod.ts | 2 +- src/shared/utils/roles/can-mod.ts | 2 +- 53 files changed, 228 insertions(+), 227 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index ad777401..ea26ba3b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -20,10 +20,11 @@ "@typescript-eslint/no-explicit-any": 0, "@typescript-eslint/explicit-module-boundary-types": 0, "@typescript-eslint/no-empty-function": 0, + "@typescript-eslint/no-non-null-assertion": 0, "arrow-body-style": 0, "curly": 0, "eol-last": 0, - "eqeqeq": 0, + "eqeqeq": "error", "func-style": 0, "import/no-duplicates": 0, "max-statements": 0, @@ -39,7 +40,7 @@ "no-useless-constructor": 0, "no-useless-escape": 0, "no-var": 0, - "prefer-const": 1, + "prefer-const": "error", "prefer-rest-params": 0, "prettier/prettier": "error", "quote-props": 0, diff --git a/src/server/handlers/catch-all-handler.tsx b/src/server/handlers/catch-all-handler.tsx index 5f7f7da3..6dd9323a 100644 --- a/src/server/handlers/catch-all-handler.tsx +++ b/src/server/handlers/catch-all-handler.tsx @@ -48,7 +48,7 @@ export default async (req: Request, res: Response) => { let errorPageData: ErrorPageData | undefined = undefined; let try_site = await client.getSite(getSiteForm); - if (try_site.state === "failed" && try_site.msg == "not_logged_in") { + if (try_site.state === "failed" && try_site.msg === "not_logged_in") { console.error( "Incorrect JWT token, skipping auth so frontend can remove jwt cookie", ); diff --git a/src/shared/components/app/navbar.tsx b/src/shared/components/app/navbar.tsx index de09b300..0e96d680 100644 --- a/src/shared/components/app/navbar.tsx +++ b/src/shared/components/app/navbar.tsx @@ -480,7 +480,7 @@ export class Navbar extends Component { } get unreadInboxCount(): number { - if (this.state.unreadInboxCountRes.state == "success") { + if (this.state.unreadInboxCountRes.state === "success") { const data = this.state.unreadInboxCountRes.data; return data.replies + data.mentions + data.private_messages; } else { @@ -489,7 +489,7 @@ export class Navbar extends Component { } get unreadReportCount(): number { - if (this.state.unreadReportCountRes.state == "success") { + if (this.state.unreadReportCountRes.state === "success") { const data = this.state.unreadReportCountRes.data; return ( data.post_reports + @@ -502,7 +502,7 @@ export class Navbar extends Component { } get unreadApplicationCount(): number { - if (this.state.unreadApplicationCountRes.state == "success") { + if (this.state.unreadApplicationCountRes.state === "success") { const data = this.state.unreadApplicationCountRes.data; return data.registration_applications; } else { diff --git a/src/shared/components/app/theme.tsx b/src/shared/components/app/theme.tsx index 93f6aed3..07c4f8c7 100644 --- a/src/shared/components/app/theme.tsx +++ b/src/shared/components/app/theme.tsx @@ -22,8 +22,8 @@ export class Theme extends Component { ); } else if ( - this.props.defaultTheme != "browser" && - this.props.defaultTheme != "browser-compact" + this.props.defaultTheme !== "browser" && + this.props.defaultTheme !== "browser-compact" ) { return ( @@ -34,7 +34,7 @@ export class Theme extends Component { /> ); - } else if (this.props.defaultTheme == "browser-compact") { + } else if (this.props.defaultTheme === "browser-compact") { return ( { const cv = this.commentView; const purgeTypeText = - this.state.purgeType == PurgeType.Comment + this.state.purgeType === PurgeType.Comment ? I18NextService.i18n.t("purge_comment") : `${I18NextService.i18n.t("purge")} ${cv.creator.name}`; @@ -278,9 +278,9 @@ export class CommentNode extends Component { : colorList[0]; const showMoreChildren = - this.props.viewType == CommentViewType.Tree && + this.props.viewType === CommentViewType.Tree && !this.state.collapsed && - node.children.length == 0 && + node.children.length === 0 && node.comment_view.counts.child_count > 0; return ( @@ -1210,19 +1210,19 @@ export class CommentNode extends Component { get myComment(): boolean { return ( - UserService.Instance.myUserInfo?.local_user_view.person.id == + UserService.Instance.myUserInfo?.local_user_view.person.id === this.commentView.creator.id ); } get isPostCreator(): boolean { - return this.commentView.creator.id == this.commentView.post.creator_id; + return this.commentView.creator.id === this.commentView.post.creator_id; } get scoreColor() { - if (this.commentView.my_vote == 1) { + if (this.commentView.my_vote === 1) { return "text-info"; - } else if (this.commentView.my_vote == -1) { + } else if (this.commentView.my_vote === -1) { return "text-danger"; } else { return "text-muted"; @@ -1499,7 +1499,7 @@ export class CommentNode extends Component { handleModBanBothSubmit(i: CommentNode, event: any) { event.preventDefault(); - if (i.state.banType == BanType.Community) { + if (i.state.banType === BanType.Community) { i.handleBanPersonFromCommunity(i); } else { i.handleBanPerson(i); @@ -1552,7 +1552,7 @@ export class CommentNode extends Component { event.preventDefault(); i.setState({ purgeLoading: true }); - if (i.state.purgeType == PurgeType.Person) { + if (i.state.purgeType === PurgeType.Person) { i.props.onPurgePerson({ person_id: i.commentView.creator.id, reason: i.state.purgeReason, diff --git a/src/shared/components/comment/comment-report.tsx b/src/shared/components/comment/comment-report.tsx index bd8c77a5..834f96a4 100644 --- a/src/shared/components/comment/comment-report.tsx +++ b/src/shared/components/comment/comment-report.tsx @@ -35,7 +35,7 @@ export class CommentReport extends Component< componentWillReceiveProps( nextProps: Readonly<{ children?: InfernoNode } & CommentReportProps>, ): void { - if (this.props != nextProps) { + if (this.props !== nextProps) { this.setState({ loading: false }); } } diff --git a/src/shared/components/common/markdown-textarea.tsx b/src/shared/components/common/markdown-textarea.tsx index 7d58a222..43784082 100644 --- a/src/shared/components/common/markdown-textarea.tsx +++ b/src/shared/components/common/markdown-textarea.tsx @@ -360,7 +360,7 @@ export class MarkdownTextArea extends Component< handleEmoji(i: MarkdownTextArea, e: any) { let value = e.native; - if (value == null) { + if (value === null) { const emoji = customEmojisLookup.get(e.id)?.custom_emoji; if (emoji) { value = `![${emoji.alt_text}](${emoji.image_url} "${emoji.shortcode}")`; diff --git a/src/shared/components/common/paginator.tsx b/src/shared/components/common/paginator.tsx index bd4ecf87..ed0ed211 100644 --- a/src/shared/components/common/paginator.tsx +++ b/src/shared/components/common/paginator.tsx @@ -15,7 +15,7 @@ export class Paginator extends Component {
- {this.state.siteForm.registration_mode == "RequireApplication" && ( + {this.state.siteForm.registration_mode === "RequireApplication" && (