Typescript: space-before-function-paren

Created on 14 Nov 2016  路  9Comments  路  Source: microsoft/TypeScript

_From @aochsner on November 11, 2016 22:19_

We use space-before-function-paren in our eslint rules for readability. I'd like an option to format to this behavior

  • VSCode Version: 1.7.1
  • OS Version: macOS Sierra 10.12.1

Steps to Reproduce:

  1. Type function foo () { }
  2. Format the code (if it doesn't auto-format)
  3. Code is formatted to function foo() { } with no mechanism to override

_Copied from original issue: Microsoft/vscode#15386_

Formatter Fixed Suggestion VS Code Tracked help wanted

Most helpful comment

So I have gotten around this issue a little bit by turning on:
"eslint.autoFixOnSave": true

in my settings.

All 9 comments

@aochsner thank you for opening this issue. The functionality for formatting is provided by TS Server. I will migrate this feature request to their repo.

Hi team, I met the same problem, this made me so sad, I have to format my code in command line tools since the build-in formatter will change function () -> function() .

So I have gotten around this issue a little bit by turning on:
"eslint.autoFixOnSave": true

in my settings.

@aochsner yeah, you approach works fine for me, thanks.

PRs welcomed.

Happy to take a stab... can you point me in the right direction?

The formatting logic resides in src/services/formatting. You'll want to check out the tests/cases/fourslash directory and peek around to get a sense of how to write a formatter test.

Also see our CONTRIBUTING.md.

Okay. I added a couple more test cases for InsertSpaceBeforeFunctionParenthesis. Found InsertSpaceAfterFunctionKeywordForAnonymousFuctions to cover that case. Added InsertSpaceAfterConstructor to handle that case. That should cover the main cases that http://eslint.org/docs/rules/space-before-function-paren enforces.

Let me know what else should be done. Thanks!

thanks @aochsner!

Was this page helpful?
0 / 5 - 0 ratings