Skip to content

fix(no-extra-parens): do not break specific ReturnStatement#738

Merged
antfu merged 10 commits into
eslint-stylistic:mainfrom
Mori-Yang:main
May 24, 2025
Merged

fix(no-extra-parens): do not break specific ReturnStatement#738
antfu merged 10 commits into
eslint-stylistic:mainfrom
Mori-Yang:main

Conversation

@Mori-Yang

Copy link
Copy Markdown
Contributor

Description

case:

((a, b) => {
  return (
    a % b == 0
  ) || (a % b == 1)
})()

It is not the job of no-extra-parens to make this code into one line. For this case, the problem of program errors caused by parentheses should be avoided. The modified solution is to check whether the argument of ReturnStatement wraps and the first line contains only one '('

Linked Issues

fixes #699

Additional context

Are there any other cases that I haven't considered?

@Mori-Yang Mori-Yang changed the title fix: no-extra-parens breaks function return values fix(no-extra-parens): no-extra-parens breaks function return values Mar 23, 2025
Comment thread packages/eslint-plugin/rules/no-extra-parens/no-extra-parens._ts_.ts Outdated
@9romise 9romise changed the title fix(no-extra-parens): no-extra-parens breaks function return values fix(no-extra-parens): do not break specific ReturnStatement Mar 25, 2025
@9romise

9romise commented Mar 25, 2025

Copy link
Copy Markdown
Member

I've updated the logic.

This exception handles cases where:

  • Parent node is a ReturnStatement
  • The return statement spans multiple lines
  • The expression is not already wrapped in parentheses

@9romise 9romise requested a review from antfu March 25, 2025 16:02
@codecov

codecov Bot commented Mar 25, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.36%. Comparing base (b6ab14d) to head (00e0373).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #738   +/-   ##
=======================================
  Coverage   74.36%   74.36%           
=======================================
  Files         122      122           
  Lines       24770    24771    +1     
  Branches     4669     4670    +1     
=======================================
+ Hits        18420    18421    +1     
  Misses       6350     6350           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@antfu antfu enabled auto-merge May 24, 2025 03:07
@antfu antfu added this pull request to the merge queue May 24, 2025
Merged via the queue into eslint-stylistic:main with commit a375a92 May 24, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

no-extra-parens: autofix breaks function return values

3 participants