Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

space_after_named_function not working inside an ES6 class #1622

Closed
jacobrec opened this issue Jan 28, 2019 · 6 comments · Fixed by #2033
Closed

space_after_named_function not working inside an ES6 class #1622

jacobrec opened this issue Jan 28, 2019 · 6 comments · Fixed by #2033

Comments

@jacobrec
Copy link

Description

space_after_named_function not working inside an ES6 class. I don't know if this is the indented behaviour or not, but it was not what I was expecting

Input

The code looked like this before beautification:

class blah {
  constructor() {
    this.doStuff()
  }

  doStuff() {
    console.log("stuff")
  }
}

function test() {}

Expected Output

The code should have looked like this after beautification:

class blah {
  constructor () {
    this.doStuff()
  }

  doStuff () {
    console.log("stuff")
  }
}

function test () {}

Actual Output

The code actually looked like this after beautification:

class blah {
  constructor() {
    this.doStuff()
  }

  doStuff() {
    console.log("stuff")
  }
}

function test () {}

Steps to Reproduce

Run on https://beautifier.io/

Environment

https://beautifier.io/
Also, ubuntu 18.10

Settings

Example:

{
  "indent_size": "2",
  "indent_char": " ",
  "max_preserve_newlines": "5",
  "preserve_newlines": true,
  "keep_array_indentation": false,
  "break_chained_methods": false,
  "indent_scripts": "normal",
  "brace_style": "collapse",
  "space_before_conditional": true,
  "unescape_strings": false,
  "jslint_happy": false,
  "end_with_newline": false,
  "wrap_line_length": "0",
  "indent_inner_html": false,
  "comma_first": false,
  "e4x": true,
  "space_after_anon_function": true,
  "space_after_named_function": true
}
@favna
Copy link

favna commented Feb 27, 2019

I can second this as I noticed it as well and (wrongfully) reported it on HookyQR's VSCode Beautify which apparently uses js-beautify in the background.

This was my code snippet from the issue there, which is just another bit of code that can be used for reproduction.

Full code as well as expected result:

export default class StringArrayType extends ArgumentType {
    constructor (client) {
        super(client, 'stringarray');
    }
}

Actual result:

export default class StringArrayType extends ArgumentType {
    constructor(client) {
        super(client, 'stringarray');
    }
}

@bitwiseman
Copy link
Member

bitwiseman commented Feb 27, 2019

This should be pretty simple but it will need to differentiate from:

function test() {
    constructor();
}

This will requires more work than I have time for currently, but here's the test and an incorrect implementation. The correct implementation will recognize that we are inside a class declaration.

@mhnaeem
Copy link
Contributor

mhnaeem commented Apr 11, 2022

Added a new PR for this feature

bitwiseman added a commit that referenced this issue Apr 22, 2022
…ion-classes

Fixes #1622 - Adds space_after_named_function option for ES6 classes
@bitwiseman bitwiseman added this to the 1.14.x milestone Apr 22, 2022
@aichingm
Copy link

From what I can tell this should already have landed in 1.14.3 right?

If so it does not seam to be working.

JS test:

$ echo "class A {bar(){}}function foo(){}" | node node_modules/.bin/js-beautify --space-after-named-function  -

class A {
    bar() {}
}

function foo () {}

Python test:

$ echo "class A {bar(){}}function foo(){}" | js-beautify --space-after-named-function  -

class A {
    bar() {}
}

function foo () {}

Versions:

$ js-beautify -h
jsbeautifier.py@1.14.3
...
$ node node_modules/.bin/js-beautify -h
js-beautify@1.14.3
...

@bitwiseman
Copy link
Member

Yup, not fixed.

@bitwiseman
Copy link
Member

Turns out this was in the 1.14.4 - released today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants