Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(eslint): enable react-hooks/recommended #4498

Conversation

dominikdosoudil
Copy link
Contributor

The only problem is that there are few internal functions that have prefix "use" and eslint thinks that they are hooks.

Should the code be refactored along with this PR or it is just ok that some false positive errors would pop up with accepting this PR?

Copy link

vercel bot commented Nov 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
semantic-ui-react ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 22, 2024 8:59am

@layershifter
Copy link
Member

Should the code be refactored along with this PR or it is just ok that some false positive errors would pop up with accepting this PR?

@dominikdosoudil let's create a separate PR to rename these functions. I believe the problem is with classNameBuilders.js.

I suggest:

  • Update src/lib/index.js to do (so we don't need to do all renames in a single PR):
    export {
      useKeyOnly,
    + useKeyOnly as getKeyOnly,
      useKeyOrValueAndKey,
    + useKeyOrValueAndKey as getKeyOrValueAndKey,
      // etc.
    } from './classNameBuilders'
  • Create a set of PRs to replace useKeyOnly with getKeyOnly, useKeyOrValueAndKey ➡️ getKeyOrValueAndKey, etc. Keep each PR with some reasonable amount of files 🐱
  • Rename functions i.e. useKeyOnly to getKeyOnly
  • Enable the ESLint plugin 🎉

@dominikdosoudil
Copy link
Contributor Author

  • Rename functions i.e. useKeyOnly to getKeyOnly

@layershifter That sounds good, however this step will still affect a lot of files as the useKeyOnly as getKeyOnly, will need to be changed to getKeyOnly,.

If that's ok with you, I'll follow the steps and mention the individual PRs here.

@layershifter
Copy link
Member

@layershifter That sounds good, however this step will still affect a lot of files as the useKeyOnly as getKeyOnly, will need to be changed to getKeyOnly,.

Indeed, but if PRs will be sliced by files' location i.e. all (use* => get*) in src/modules, then src/elements, etc. It will be less files at once :)

@dominikdosoudil
Copy link
Contributor Author

Can I suggest another approach which would avoid the last big bang?

We might create aliases for useKeyOnly and deprecate the original first:

/**
+ * @deprecated
 * Props where only the prop key is used in the className.
 * @param {*} val A props value
 * @param {string} key A props key
 *
 * @example
 * <Label tag />
 * <div class="ui tag label"></div>
 */
export const useKeyOnly = (val, key) => val && key

+ export const getKeyOnly = useKeyOnly;

Step 2 - incrementally replace the function name in individual files to make PR less big:

export {
-  useKeyOnly,
+ getKeyOnly,
-  useKeyOrValueAndKey,
+ getKeyOrValueAndKey,
  // etc.
} from './classNameBuilders'

Step 3 - remove the original functions and inline the aliases:

/**
- * @deprecated
 * Props where only the prop key is used in the className.
 * @param {*} val A props value
 * @param {string} key A props key
 *
 * @example
 * <Label tag />
 * <div class="ui tag label"></div>
 */
- export const useKeyOnly = (val, key) => val && key
-
- export const getKeyOnly = useKeyOnly;
+ export const getKeyOnly = (val, key) => val && key

This way, there should not be the large number of changes in imports after finally renaming the functions in their declarations.

@layershifter
Copy link
Member

layershifter commented Nov 13, 2024

@dominikdosoudil yeah, that's actually was my proposal 🐱 Sorry if I was unclear :)

image

^ that would avoid deprecations with the same result, but your proposal is even better :)

@dominikdosoudil
Copy link
Contributor Author

Step 1: #4500 aliases

@layershifter
Copy link
Member

Step 1: #4500 aliases

@dominikdosoudil it's merged 😉

@dominikdosoudil
Copy link
Contributor Author

After merging #4505, there will be few warnings and one remaining error:

React Hook "React.useEffect" is called conditionally. React Hooks must be called in the exact same order in every component render

caused by

  if (process.env.NODE_ENV !== 'production') {
    React.useEffect(() => {
      ...
    }, [exclusive, activeIndex])
  }

I think that it might be ignored because we are smarter than eslint here and we know that NODE_ENV won't probably change during runtime.

@layershifter layershifter mentioned this pull request Nov 22, 2024
27 tasks
@layershifter
Copy link
Member

I think that it might be ignored because we are smarter than eslint here and we know that NODE_ENV won't probably change during runtime.

@dominikdosoudil right, let's use eslint-disable-next-line for this case.

Copy link

codecov bot commented Nov 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.53%. Comparing base (a7e8c69) to head (43ca40b).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4498   +/-   ##
=======================================
  Coverage   99.53%   99.53%           
=======================================
  Files         186      186           
  Lines        3463     3463           
=======================================
  Hits         3447     3447           
  Misses         16       16           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@layershifter layershifter changed the title Eslint: extend plugin:react-hooks/recommended chore(eslint): enable react-hooks/recommended Nov 22, 2024
@layershifter layershifter merged commit e0a42b5 into Semantic-Org:master Nov 22, 2024
10 checks passed
@layershifter
Copy link
Member

@dominikdosoudil ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants