Vscode: Javascript formatter: space-before-function-paren

Created on 11 Nov 2016  路  10Comments  路  Source: microsoft/vscode

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
feature-request formatting javascript

Most helpful comment

I am able to fix this by making es-lint auto correct the fixable code:

"files.associations": {
        "*.vue": "html"
    },
"editor.formatOnSave": true,
    // Defines space handling before function argument parentheses. Requires TypeScript >= 2.1.5.
    "typescript.format.insertSpaceBeforeFunctionParenthesis": true,
    // Defines space handling before function argument parentheses. Requires TypeScript >= 2.1.5.
    "javascript.format.insertSpaceBeforeFunctionParenthesis": true,
    // Eslint options
    "eslint.enable": true,
    "eslint.options": {
        "extensions": [
            ".html",
            ".js",
            ".vue",
            ".jsx"
        ]
    },
    // An array of language ids which should be validated by ESLint
    "eslint.validate": [
        "javascript",
        "javascriptreact",
        {
            "language": "html",
            "autoFix": true
        }
    ],
    // Run the linter on save (onSave) or on type (onType)
    "eslint.run": "onSave",
    // Turns auto fix on save on or off.
    "eslint.autoFixOnSave": true

Eslint is now fully integrated in vscode and everything works great! 馃憤

All 10 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.

This issue was moved to Microsoft/TypeScript#12234

Does this have a new issue for the vscode side now, @waderyan? Can't seem to find it

This doesn't seem fixed at all yet the referenced issue(Microsoft/TypeScript#12234) and this one is closed. Format still removes space between function name and (. I found no settings option for this either.

Using the latest 1.9.0 on macOS.

same as krokofant, MacOS, 1.9.1

Using Vs code 1.12 insider build. Following settings are ignored on format:

// Defines space handling before function argument parentheses. Requires TypeScript >= 2.1.5.
"typescript.format.insertSpaceBeforeFunctionParenthesis": true,
// Defines space handling before function argument parentheses. Requires TypeScript >= 2.1.5.
"javascript.format.insertSpaceBeforeFunctionParenthesis": true

same as krokofant, MacOS, 1.12.2

I am able to fix this by making es-lint auto correct the fixable code:

"files.associations": {
        "*.vue": "html"
    },
"editor.formatOnSave": true,
    // Defines space handling before function argument parentheses. Requires TypeScript >= 2.1.5.
    "typescript.format.insertSpaceBeforeFunctionParenthesis": true,
    // Defines space handling before function argument parentheses. Requires TypeScript >= 2.1.5.
    "javascript.format.insertSpaceBeforeFunctionParenthesis": true,
    // Eslint options
    "eslint.enable": true,
    "eslint.options": {
        "extensions": [
            ".html",
            ".js",
            ".vue",
            ".jsx"
        ]
    },
    // An array of language ids which should be validated by ESLint
    "eslint.validate": [
        "javascript",
        "javascriptreact",
        {
            "language": "html",
            "autoFix": true
        }
    ],
    // Run the linter on save (onSave) or on type (onType)
    "eslint.run": "onSave",
    // Turns auto fix on save on or off.
    "eslint.autoFixOnSave": true

Eslint is now fully integrated in vscode and everything works great! 馃憤

You guys should open a new issue, it works for me on Win10 and I don't think they watch comments on closed issues (that's why I opened the pull in the first place)

Thanks @mubaidr. Your settings fixed the problem for me. Version 1.16.1 (windows).

Was this page helpful?
0 / 5 - 0 ratings