jsx-eslint / eslint-plugin-react

React-specific linting rules for ESLint
MIT License
8.86k stars 2.75k forks source link

[New] `async-server-action`: Add rule to require that server actions be async #3729

Open jorgezreik opened 2 months ago

jorgezreik commented 2 months ago

Adds a new rule to require that a server actions (functions with the 'use server' directive) be async as specified by the server actions spec. Suggests fixes for server actions that aren't async by adding the async keyword.

Note: It is my first time contributing so let me know if I missed anything!

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 97.59%. Comparing base (a944aa5) to head (7f9a2bd).

:exclamation: Current head 7f9a2bd differs from pull request most recent head 4d1e087

Please upload reports for the commit 4d1e087 to get more accurate results.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #3729 +/- ## ========================================== + Coverage 94.47% 97.59% +3.11% ========================================== Files 134 134 Lines 9613 9479 -134 Branches 3486 3468 -18 ========================================== + Hits 9082 9251 +169 + Misses 531 228 -303 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

jorgezreik commented 2 months ago

I see some examples using single and double quotes - great! - but none using backticks. Can we add some? (whether it's supported or not)

I knew I'd miss a few things 😅 Thanks for the feedback, really appreciate it!

Backticks don't work with use server, but great idea to test them. Adding now.

jorgezreik commented 2 months ago

A semi-related question that came to mind that I'd like advice on:

Other ESLint rules like eslint/require-await and typescript-eslint/require-await report async functions that do not have an await operator as incorrect. Any ideas on how we can make rules like these not report on "use server"? Adding options to these rules to ignore functions with certain directives would do the trick, but an option like that is React-specific enough that it's unlikely to get merged.

ljharb commented 1 month ago

The require-await rules are harmful and bad and should never have existed in the first place. An async function without any awaits is perfectly acceptable (unlike a generator without a yield).

As such, the solution there is to just disable those horrifically foolish rules.