~cytrogen/masto-fe

d9b93bd15e508bd19896950ca5c5d356e7e402d4 — Renaud Chaput 2 years ago 955179f
Enforce React Rules of Hooks with eslint (#24911)

M .eslintrc.js => .eslintrc.js +2 -0
@@ 4,6 4,7 @@ module.exports = {
  extends: [
    'eslint:recommended',
    'plugin:react/recommended',
    'plugin:react-hooks/recommended',
    'plugin:jsx-a11y/recommended',
    'plugin:import/recommended',
    'plugin:promise/recommended',


@@ 284,6 285,7 @@ module.exports = {
        'eslint:recommended',
        'plugin:@typescript-eslint/recommended',
        'plugin:react/recommended',
        'plugin:react-hooks/recommended',
        'plugin:jsx-a11y/recommended',
        'plugin:import/recommended',
        'plugin:import/typescript',

M app/javascript/mastodon/actions/streaming.js => app/javascript/mastodon/actions/streaming.js +2 -0
@@ 52,8 52,10 @@ export const connectTimelineStream = (timelineId, channelName, params = {}, opti
    /**
     * @param {function(Function, Function): void} fallback
     */

    const useFallback = fallback => {
      fallback(dispatch, () => {
        // eslint-disable-next-line react-hooks/rules-of-hooks -- this is not a react hook
        pollingId = setTimeout(() => useFallback(fallback), 20000 + randomUpTo(20000));
      });
    };

M app/javascript/mastodon/features/compose/containers/emoji_picker_dropdown_container.js => app/javascript/mastodon/features/compose/containers/emoji_picker_dropdown_container.js +1 -0
@@ 72,6 72,7 @@ const mapDispatchToProps = (dispatch, { onPickEmoji }) => ({
  },

  onPickEmoji: emoji => {
    // eslint-disable-next-line react-hooks/rules-of-hooks -- this is not a react hook
    dispatch(useEmoji(emoji));

    if (onPickEmoji) {

M app/javascript/mastodon/features/compose/containers/language_dropdown_container.js => app/javascript/mastodon/features/compose/containers/language_dropdown_container.js +1 -0
@@ 26,6 26,7 @@ const mapDispatchToProps = dispatch => ({
  },

  onClose (value) {
    // eslint-disable-next-line react-hooks/rules-of-hooks -- this is not a react hook
    dispatch(useLanguage(value));
  },


M package.json => package.json +1 -0
@@ 189,6 189,7 @@
    "eslint-plugin-jsx-a11y": "~6.7.1",
    "eslint-plugin-promise": "~6.1.1",
    "eslint-plugin-react": "~7.32.2",
    "eslint-plugin-react-hooks": "^4.6.0",
    "husky": "^8.0.3",
    "jest": "^29.5.0",
    "jest-environment-jsdom": "^29.5.0",

M yarn.lock => yarn.lock +5 -0
@@ 5125,6 5125,11 @@ eslint-plugin-promise@~6.1.1:
  resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-6.1.1.tgz#269a3e2772f62875661220631bd4dafcb4083816"
  integrity sha512-tjqWDwVZQo7UIPMeDReOpUgHCmCiH+ePnVT+5zVapL0uuHnegBUs2smM13CzOs2Xb5+MHMRFTs9v24yjba4Oig==

eslint-plugin-react-hooks@^4.6.0:
  version "4.6.0"
  resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.6.0.tgz#4c3e697ad95b77e93f8646aaa1630c1ba607edd3"
  integrity sha512-oFc7Itz9Qxh2x4gNHStv3BqJq54ExXmfC+a1NjAta66IAN87Wu0R/QArgIS9qKzX3dXKPI9H5crl9QchNMY9+g==

eslint-plugin-react@~7.32.2:
  version "7.32.2"
  resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.32.2.tgz#e71f21c7c265ebce01bcbc9d0955170c55571f10"