mihai-vlc / sublime-jsfmt

jsfmt plugin for Sublime Text
MIT License
477 stars 21 forks source link

Indentation issue #32

Closed Shaked closed 9 years ago

Shaked commented 9 years ago

Hey, I am not sure that this is a bug.

When formatting with the tool the following code:

define([
    'jquery',
    'underscore',
    'backbone'
], function(
    $,
    _,
    Backbone
) {
    'use strict';
    return {}
});

It ends up as:

define([
    'jquery',
    'underscore',
    'backbone'
], function(
    $,
    _,
    Backbone
) {
'use strict';
return {};
});

(Notice that the content of the function is not indented. Is there a way to actually support that?

Thank you! Shaked

mihai-vlc commented 9 years ago

I can't seem to reproduce that issue. Do you have any jsfmt plugins installed ?

Shaked commented 9 years ago

I disabled them but still the same result. Also tried to reinstall the plugin but no luck, this is my configuration file:

{
  // autoformat on save
  "autoformat": true,

  // array of extensions for autoformat
  "extensions": ["js", "sublime-settings"],

  // options for jsfmt
  "options": {
    "preset": "jquery",
    "indent": {
      "value": "    "
    },
    // plugins included
    "plugins": [
      // "esformatter-quotes",
      // "esformatter-semicolons",
      // "esformatter-braces",
      // "esformatter-dot-notation"
    ]
  },
  "options-JSON": {
    "plugins": [
      "esformatter-quotes"
    ],
    "quotes": {
      "type": "double"
    }
  },
  "node-path": "node",
  "alert-errors": true,
  "ignore-selection": false
}
mihai-vlc commented 9 years ago

I see you have the preset set to jquery.
If you have a look here you can see all the specific configuration.

The one that causes your problem is TopLevelFunctionBlock.

This is enabled by default, with no special behaviour. When disabled (set to 0), esformatter will not indent top level function blocks (used by the jQuery preset).

So enabling that option will fix your issue:

"options": {
        "preset": "jquery",
        "indent": {
            "value": "    ",
            "TopLevelFunctionBlock" : 1
        }
   }

Please let me know if this is fixed.

Shaked commented 9 years ago

Works like a charm!