Parentheses around single parameter arrow functions / Add support for arrow-parens property
Problem
Hey ! It will be great to add an option to disable auto remove of parenthesis when there is only one argument in an arrow function. Most of professional projects configure their way since it's the default eslint behaviour. Here is a Eslint Link : http://eslint.org/docs/rules/arrow-parens [code block]
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Enable Arrow Function Parentheses Support in Prettier
Prettier currently removes parentheses around single-parameter arrow functions by default, which can conflict with team coding standards that prefer explicit parentheses for clarity and consistency. This behavior is not configurable within Prettier, leading to discrepancies with ESLint configurations that allow for such options.
Awaiting Verification
Be the first to verify this fix
- 1
Update Prettier Configuration
Add a configuration option to Prettier to support keeping parentheses around single parameter arrow functions. This will align Prettier's behavior with common ESLint configurations.
javascriptmodule.exports = { arrowParens: 'always' }; - 2
Modify ESLint Configuration
Ensure that the ESLint configuration is set to enforce the same rule for consistency across the project. Update the ESLint configuration file to include the arrow-parens rule.
javascriptmodule.exports = { rules: { 'arrow-parens': ['error', 'always'] } }; - 3
Run Prettier and ESLint
After updating the configurations, run Prettier and ESLint on the codebase to ensure that the changes are applied correctly and that there are no formatting errors.
bashnpx prettier --write . && npx eslint . - 4
Review Code Changes
Review the changes made by Prettier to ensure that all single-parameter arrow functions now have parentheses. Confirm that the code adheres to the new formatting rules.
bashgit diff
Validation
To confirm the fix worked, check that all single-parameter arrow functions in the codebase retain their parentheses after running Prettier. Additionally, ensure that ESLint does not report any errors related to the arrow-parens rule.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep