diff --git a/.eslintrc.json b/.eslintrc.json index ef97a7a..35fed42 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -5,7 +5,8 @@ }, "extends": [ "eslint:recommended", - "plugin:react/recommended" + "plugin:react/recommended", + "plugin:react-hooks/recommended" ], "overrides": [ ], diff --git a/package-lock.json b/package-lock.json index 1ca5e00..22be2e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,6 +30,7 @@ "css-toggle-switch": "^4.1.0", "eslint": "^8.25.0", "eslint-plugin-react": "^7.31.10", + "eslint-plugin-react-hooks": "^4.6.0", "sass": "^1.55.0", "webpack": "^5.74.0", "webpack-cli": "^4.10.0", @@ -3471,6 +3472,18 @@ "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8" } }, + "node_modules/eslint-plugin-react-hooks": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.6.0.tgz", + "integrity": "sha512-oFc7Itz9Qxh2x4gNHStv3BqJq54ExXmfC+a1NjAta66IAN87Wu0R/QArgIS9qKzX3dXKPI9H5crl9QchNMY9+g==", + "dev": true, + "engines": { + "node": ">=10" + }, + "peerDependencies": { + "eslint": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0" + } + }, "node_modules/eslint-plugin-react/node_modules/doctrine": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", @@ -12604,6 +12617,13 @@ } } }, + "eslint-plugin-react-hooks": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.6.0.tgz", + "integrity": "sha512-oFc7Itz9Qxh2x4gNHStv3BqJq54ExXmfC+a1NjAta66IAN87Wu0R/QArgIS9qKzX3dXKPI9H5crl9QchNMY9+g==", + "dev": true, + "requires": {} + }, "eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", diff --git a/package.json b/package.json index 0fbfbfa..d57efa8 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "css-toggle-switch": "^4.1.0", "eslint": "^8.25.0", "eslint-plugin-react": "^7.31.10", + "eslint-plugin-react-hooks": "^4.6.0", "sass": "^1.55.0", "webpack": "^5.74.0", "webpack-cli": "^4.10.0", diff --git a/src/pages/common/Post.js b/src/pages/common/Post.js index c12074b..1283aa2 100644 --- a/src/pages/common/Post.js +++ b/src/pages/common/Post.js @@ -75,11 +75,8 @@ const Post = (props) => { } } - let editedMode, setEditedMode - if (innerHTML[editedModes.rich]) - [editedMode, setEditedMode] = useState(editedModes.rich) - else - editedMode = editedModes.orig + // eslint-disable-next-line react-hooks/rules-of-hooks + const [editedMode, setEditedMode] = useState(innerHTML[editedModes.rich] ? editedModes.rich : editedModes.orig) const totalComments =
{props.num_comments} comments  diff --git a/src/pages/thread/Comment.js b/src/pages/thread/Comment.js index 512c19d..2207a81 100644 --- a/src/pages/thread/Comment.js +++ b/src/pages/thread/Comment.js @@ -45,11 +45,7 @@ const Comment = (props) => { } const [collapsed, setCollapsed] = useState(false) - let editedMode, setEditedMode - if (innerHTML[editedModes.rich]) - [editedMode, setEditedMode] = useState(editedModes.rich) - else - editedMode = editedModes.orig + const [editedMode, setEditedMode] = useState(innerHTML[editedModes.rich] ? editedModes.rich : editedModes.orig) const permalink = `/r/${props.subreddit}/comments/${props.link_id}/_/${props.id}/` const parentlink = props.parent_id == props.link_id ? undefined : ( props.depth == 0 ? diff --git a/src/pages/thread/SortBy.js b/src/pages/thread/SortBy.js index 11d90bf..2ca27b5 100644 --- a/src/pages/thread/SortBy.js +++ b/src/pages/thread/SortBy.js @@ -1,7 +1,7 @@ import React, { useState } from 'react' import {connect, sort, filter, minCommentsLimit, maxCommentsLimit, constrainMaxComments} from '../../state' -const sortBy = props => { +const SortBy = props => { // The current value of the field; it'll be later saved after an onBlur event const [maxCommentsField, setMaxCommentsField] = useState(props.global.maxComments) const isFirefox = typeof InstallTrigger !== 'undefined' @@ -57,4 +57,4 @@ const sortBy = props => { ) } -export default connect(sortBy) +export default connect(SortBy)